tags:

views:

99

answers:

3

Hi,

I have this xml data format. I would like to extract the properties name and value from it. I have tried to get node by node but it is troublesome.

<?xml version="1.0"> encoding="ASCII"?> 
<xDiagram>  
  <children iD="1261435145010.0" location="Point(547,184)" 
    size="Dimension(102,140)" shapeType="TestInfoShape"
    modelEntityID="TestInfo.7">
    <properties>
      <properties name="desc" type="MultiLinesText"
        parent="this_comp1" parentName="multiLinesText"
        modelPropName="desc" value="create test user can access"/>
      <properties name="name" type="String" parent="this_comp2"
        parentName="text" modelPropName="name" value="testCase1"/>
    </properties>
  </children>
</xDiagram>

Can anyone suggest a better way to do it? I like to use XPath but it can't lock on the element.

Thanks

+3  A: 

XPath is the right tool for this type of job. You can try improving your XPath expression at a site like:

http://www.whitebeam.org/library/guide/TechNotes/xpathtestbed.rhtm

For example, this XPath will return a NodeList containing all of the inner "Properties" elements:

/xDiagram/children/properties/properties
Mark Renouf
A: 

The Java Streaming API for XML is also handy (when SAX, DOM, or XPath aren't quite right for the job).

Jeremy Raymond
A: 

See if JAXB helps you: http://www.roseindia.net/jaxb/r/jaxb.shtml

Ravi Gupta