Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Why namespace information is not in attributes list

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
What's wrong? Where are you going? Stop! Read this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic