• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 222
  • Last Modified:

Skipping node in XML using Xerces in java

Hi,

   I am using Xerces for XML processing, i wanted to know how to skip a particular node or child node in a xml document.
for eg.
<a>
<p><hw>element1</hw><def></def></p>
<p><hw>element1</hw><def></def></p>
<p><hw>element1</hw><def></def></p>
<p><sn>element1</sn><def></def></p>
<p><hw>element1</hw><def></def></p>
</a>

in the above scenario, i want to only parse hw but not sn how to do it.....
0
sangameshrh
Asked:
sangameshrh
3 Solutions
 
objectsCommented:
depends on what u need, but xpath is probably the first thing to look at using

http://www.exampledepot.com/egs/org.w3c.dom/xpath_GetChildElem.html?l=rel
0
 
R7AFCommented:
Assuming the <a> element is a child or <root>, the following template does what you want:

########### XSLT ############

<?xml version='1.0'?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
            xmlns:xhtml="http://www.w3.org/1999/xhtml" version="1.0">

<xsl:template match="/root">
      <html><body>
            <xsl:for-each select="a/p[hw]">
                  <xsl:value-of select="."/>
            </xsl:for-each>
      </body></html>
</xsl:template>

</xsl:stylesheet>

########## XML ##########

<?xml version="1.0" encoding="UTF-8"?>

<root>
<a>
      <p><hw>hw1</hw><def></def></p>
      <p><hw>hw2</hw><def></def></p>
      <p><hw>hw3</hw><def></def></p>
      <p><sn>sn1</sn><def></def></p>
      <p><hw>hw4</hw><def></def></p>
</a>
</root>

#######################

The xpath is: a/p[hw], which filters for nodes with "hw" in it.
An alternative is a/p[not(sn)], which filters out nodes with "sn".
0
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now