Reg Xml Parsing

K

kumsa

hi iam new to java and jdom parsing.my imput is user passes the xml
file and a string (string is not a tag in xml its a attribute value).i
need to look for the string in the xml file and get all its child
attributes .my xml looks like


<Trs>
<cetTra>
<xName>"jeff"</xName>
<child>pat</child>
<child>sush</child>
<Delay>
<timeSec>60</timeSec>
<retry>1</retry>
</Delay>
</cetTra>

<cetTra>
<xName>"kumsa"</xName>
<child>sac</child>
<child>ed</child>
<Delay>
<timeSec>5</timeSec>
<retry>10</retry>
</Delay>
</cetTra>

</Trs>



my quesion is how to get only the the contents based on attribute
..Input string will be jeff i need to get the contents only for jeff .my
code looks like

List passedStringList = root.getChildren("CetTra");
Iterator i = passedStringList.iterator();
while (i.hasNext()) {
Element serv= (Element) i.next();
out.print("\t" + serv.getChild("xName")
.getText());

or can i do this with Jdom or shld i use perl parser .Can any one pls
guide me how to proceed.
thanks in advance
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

kumsa said:
hi iam new to java and jdom parsing.my imput is user passes the xml
file and a string (string is not a tag in xml its a attribute value).i
need to look for the string in the xml file and get all its child
attributes .my xml looks like
my quesion is how to get only the the contents based on attribute
.Input string will be jeff i need to get the contents only for jeff .my
code looks like
or can i do this with Jdom or shld i use perl parser .Can any one pls
guide me how to proceed.

I think you should use the JDOM XPath class to get what you wnat out.

Arne
 
D

Daniel Pitts

kumsa said:
hi iam new to java and jdom parsing.my imput is user passes the xml
file and a string (string is not a tag in xml its a attribute value).i
need to look for the string in the xml file and get all its child
attributes .my xml looks like


<Trs>
<cetTra>
<xName>"jeff"</xName>
<child>pat</child>
<child>sush</child>
<Delay>
<timeSec>60</timeSec>
<retry>1</retry>
</Delay>
</cetTra>

<cetTra>
<xName>"kumsa"</xName>
<child>sac</child>
<child>ed</child>
<Delay>
<timeSec>5</timeSec>
<retry>10</retry>
</Delay>
</cetTra>

</Trs>



my quesion is how to get only the the contents based on attribute
.Input string will be jeff i need to get the contents only for jeff .my
code looks like

List passedStringList = root.getChildren("CetTra");
Iterator i = passedStringList.iterator();
while (i.hasNext()) {
Element serv= (Element) i.next();
out.print("\t" + serv.getChild("xName")
.getText());

or can i do this with Jdom or shld i use perl parser .Can any one pls
guide me how to proceed.
thanks in advance
Using XPath is easy, and clear. Why parse the XML syntax when there
are libraries out there that do it for you. You're only concern should
be the semantic values in the XML. That is what XPath helps get you to.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top