java - Correct way to retrieve collection using XPath? -


i've got xml file of several recordings looks this:

<audiolibrary>     <prompt name="accountinfo">         <prompt-segment>             <audio src="audio/default/accountinfo.wav"                  text="account information"/>         </prompt-segment>     </prompt>     ...     <prompt name="accountclosed">         <prompt-segment>             <audio src="audio/default/accountclosed.wav"                 text="sorry, account closed."/>         </prompt-segment>     </prompt> </audiolibrary> 

following xpath tutorial, know can retrieve, example, attribute of first prompt following expressions:

xpathobject.compile("/audioibrary/prompt[@name='accountinfo']/prompt-segment/audiofile/@src"); xpathobject.compile("/audioibrary/prompt[1]/prompt-segment/audiofile/@src"); 

now, if want retrieve of prompts, understanding correctly should iterate through .compile() statements until come blank value?

something skeletal example, here?:

int index = 1; {     xpathobject.compile("/audioibrary/prompt["+ index +"]/prompt-segment/audiofile/@src");     (prompt content retrieval code here)     index++; } while(!src.equals("")) 

or, there better way retrieve collection?

thanks!
ivr avenger

xpathexpression expr = xpathobject.compile("/audiolibrary/promp/prompt-segment/audio/@src") object result = expr.evaluate(doc, xpathconstants.nodeset); nodelist nodes = (nodelist) result; (int = 0; < nodes.getlength(); i++) {     //what going do....  } 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -