Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DOM validation PLEASE HELP

 
Ariel Valentin
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy Partners
Need some help...
I was able to print out the XML nodes in the command prompt for debugging like so:
Document customers
<customers>
<customer id="0001">
<name >Ariel S. Valentin</name>
<userid>Ariel_V</userid>
</customer>
....
</customers>
Number of Customers=3
Elements
Customer Node List 3
Press any key to continue...
Now in order to validate to XML schemas I had to add the "endorsed" folder to the JRE, sadly I am getting a "null" instead of the nodes (elements call them what you will). Shouldn't it at least give me the Hash address?
Document customers
Entire List [customers: null]
Number of Customers=3
Elements
Customer Node List 3
Press any key to continue...
I want the best of both worlds, where it could be easy to debug by seeing what the actual nodes are and use XSD validation.
What can I do? Any Ideas? Anyone else face this problem?
Here is a Code Snippit:
//Please excuse the inconsistency and poor style
document = builder.parse("c:/xmlcache/customer.xml");
System.out.print("Document "
+ document.getFirstChild().getNodeName()
+"\n");
Element entireList = (Element) document.getFirstChild();
System.out.print("Entire List "+ entireList +"\n");
NodeList customerNL = document.getElementsByTagName("customer");

System.out.print("Number of Customers="
+ customerNL.getLength()
+ "\n");

StringBuffer sb = new StringBuffer("Elements\n");
sb.append("Customer Node List " + customerNL.getLength()+"\n");
System.out.print(sb.toString());
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of

I always use

Bill
 
Ariel Valentin
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bill,
Thanks for replying. I went back and read the Node interfaces API and now realize I get exactly what I should for an empty or complex element "null", not a string representation of the node and all it's children. I guess the difference is what Crimson returns as oppossed to Xerces.
This is what I got using crimson parser
Advantage for me!- Easy to debug
Disadvantage-Unable to validate schemas with this:
The Document Itself rg.apache.crimson.tree.XmlDocument@1034bb5
Document #document
docElement=<customers>
<customer id="0001">
<name>Ariel S. Valentin</name>
<userid>Ariel_V</userid>
....
</customers>
docElements Tag Name=customers
Customer Node List=org.apache.crimson.tree.ParentNode$TagList@186d4c1
First Customer element=<customer id="0001">
<name>Ariel S. Valentin</name>
<userid>Ariel_V</userid>
</customer>
Press any key to continue...
After adding xerces:
UGG! Seeing null makes me uncomfortable...
The Document Itself:[#document: null]
Document #document
docElement=[customers: null]
docElements Tag Name=customers
Customer Node List=org.apache.xerces.dom.DeepNodeListImpl@1ded0fd
First Customer element=[customer: null]
Press any key to continue...
Code Snippit:
document = builder.parse("c:/xmlcache/customer.xml");
System.out.print("The Document Itself:"+ document +"\n");
System.out.print("Document "+ document.getNodeName() +"\n");
Element docElement;
NodeList customerNL;

docElement = document.getDocumentElement();
System.out.print("docElement="+ docElement +"\n");
System.out.print("docElements Tag Name="+ docElement.getTagName() +"\n");
System.out.print("Customer Node List="+ docElement.getElementsByTagName("customer")+"\n");
System.out.print("First Customer element="+ docElement.getElementsByTagName("customer").item(0)+"\n" );
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic