[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
RE: [xsl] Using Java for DOM processing
Subject: RE: [xsl] Using Java for DOM processing From: "Gertjan Assies" <Gertjan.Assies@xxxxxxxxxxxxxx> Date: Tue, 13 Apr 2004 16:52:53 +0200 |
Hi, The carriage return characters in your second example are represented in the DOM tree as textnodes, hence the name #text, this could be a result of your parser not removing those whitespace, I'm not exactly sure what the spec. says about that. You should also check on those nodes in your code, something like this If (currentNode.getNodeType() != Node.TEXT_NODE) { System.out.println(currentNode.getNodeName()); } cheers, Gertjan Assies -----Original Message----- From: Chisanga Mwelwa [mailto:sangz2000@xxxxxxxxxxx] Sent: Tuesday, April 13, 2004 4:26 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Cc: xml-dev@xxxxxxxxxxxxx Subject: [xsl] Using Java for DOM processing Hi, I am currently trying to get my head round using DOM with Java. In particular I have been looking at the getNodeName() method. I have noticed that the format/layout you present the XML document in, seems to have an effect on the way the DOM method (getNodeName) handles the XML document. Could someone enlighten me on this, is this a bug or something normal and if so should I expect all DOM methods to process XML documents in a manner dependent on the XML format/layout? Below I have presented a snippet of the Java code and XML document I am dealing with to help you "digest" my problem. Your help is appreciated! Java code snippet >>> .. System.out.print( "Here is the document's root node:" ); System.out.println( " " + root.getNodeName() ); System.out.println( "Here are its child elements: " ); NodeList childNodes = root.getChildNodes(); Node currentNode; .. for ( int i = 0; i < childNodes.getLength(); i++ ) { currentNode = childNodes.item( i ); // print node name of each child element System.out.println( currentNode.getNodeName()); } .. This is the output I desire : Here is the document's root node: article Here are its child elements: title date author summary content The first child of root node is: title whose next sibling is: date value of date element is: April 13, 2004 Parent node of date is: article I only get the above output when my XML file is presented as below: <?xml version = "1.0"?> <article><title>Simple XML</title><date>April 13, 2004</date><author><firstName>Tem</firstName><lastName>Nieto</lastName>< /author><summary>XML is easy.</summary><content>Once you have mastered XHTML, you can easily learn XML. You must remember that XML is not for displaying information but for managing information.</content></article> When my XML file is foramtted as below this is the (unwanted) output I get: Here is the document's root node: article Here are its child elements: #text title #text date #text author #text summary #text content #text The first child of root node is: #text whose next sibling is: title value of title element is: Simple XML Parent node of title is: article This is the XML layout I prefer to use, note each element is defined on a new line, unfortunately it gives me the (unwanted) output above i.e. the #text: <?xml version = "1.0"?> <article> <title>Simple XML</title> <date>April 13, 2004</date> <author> <firstName>Tem</firstName> <lastName>Nieto</lastName> </author> <summary>XML is easy.</summary> <content>Once you have mastered XHTML, you can easily learn XML. You must remember that XML is not for displaying information but for managing information. </content> </article> _________________________________________________________________ Express yourself with cool new emoticons http://www.msn.co.uk/specials/myemo BackStream(R) Willem de Zwijgerlaan 350-352 1055 RD Amsterdam The Netherlands tel. +31 20 386 8365 fax +31 20 386 8948 Post Office Address: Postbus 58385 1040 HJ Amsterdam BackStream: The Digital Delivery Company www.backstream.com This e-mail and any attachment may contain confidential and privileged material intended for the addressee only. If you are not the addressee, you are notified that no part of the e-mail or any attachment may be disclosed, copied or distributed, and that any other action related to this e-mail or attachment is strictly prohibited, and may be unlawful. If you have received this e-mail by error, please notify the sender immediately by return e-mail, and delete this message. BackStream, its subsidiaries and/or its employees shall not be liable for the incorrect or incomplete transmission of this e-mail or any attachments, nor responsible for any delay in receipt.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Using Java for DOM processing, Chisanga Mwelwa | Thread | [xsl] Writing to a text file, Naomi Gronson |
[xsl] Using Java for DOM processing, Chisanga Mwelwa | Date | [xsl] Writing to a text file, Naomi Gronson |
Month |