how to get all the values of a specific element in an XML using java

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sulabh4u
    New Member
    • Jun 2007
    • 4

    #1

    how to get all the values of a specific element in an XML using java

    lets say i need all the values of <scopeID> element from this xml:

    <?xml version="1.0"?>
    <scopes>
    <item>
    <scope>scope1 </scope>
    <description>de scription of the scope</description>
    <scopeID>12vkjl asc</scopeID>
    </item>
    <item>
    <scope>scope2 </scope>
    <description>de scription of the scope2</description>
    <scopeID>8s9sm2 emk</scopeID>
    </item>
    <item>
    <scope>scope3 </scope>
    <description>de scription of the scope3</description>
    <scopeID>7tqsxj nds</scopeID>
    </item>
    </scopes>


    how to do it using java ? Thx a ton in advance!
  • blazedaces
    Contributor
    • May 2007
    • 284

    #2
    Originally posted by sulabh4u
    lets say i need all the values of <scopeID> element from this xml:

    <?xml version="1.0"?>
    <scopes>
    <item>
    <scope>scope1 </scope>
    <description>de scription of the scope</description>
    <scopeID>12vkjl asc</scopeID>
    </item>
    <item>
    <scope>scope2 </scope>
    <description>de scription of the scope2</description>
    <scopeID>8s9sm2 emk</scopeID>
    </item>
    <item>
    <scope>scope3 </scope>
    <description>de scription of the scope3</description>
    <scopeID>7tqsxj nds</scopeID>
    </item>
    </scopes>


    how to do it using java ? Thx a ton in advance!
    The two main xml-parsers/readers out there are DOM and SAX. Look them both up, I believe they're both opensource and free to look at and inspect their documentation.

    In fact, SAX is included in Java 1.5 and higher (I believe it's 1.5 and higher, might have been earlier versions too, but at least SAX 2.0 is 1.5 and higher, correct me if I'm wrong). So read into it and look at your java src files to look at it perhaps...

    Good luck, xml is not fun at all. This simple task can be fairly daunting if you're new to java, I know,

    -blazed

    Comment

    Working...