BizTalk Utilities CV ,   Jobs ,   Code library  
 
 
Page 5 of 13

 

Previous Page Table Of Contents Next Page

Java and the XML DOM, cont.

Node Interface Methods

Method                                                Description

Node appendChild(Node newChild)                              ‑Adds the newChild node as the last child node of this node

Node cloneNode(boolean deep)                                   Creates a duplicate of this node

NamedNodeMap getAttributes()                                   ‑Gets a NamedNodeMap containing the attributes of this node

NodeList getChildNodes()                                           ‑Gets a NodeList that contains all children of this node

Node getFirstChild()                                                  Gets the first child of this node

Node getLastChild()                                                   Gets the last child of this node

java.lang.String getLocalName()                                  Gets the local name of the node

java.lang.String getNamespaceURI()                           Gets the namespace URI of this node

Node getNextSibling()                                                Gets the node immediately following this one

java.lang.String getNodeName()                                  Gets the name of this node

short getNodeType()                                                  Gets a code representing the type of the node

java.lang.String getNodeValue()                                  Gets the value of this node

Document getOwnerDocument()                                  Gets the Document object that owns this node

Node getParentNode()                                               Gets the parent of this node

java.lang.String getPrefix()                                         Gets the namespace prefix of this node

Node getPreviousSibling()                                          Gets the node immediately before this one

boolean hasChildNodes()                                            Is true if this node has any children

Node insertBefore(Node newChild,                              Inserts the node newChild before the child Node refChild)                          node refChild

void normalize()                                                        ‑Normalizes text nodes by making sure that there are no immediately adjacent or empty text nodes

Node removeChild(Node oldChild)                               Removes the child node oldChild

Node replaceChild(Node newChild,                              Replaces the child node oldChild with Node oldChild)                                 newChild

void setNodeValue                                                    Sets a node's value(java.lang.String nodeValue)

void setPrefix(java.lang.String prefix)                          Sets a prefix

boolean supports(java.lang.String                        Is true if the DOM implementation feature, java.lang.String version)           ‑implements a specific feature supported by this node

At this point, we have access to the root node of the document. Our goal here is to check how many <CUSTOMER> elements the document has, so I'll use the getElementsByTagName method to get a NodeList object containing a list of all <CUSTOMER> elements:

import org.w3c.dom.*;

import org.apache.xerces.parsers.DOMParser;

 

public class FirstParser

{

    public static void main(String[] args)

    {

 

        try {

            DOMParser parser = new DOMParser();

            parser.parse(args[0]);

            Document doc = parser.getDocument();

 

            NodeList nodelist = doc.getElementsByTagName("CUSTOMER");

            .

            .

            .

        } catch (Exception e) {

            e.printStackTrace(System.err);

        }

    }

}

The NodeList interface supports an ordered collection of nodes. You can access nodes in such a collection by index, and we'll do that in this chapter. You can find the methods of the NodeList interface in Table 11.5.

 

Page 5 of 13

 

Previous Page Table Of Contents Next Page
 

Recent Jobs

Integration Specialist Needed - Wor
Virtualization Server Infrastructur
A great opportunity to Digital Vide
here is a greate opportunity as a S
A great opportunity as a Network En

View all Jobs (Add yours)
View all CV (Add yours)




Chicago Web Site Design
conference call services
conference call
Giorgio armani sunglasses
air freshener
odor remover


    Email TopXML  

Front Page Daily Stuff TopXML Forum XML blogs XML Newsgroups BizTalk Biztalk Utilities Biztalk Utilities Tutorial B2B SAP XML Microsoft .NET Dotnet System XML Soapformatter SQLXML XMLserializer XQuery PHP PHP SimpleXML PHP XML Dom PHP XML RPC PHP XSLT Java Java Java XML Xalan Microsoft ASP ASP Schemas XML SQL Server XML XMLDom XSL XSL Tutorial XSLT Stylesheets General Javascript CSS XHTML WAP