Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

XML parentnode read

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have the following kind of xml with me.
<School>
<Class1>
<Student1>
<FirstName>
</FirstName>
</Student1>
<Student2>
<FirstName>
</FirstName>
</Student2>
</Class1>
<Class2>
<Student3>
<LastName>
</LastName>
</Student3>
</Class2>
</School>

I want to read all the parent nodes of Firstname, LastName etc. ie I want to write a code which returns me that the childnode FirstName has parentnodes as Student1, Class1. Then Childnode FirstName has parentnode as Student2. Then childnode LastName has parentnode as Student3,Class2.

How can I do it using Xpath or xmlParser?
 
Sheriff
Posts: 26973
85
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A node only has one parent. You seem to be including some of the other ancestors, but not all of them, in some of your lists of "parent" nodes. I don't see any consistency in what you want. However if you want to get all the ancestors of a node, then there's the ancestors axis.
 
Megha Patni
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to do it using java code and the attribute names are also not constant. How can I do it in Java code using XPath or XMLParser?
 
reply
    Bookmark Topic Watch Topic
  • New Topic