This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes DOM validation PLEASE HELP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "DOM validation PLEASE HELP" Watch "DOM validation PLEASE HELP" New topic
Author

DOM validation PLEASE HELP

Ariel Valentin
Ranch Hand

Joined: Jan 30, 2004
Posts: 44
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());


A. Valentin
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12759
    
    5
Instead of

I always use

Bill
Ariel Valentin
Ranch Hand

Joined: Jan 30, 2004
Posts: 44
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" );
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DOM validation PLEASE HELP
 
Similar Threads
java.lang.string
XML and Java
XML Node Parsing Problem , when Node owns NodeList using Xercer , HELP !!!!
some notes on xml
Extract full path when parsing XML