?
Solved

Skipping node in XML using Xerces in java

Posted on 2007-07-23
5
Medium Priority
?
215 Views
Last Modified: 2010-05-18
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
Comment
Question by:sangameshrh
4 Comments
 
LVL 92

Accepted Solution

by:
objects earned 336 total points
ID: 19546036
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
 
LVL 13

Assisted Solution

by:R7AF
R7AF earned 332 total points
ID: 19546350
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
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 332 total points
ID: 19546432
0
 
LVL 1

Expert Comment

by:Computer101
ID: 20213294
Forced accept.

Computer101
EE Admin
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month16 days, 10 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question