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 Daling Xu <da...@sonexent.com> on 2001/12/21 15:40:08 UTC
Why the namespace information doesn't shown in attributes?
Hi, All
I am user Xerces 1.4 SAX parser. In my content handler, I need to print out the root element exactly the same as the original XML file I am parsing. Following is the code I used:
public void startElement(....) {
...
System.out.print("<"+localName);
for(int i=0; i<atts.getLength(), i++)
{
System.out.print(" " + atts.getName(i) + "=" + atts.getValue(i));
}
System.out.print(">");
....
}
When the root element have no namespace informaion, the print out looks perfect:
original:
<root ID="5">
printout from my code:
<root ID="5">
but, when I add some namespace information into the root element, the print out is not what I expected:
original:
<root
xmlns="http://myProject.myCompany.com/order"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://myProject.myCompany.com/order order.xsd"
ID="5">
now the print out is:
<root
xsi:schemaLocation="http://myProject.myCompany.com/order order.xsd"
ID="5">
here, I missed two lines from the original xml file. I tried to debug my code, and found that the xml=... and xml:xsi=... was not listed in the atts as attribute name/value pair. What's the reason? How to fix my problem?
Thanks for any comments.
Linda