NonValidating DOM Parser & Whitespace text nodes

Hello,
Using the DOM parser and the Oracle samples (DOMSample),I wrote a
java progam to filter an XML file.
Ex:<a>
1
<c>2</c>
</a>
to
a:
b:1
c:2
end
It works fine. But when I set the parsers validation mode to
false, my code fails. It seems that a TEXTNODE is now generated
containing the whitespace of the file as I traverse the DOM tree.
Should I code around this or is there another way to handle
this unexpected textnode?
Bob
null

Correct me if i am wrong.
The Element object you are referring to is of type
org.w3c.dom.Element.
And as far as i know, it doesn't have any methods
such as getTextContent().Even the Node class does not
have such method.Yes you are wrong , with JDK 1.5 they do have getTextContent() method for org.w3c.dom Node & Element .
@ OP , dont know why your getTextContent is not working its working over here for me .
You may iterate over such a Node and remove the contents.
for. eg.
<Name>Son</Name>
Node name //(is ur node )
NodeList nk = node.getChildNodes();
                          String val= null;
                          for (int j=0; j < nk.getLength(); j++) {
                            Node k = nk.item(j);
                            val=  k.getNodeValue();
                          }Now u may use the value collected in String val
but make sure u apply this code only to above type of node, viz <Name>Son</Name>

Similar Messages

  • XML parser fails to convert html encoded text nodes

    Under the strain of large documents this defect rears its ugly head more often. While parsing a text node containing html encoded chars i.e. < > &; etc...
    The parser will seemingly forget to change the chars at random, 99.9% of the time everything is ok and the proper conversions take place:
    < -> &#60;
    > -> >
    &; -> &#38;
    Once an error occurs it is reproducible until the text node is changed ( values and/or order ) then it is a crapshoot again.
    These tests were done using the default UTF-8 encoding, here is the exception thrown by the parser along with a portion of the text node before and after the first parsing.
    Let me be clear, the parser actually succeeds the first time but the transformation of the HTML encoded pieces possibly fails. It is on the parsing of the text node value as its own document that the parser fails.
    Error 0 : Error parsing XML string! Line :: 1, Column :: 65674
    Error 1 : End tag does not match start tag 'Project'.
    End tag does not match start tag 'Project'.
    at oracle/xml/parser/v2/XMLError.flushErrors (XMLError.java:233)
    at oracle/xml/parser/v2/NonValidatingParser.parseDocument (NonValidatingParser.java:248)
    at oracle/xml/parser/v2/XMLParser.parse (XMLParser.java:117)
    at pacificedge/xml/XMLUtilities.loadParserFromString (XMLUtilities.java:104)
    Preprocessing ::
    <Project stuff0="0" stuff1="0" stuff2="0" stuff3="1" stuff4="100167" stuff5="100213">
    <StuffA>100213</StuffA>
    <Name>I am a Name</Name>
    <StartDate>1998-08-10</StartDate>
    <FinishDate>2000-06-30</FinishDate>
    <Path>Folder1\Folder2</Path>
    </Project>
    Post processing:
    <Project stuff0="0" stuff1="0" stuff2="0" stuff3="1" stuff4="100167" stuff5="100213">
    <StuffA>100213</StuffA>
    <Name>I am a Name</Name>
    <StartDate>1998-08-10</StartDate> <-- Error is raised here when the value of the text node is used as an xml document
    <FinishDate>2000-06-30</FinishDate>
    <Path>Folder1\Folder2</Path>
    </Project>
    Please investigate this. It is a chronic problem for us and possibly many others.
    null

    Sorry for the encoding issues in the message before here are the pertinent pieces hope this shows up correctly.
    &;lt; -> &;#60;
    &;gt; -> >
    &;amp; -> &;#38;
    Preprocessing ::
    &;lt;Project stuff0="0" stuff1="0" stuff2="0" stuff3="1" stuff4="100167" stuff5="100213"&;gt;
    &;lt;StuffA&;gt;100213&;lt;/StuffA&;gt;
    &;lt;Name&;gt;I am a Name&;lt;/Name&;gt;
    &;lt;StartDate&;gt;1998-08-10&;lt;/StartDate&;gt;
    &;lt;FinishDate&;gt;2000-06-30&;lt;/FinishDate&;gt;
    &;lt;Path&;gt;Folder1\Folder2&;lt;/Path&;gt;
    &;lt;/Project&;gt;
    Post processing:
    <Project stuff0="0" stuff1="0" stuff2="0" stuff3="1" stuff4="100167" stuff5="100213">
    <StuffA>100213</StuffA>
    <Name>I am a Name</Name>
    &;lt;StartDate>1998-08-10</StartDate> <-- Error is raised here when the value of the text node is used as an xml document
    <FinishDate>2000-06-30</FinishDate>
    <Path>Folder1\Folder2</Path>
    </Project>
    null

  • Extra #Text node

    Hi,
    It seems I got extra #Text node in my DOM object. For example, if my XML is as follows:
    <Root>
    <FirstElement>Value</FirstElement>
    </Root>
    My DOM tree will look like:
    + ELEMENT: Root
    + #TEXT:
    + ELEMENT: FirstElement
    + #TEXT: Value
    + #TEXT:
    Is there a way to avoid those extra empty #Text Node?

    //Create a DocumentBuilderFactory 
    DocumentBuilderFactory factory =
                DocumentBuilderFactory.newInstance();
    //Set the factory object to be validating
    factory.setValidating(true);
    //Set the factory object to not parse empty text nodes
    factory.setIgnoringElementContentWhitespace(true);
    //Create a DocumentBuilder and parse XML document
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document     document = builder.parse(new File("input.xml"));

  • CDATA sections converted to text nodes by XMLDOM parser

    I have done a lot of reading, experimentation and openned a TAR on this. I am suprised nobody else has posted on the issue. The xmlparser.parseClob call appears to parse an XML document properly but converts CDATA sections into text nodes.
    For example take the following XML:
    <some><pnode><![CDATA[the <xml>]]></pnode></some>
    If I immediately write it back out using xmldom.writeToClob the resulting XML will be:
    <some>
    <pnode>the &amp;#60;xml></pnode>
    </some>
    For one I wish writeToClob wouldn't add whitespace (but that's another issue), but as you can see the CDATA node no longer exists, being replaced by an encoded text node.
    I wrote code to traverse the DOM outputting node types and even writing a similar printer to the writeToClob. The fact is there really is no CDATA node in the DOM after parsing. Instead the code which traverses the DOM identifies a single text node with CDATA text contained in it.
    In my opinion this is extremely odd default behavior and I cannot seem to work around it due to the fact that the DOM structure is not created properly by the parse. Please tell me that other people have ran into this behavior and I'm not just nuts? Better yet, please just tell me I'm doing something wrong and you have the answer...that would be kinder to my project schedule.
    If you like I have example code. I am using the xmldom API on Oracle 9.2.0.4.

    Thanks for the response Mark. I have gotten some feedback from my TAR as well. We are using version 9.2.0.*. I have since learned that this is a bug in the xmldom implementation based on Java. It has been recommended that I use the dbms_* packages as you suggested. I originally attempted to use the dbms_* packages (the C-based implementation) when following the tutorials and other documentation but for some reason we do not seem to have those packages installed. I was directed by my DBA's to use the other package as we both bevelieved it was just the same package in a different location. I am working with my DBA to get the C-based dbms_* packages installed.

  • Reading DOM document text nodes

    I have created a DOM document from a text string, which seems fine. The structure is something like:
    <BOOK>
        <BOOK_ID>1</BOOK_ID>
        <BOOK_NAME>Test Book 1</BOOK_NAME>
        <BOOK_DESC>This is a test book</BOOK_DESC>
    </BOOK>When I try to traverse this structure using DOM, for each node (BOOK_ID, BOOK_NAME, BOOK_DESC), I get two nodes - one ElementNode, one TextNode, as I would expect.
    However, when I call get value on the TextNodes, it simply returns "\n ", instead of returning the text between the tags.
    Does any one know why?
    Thanks a lot,
    Jim

    I have some thing similar probelm but failed to get this working. Which ever nodes I try, all I get is node value "null" and say's that the node type is ELEMENT_NODE, but that node is TEXT_NODE as per schema.
    So I tried to validate the schema xml file which is external (even the xml file is located external), but failed to get this working too, now just stranded wihtout any clues what I have to do.
    I am using DOM parser with j2sdk-1.4.1_05.
    My xml file is:
    <?xml version="1.0" standalone="yes" ?>
    <IRXML CorpMasterID="9999999">
    <NewsRelease ReleaseID="215555" DLU="20020814 15:43:00" ArchiveStatus="Current">
    <Title>Viking Energy CEO and CFO Certify Financial Reports for SEC</Title>
    <Date Date="20020814" Time="15:32:00">8/14/2002 3:32:00 PM</Date>
    <Categories>
    <Category>Financial Releases</Category>
    </Categories>
    </NewsRelease>
    </IRXML>
    The nodes <Title> and <Date> are text nodes, so any help is appreciated.
    Thanks.

  • How to get nodes and its attributes of an XML file usiong DOM parsing?

    how to get nodes and its attributes of an XML file usiong DOM parsing?
    i am new to XML parsing.......
    Thanking you........

    import org.w3c.dom.Document;
    import org.w3c.dom.*;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.DocumentBuilder;
    import org.xml.sax.SAXException;
    import org.xml.sax.SAXParseException;      ...
    //Setup the document
    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
         DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
         Document doc = docBuilder.parse (new File("MY_XML_FILE.xml"));
    //get elemets by name
         String elementValue = doc.getElementsByTagName("MY_ELEMENT").item(0).getTextContent();
    //This method can return multiple nodes, in this instance I get item(0) , first nodeRead the api for other methods of getting data.

  • Reading from XML file using DOM parser.

    Hi,
    I have written the following java code to read the XML file and print the values. It reads the XML file. It gets the node NAME and prints it. But it returns null when trying to get the node VALUE. I am unable to figure out why.
    Can anyone please help me with this.
    Thanks and Regards,
    Shweta
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import oracle.xml.parser.v2.*;
    import org.w3c.dom.*;
    import org.xml.sax.SAXException;
    public class ReadNodes
    private static XMLDocument mDoc;
    public ReadNodes () {
         try {
    DOMParser lParser = new DOMParser();
    URL lUrl = createURL("mot.xml");
    System.out.println("after creating the URL object ");
    lParser.setErrorStream(System.out);
    lParser.showWarnings(true);
    lParser.parse(lUrl);
    mDoc = lParser.getDocument();
         System.out.println("after creating the URL object "+mDoc);
    lParser.reset();
    } catch (Exception e) {
    e.printStackTrace();
    } // end catch block
    } // End of constructor
    public void read() throws DOMException {
    try {
         NodeList lTrans = this.mDoc.getElementsByTagName("TRANSLATION");
         for(int i=0;i<lTrans.getLength();i++) {
              NodeList lTrans1 = lTrans.item(i).getChildNodes();
              System.out.println("lTrans1.item(0).getNodeName : " + lTrans1.item(0).getNodeName());
              System.out.println("lTrans1.item(0).getNodeValue : " + lTrans1.item(0).getNodeValue());
              System.out.println("lTrans1.item(1).getNodeName : " + lTrans1.item(1).getNodeName());
              System.out.println("lTrans1.item(1).getNodeValue : " + lTrans1.item(1).getNodeValue());
         } catch (Exception e) {
         System.out.println("Exception "+e);
         e.printStackTrace();
         } catch (Throwable t) {
              System.out.println("Exception "+t);
    public static URL createURL(String pFileName) throws MalformedURLException {
    URL url = null;
    try {
    url = new URL(pFileName);
    } catch (MalformedURLException ex) {
    File f = new File(pFileName);
    String path = f.getAbsolutePath();
    String fs = System.getProperty("file.separator");
    System.out.println(" path of file : "+path +"separator " +fs);
    if (fs.length() == 1) {
    char sep = fs.charAt(0);
    if (sep != '/')
    path = path.replace(sep, '/');
    if (path.charAt(0) != '/')
    path = '/' + path;
    path = "file://" + path;
    System.out.println("path is : "+path);
    // Try again, if this throws an exception we just raise it up
    url = new URL(path);
    } // End catch block
    return url;
    } // end method create URL
    public static void main (String args[]) {
         ReadNodes mXML = new ReadNodes();
         mXML.read();
    The XML file that I am using is
    <?xml version = "1.0"?>
    <DOCUMENT>
    <LANGUAGE_TRANS>
    <TRANSLATION>
    <CODE>3</CODE>
    <VALUE>Please select a number</VALUE>
    </TRANSLATION>
    <TRANSLATION>
    <CODE>5</CODE>
    <VALUE>Patni</VALUE>
    </TRANSLATION>
    <TRANSLATION>
    <CODE>6</CODE>
    <VALUE>Status Messages</VALUE>
    </TRANSLATION>
    <TRANSLATION>
    <CODE>7</CODE>
    <VALUE>Progress</VALUE>
    </TRANSLATION>
    <TRANSLATION>
    <CODE>8</CODE>
    <VALUE>Create Data Files...</VALUE>
    </TRANSLATION>
    <TRANSLATION>
    <CODE>9</CODE>
    <VALUE>OK</VALUE>
    </TRANSLATION>
    </LANGUAGE_TRANS>
    </DOCUMENT>

    because what you want is not the node value of CODE but the node value of the text nodes into it!
    assuming only one text node into it, try this:
    System.out.println("lTrans1.item(0).getNodeName : " + lTrans1.item(0).getFirstChild().getNodeValue());

  • Parsing xml using DOM parser in java

    hi there!!!
    i don have much idea about parsing xml.. i have an xml file which consists of details regarding indentation and spacing standards of C lang.. i need to read the file using DOM parser in java n store each of the attributes n elements in some data structure in java..
    need help as soon as possible!!!

    DOM is the easiest way to parse XML document, google for JDOM example it is very easy to implement.
    you need to know what is attribute, what is text content and what is Value in XML then easily you can parse your document with dom (watch for space[text#] in your XML document when you parse it).
    you get root node then nodelist of childs for root then go further inside, it is easy believe me.

  • Dom Parsing and BR tag problem...

    hi all,
    I have a Dom parser which examines an xml file and creates a Jtree from its content... it works fine except that when it meets a </br> tag it creates a new node for it in the tree... is there anyway to get it to consider the two "node" as one...
    example:
    - <p>
    some text 1
    some text 2
    </p>
    should be added in one node as some text 1 some text 2 instead it puts some text 1 in one node and some text 2 in another....
    thanks
    Lila

    oooh sorry i didnt check how the message looked this is the question:
    hi all, I have a Dom parser which examines an xml file and creates a Jtree from its content... it works fine except that when it meets a / BR tag it creates a new node for it in the tree... is there anyway to get it to consider the two "node" as one... example: -
    < p >
    some text 1
    < / BR > <--- THIS NODE IS PROBLEM
    some text 2
    < / p >
    should be added in one node as some text 1 some text 2 instead it puts some text 1 in one node and some text 2 in another....
    thanks
    Lila

  • #text nodes

    Hello,
    I am parsing xml document using xerces with schema validation on, without DTD.
    <xs:element name="variant">
    <xs:complexType>
    <xs:sequence>
    <xs:element ref="ds:default"/>
    <xs:element ref="ts:answer"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    As I understand this element should be "element only": without #text nodes in the dom tree.
    But I get: #text default #text answer #text.
    Can I fix it?
    Thanks
    Justinas

    Do you have white space between the nodes? I believe you can tell the parser to ignore white space that is not required by the schema.

  • Manipulating Text Nodes

    Hi,
    I have only recently begun working with XML and the DOM. I have
    begun writng a small app to upload XML data to a database using
    the version 2 parser. I am having trouble getting at the content
    of text nodes ( for example the "Stan" in <name>Stan</name> ). I
    have tried using the getNodeValue() function,and casting to a
    XMLText and the getData() function. I know I am at the correct
    node because I have used to the getNodeName() function to
    generate a list of nodes as I work my way through the document
    from the root. What am I missing?
    Thank you for your help,
    Stan Grabinski
    null

    Stan Grabinski (guest) wrote:
    : Hi,
    : I have only recently begun working with XML and the DOM. I
    have
    : begun writng a small app to upload XML data to a database
    using
    : the version 2 parser. I am having trouble getting at the
    content
    : of text nodes ( for example the "Stan" in
    <name>Stan</name> ). I
    : have tried using the getNodeValue() function,and casting to a
    : XMLText and the getData() function. I know I am at the
    correct
    : node because I have used to the getNodeName() function to
    : generate a list of nodes as I work my way through the document
    : from the root. What am I missing?
    : Thank you for your help,
    : Stan Grabinski
    You need to use the getNodeValue() method against the text node
    associated with the element node of interest not the element
    node itself. If this doesn't help, please post a code sample and
    the XML file.
    Oracle XML Team
    http://technet.oracle.com
    Oracle Technology Network
    null

  • Updating XML file using DOM parser

    Hi,
    Can someone help me, how to update following XML file using DOM parser.
    The following is my XML file.
    <students>
         <student>
              <id>1</id>
              <name>abc</name>
         </student>
         <student>
              <id>2</id>
              <name>xyz</name>
         </student>
         <student>
              <id>3</id>
              <name/>
         </student>
         <student>
              <id>4</id>
              <name>ijk</name>
         </student>
         <student>
              <id>5</id>
              <name></name>
         </student>
    </students>Consider, I will input 2 fields, ie., id & name. For the matching Id, the name has to be updated.
    Though, I have achieved this, but I am unable to update the value for 3rd record, & 5th record ie., id=3 & id=5. Since, these are blank.
    Thanks.

    Some <name> elements have a child node which is a text node. From what you say it appears you know how to change those text nodes.
    The other <name> elements don't have any child nodes. But you want one. This suggests to me that you need code that creates a text node and adds it to the <name> element as its child.

  • DOM Parser fails with regular expression using anchor (carat, dollar)

    I'm using version "Oracle XDK Java 9.0.4.0.0 Production"
    In trying to parse XML against schema: a regular expression fails to parse the data "8:00" with the following simple regular expression: "^.*$" (used to narrow the error)
    The error message is
    <Line 14, Column 25>: XSD-2025: (Error) Invalid text '8:00' in element: 'XYZ'
    If I remove the anchors and just have ".*", the data is parsed successfully.
    I dont understand why the parse fails when I use a anchors in the regular expression, and the java Pattern/Matcher classes succeed with the anchors?

    That "ns670" string is an xml namespace prefix. it should have a corresponding xml namespace declaration somewhere in the xml document (i'm guessing you have not shown the whole document). the actual value of an xml namespace prefix is meaningless. if you parse the xml with a namespace aware DOM parser, it should generate Nodes with the correct namespace. the namespace is the value you care about when extracting data from the document, not the namespace prefix.
    alternately, if you parse the document using a namespace aware DOM parser, you can just look for nodes based on their "local" name (the part after the ":" separator) and ignore the namespace/prefix.
    whatever you do, please do not parse the xml with a regex, see this http://stackoverflow.com/a/1732454/552759 for details (applies to xml as well).

  • Oracle.xml.parser.v2.XMLDOMException: Node cannot be modified.

    Considering a parsed xml document I'm trying to create a new node in the DOM if the node does not allready exists.
    nl_0 is the path to the parentnode.
    nl_1 is the path to the childnode, the element to be or not to be created.
    NodeList nl_0 = theXMLDoc.selectNodes("//FINALRESULT");
    NodeList nl_1 = theXMLDoc.selectNodes("//FINALRESULT/RESULT");
    if ( ((XMLElement)nl1.item(i) ) != null) {
    Text rs = (Text)nl1.item(i).getFirstChild();
    rs.setNodeValue(nl1.item(i).getNodeName());
    } else if (( (XMLElement)nl_0.item(i) ) != null ) {
    ( (XMLElement)nl_0.item(i) ).appendChild(new XMLElement("RESULT")).setNodeValue("A");
    Can someone please tell me what to do to make this work.
    Other possible methods are good too.
    Philippe

    You're trying to set the node value of an element, which cannot have a node value.
    You need to set the node value of the text-node child of the element instead.
    Or remove the current text-node child and append a new text-node child with the new value.

  • Returning Text Nodes

    Hi,
    Can somebody please help me with this problem. I am trying to return a specific node name, return it, and see if it has any child nodes. Below is a snippet from my XML doc:
    <description>
         <genre>football simulation</genre>
         <year>2004</year>
         <publisher ....However, when I enter "year", I am presented with
    <year>2004</year>as the child nodes of the "year" node. And when print the results from
    getNodeType, the text nodes arent identified. How can I get my code to see if there are text nodes present and return the text nodes?? I'll be extrmely grateful for any help!! Thanks.
    Below is some of my Java code:
      NodeList docNodes = test.getElementsByTagName("year");
          if(docNodes.getLength() !=0){
               System.out.println("noelist length: "+docNodes.getLength());
               for (int i=0; i<docNodes.getLength();i++){
                    Node blah = docNodes.item(i);
                    System.out.println(blah);
                       System.out.println(blah.getNodeType());
                    if(blah.hasChildNodes()){
                         System.out.println("child nodes present: "+blah.getChildNodes());
                         Node check = (Node) blah.getChildNodes();
                         System.out.println("node type: "+check.getNodeType());
                         if (check.getNodeType()==Node.TEXT_NODE){
                              System.out.println("text nodes present");
                         else{
                              System.out.println("text nodes ARENT present");
                         }

    Here is a little helper class I use when parsing DOM via Xerces. May not work equally well for jDOM or other implementations.
    final public class XmlHelper extends Object {
         // Class Variables //
         /** TODO Consider moving this to an interface with constants */
         static final public String XML_TAG_ROOT = "document";
         // Constructors //
          * Default constructor.
         public XmlHelper() {
              super();
         // Static Methods //
         static public Document newDocument()
              throws ConfigurationException {
              try {
                   DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
                   return builder.newDocument();
              catch (ParserConfigurationException configure) {
                   throw new ConfigurationException("Error instantiating DOM XML parser", configure);
         static public Document parse(InputStream in)
              throws ConfigurationException, IOException, ParseException {
              try {
                   DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
                   return builder.parse(in);
              catch (ParserConfigurationException configure) {
                   throw new ConfigurationException("Error instantiating DOM XML parser", configure);
              catch (SAXException parse) {
                   throw new ParseException("Error SAX parsing XML input stream", parse);
         static public Document parse(String uri)
              throws ConfigurationException, IOException, ParseException {
              try {
                   DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
                   return builder.parse(uri);
              catch (ParserConfigurationException configure) {
                   throw new ConfigurationException("Error instantiating DOM XML parser", configure);
              catch (SAXException parse) {
                   throw new ParseException("Error SAX parsing XML uri '" + uri + "'", parse);
         static public String serialize(Document target)
              throws IOException, ConfigurationException, TransformationException {
              ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
              serialize(target, byteOut, true);
              return byteOut.toString();
         static public void serialize(Document document, OutputStream target)
              throws IOException, ConfigurationException, TransformationException {
              serialize(document, target, false);          
         static public void serialize(Document document, OutputStream target, boolean indent)
              throws IOException, ConfigurationException, TransformationException {
              try {
                   Transformer transformer = TransformerFactory.newInstance().newTransformer();
                   if (indent)
                        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
                   transformer.transform(new DOMSource(document), new StreamResult(target));
              catch (TransformerConfigurationException configure) {
                   throw new ConfigurationException("Error instantiating XML transformer", configure);
              catch (TransformerException transform) {
                   /** @todo Need to write a generic transformation or serialization exception */
                   throw new TransformationException("Error transforming XML", transform);
         static public Element getChildElement(Element parent, String name) {
              Element child = null;
              if (parent != null) {
                   NodeList childNodes = parent.getElementsByTagName(name);
                   switch (childNodes.getLength()) {
                        case 0:
                             System.err.println("XML element <" + parent.getNodeName() + ">" +
                                  " has zero child nodes <" + name + "> (expecting one node)");
                        case 1:
                             child = (Element) childNodes.item(0);
                             break;
                        default:
                             child = (Element) childNodes.item(0);
                             /** @todo Consider implementing a "Warning Log" for errors such as these rather than sys.err */
                             System.err.println("XML element <" + parent.getNodeName() + ">" +
                                  " has " + childNodes.getLength() + " child nodes <" + name + "> (expecting only one)");
              return child;
         static public List getAllChildElements(Element parent, String name) {
              List elements = null;
              if (parent != null) {
                   elements = Collections.synchronizedList(new ArrayList());
                   NodeList childNodes = parent.getChildNodes();
                   for (int current = 0; current < childNodes.getLength(); current++) {
                        Node node = childNodes.item(current);
                        if ((node instanceof Element) && node.getNodeName().equals(name)) {
                             elements.add(node);
              return elements;
         static public String getChildElementValue(Element parent, String childName) {
              Element child = getChildElement(parent, childName);
              return child == null ? null : getElementValue(child);
         static public String getElementValue(Element parent) {
              NodeList nodes = parent.getChildNodes();
              int current = 0;
              int length = nodes.getLength();
              while (current < length) {
                   Node node = nodes.item(current);
                   if (node instanceof Text) {
                        String value = node.getNodeValue();
                        if (value != null)
                             return value.trim();
                   current++;
              return "";
    }- Saish

Maybe you are looking for