You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Charles Hudak <CH...@arrowheadgrp.com> on 2003/09/25 01:20:35 UTC

getChildNode() not finding Elements with numeric suffixes

Hi,

We have an application where we are processing a fairly flat xml doc of the
general form:

<foo>
   <foo-data>This is fubar</foo-data>
   <fubar-data>This is also fubar</fubar-data>
   <foo-bar1>This is some bad data</foo-bar1>
</foo>

The problem is when we get a handle to the foo Node and call
getChildNodes(), the last node does not show up in the child node list. This
happens for all Element names that END with a numeric suffix. Elements with
embedded numbers work fine--it is only those with trailing numbers that are
causing problems.

Curiously, when I use the XMLSerializer to serialize the DOM tree,
everything shows up correctly but when we try to find the node during
processing, it doesn't exist.

According to the xml spec, Element names of this sort are clearly allowed.

Does anyone have any idea why this would be causing a problem?

I'm not exactly sure which Xerces version that we are using. I think that I
downloaded it in the Sun xml pack or from the Xerces dev site within the
last six months. We have a xerces.jar and a xercesImpl.jar.

Thanks in advance for any assistance,

Charles

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: getChildNode() not finding Elements with numeric suffixes

Posted by Elena Litani <el...@ca.ibm.com>.
Charles Hudak wrote:
> <foo>
>    <foo-data>This is fubar</foo-data>
>    <fubar-data>This is also fubar</fubar-data>
>    <foo-bar1>This is some bad data</foo-bar1>
> </foo>
> 
> The problem is when we get a handle to the foo Node and call
> getChildNodes(), the last node does not show up in the child node list. 

This is very strange. What version [1] of the parser are you using? 


[1] http://xml.apache.org/xerces2-j/faq-general.html#faq-1

Thank you,
-- 
Elena Litani / IBM Toronto

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Problem in using getAttributeNS() method

Posted by Yasir Khan <ya...@ascertia.com>.
Hi,

I am using the latest Xerces API from Apache. I create a document and then
create some elements and set some attributes by using
Document.createElementNS() method and Element.setAttributeNS(). Now when I
try to access an attribute value from one of the element using
Element.getAttributeNS() method I successfully got the value. Then I saved
the document object to file. Then I read the file and create the document
object using DOMParser class. Now again I try to access the same attribute
value from the same element using Element.getAttributeNS() method but this
time I am unable to get the value of the attribute. On the other hand if I
try to access the attribute value using Element.getAttribute() it
successfully returns the value. It shows Element.getAttributeNS() is not
working in the same way after creating the document from file.

I am writing my code below:

    /* creating document */
    String str_xmlNS = "http://www.w3.org/2000/xmlns/";
    String str_myNS = "http://www.ascertia.com/xml/";
    Document obj_doc = XMLUtil.createDocument();
    Element obj_root = obj_doc.createElementNS(str_myNS,"myns:root");
    obj_root.setAttributeNS(str_xmlNS,"xmlns:myns",str_myNS);
    obj_root.setAttributeNS(str_myNS,"attribute","value");
    Element obj_element = obj_doc.createElementNS(str_myNS, "myns:element");
    obj_root.appendChild(obj_element);
    obj_doc.appendChild(obj_root);

    /* printing and saving to file */
    System.out.println("--- Before saving to file ---");
    System.out.println("Namespace URI is      :
"+obj_doc.getDocumentElement().getNamespaceURI());
    System.out.println("NS Attribute value is :
"+obj_doc.getDocumentElement().getAttributeNS(str_myNS, "attribute"));
    XMLWriter writer = new XMLWriter();
    writer.setOutput(new FileOutputStream("c:/xml.xml"), "utf-8");
    writer.write(obj_doc);

   /*output in file is below*/
   /*
       <?xml version="1.0" encoding="UTF-8"?>
       <myns:root attribute="value"
xmlns:myns="http://ww.ascertia.com/xml/">
                 <myns:element></myns:element>
       </myns:root>
   */

    /*reading from file and printing - but it doesn't work*/
    System.out.println("--- After saving to file ---");
    org.apache.xerces.parsers.DOMParser obj_parser = new
org.apache.xerces.parsers.DOMParser();
    obj_parser.parse("c:/xml.xml");
    Document obj_doc1 = obj_parser.getDocument();
    System.out.println("Namespace URI is      :
"+obj_doc1.getDocumentElement().getNamespaceURI());
    System.out.println("NS Attribute value is :
"+obj_doc1.getDocumentElement().getAttributeNS(str_myNS, "attribute"));

    /*it works*/
    System.out.println("--- Following works ---");
    System.out.println("Attribute value is    :
"+obj_doc1.getDocumentElement().getAttribute("attribute"));

Below is the out put of the program:

--- Before saving to file ---
Namespace URI is      : http://ww.ascertia.com/xml/
NS Attribute value is : value
--- After saving to file ---
Namespace URI is      : http://ww.ascertia.com/xml/
NS Attribute value is :
--- Following works ---
Attribute value is    : value

Please tell me what is going wrong in the above program.

Thanx & regards,
Yasir Khan


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org