1

What best meets my requirements in creating and modifying XML?

Requirements:

  • checking whether a node exists through the entire path from the root

    <root>
       <a>
          <b>
          </b>
       </a>
    <root>
    

    -> //root/a/b

  • creating XML nodes with easy access to them, like expressions in XPath.

What can be recommend?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Was
  • 23
  • 4
  • You may write a simple helper class to accomplish your task around DOM. See this http://stackoverflow.com/a/8346867/851432 – Jomoos Dec 01 '11 at 19:18

3 Answers3

2

You can use Java XPath API in javax.xml.xpath package. This is a tutorial

And to create XML nodes using XPath check this out

Community
  • 1
  • 1
Raihan
  • 10,095
  • 5
  • 27
  • 45
0

Perhaps this is overkill for you but XmlBeans from Apache is pretty cool and JAXB with Binders (which is perhaps a bit more modern) are both great options for modelling strictly defined XML (those with XSD Schema, DTD) in a Java friendly manner as simple beans. With a little extra coding, both can use XPath to reference elements within the XML data.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Yaneeve
  • 4,751
  • 10
  • 49
  • 87
0

If you can use Groovy, XmlSlurper plays nicely with Java, e.g. reading and updating. Groovy has its own expression language GPath, which has similar purpose as the more well-known XPath.

Curious for more? Visit Groovy XML processing.

matsev
  • 32,104
  • 16
  • 121
  • 156