1
<xml>
<name>steve</name>
<age>12</age>
<country>Germany</country>
<person>
  <college>kmu university</college>
  <country>Sweden</country>
</person>
</xml>

Using stax parser while parsing I get country name as Germany,Sweden. But I need only Sweden not germany. Any other way to get it.I am using STAX parser to parse this xml.

Expected Output: Sweden

Actual Output:Germany,Sweden

2
  • do you have to use STAX? Commented Feb 14, 2013 at 15:39
  • yes I have to use STAX because Xml content very large in size Commented Feb 14, 2013 at 16:08

1 Answer 1

3

When you do StAX (and SAX) parsing, you need to track the context yourself. this means you need to keep track of the elements which have started and not yet completed. once you have this information, you can then keep only the "country" element which is nested under the "person" element and ignore all other "country" elements.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks how to get country element node only under person can you give some example...I dont want code just explain logic it is enough.
@BalaMurugan - i did explain the logic in my answer: "keep track of the elements which have started and not yet completed" and "keep only the "country" element which is nested under the "person" element"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.