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

 

Previous Page Table Of Contents Next Page

Java and the XML DOM, cont.

XMLParser Methods

Method                                                          Description

void addRecognizer(org.apache.xerces.readers.                   Adds a recognizerXMLDeclRecognizer recognizer)

abstract void attlistDecl(int elementType,                         Serves as a callback for an attribute list int attrName, int attType, java.lang.             declarationString enumString, int attDefaultType, int attDefaultValue)

void callCharacters(int ch)                                         Calls the characters callback

void callComment(int comment)                                   Calls the comment callback

void callEndDocument()                                           Calls the end document callback

boolean callEndElement(int readerId)                              Calls the end element callback

void callProcessingInstruction                                     Calls the processing instruction callback(int target, int data)

void callStartDocument(int version,                                Calls the start document callbackint encoding, int standalone)

void callStartElement(int elementType)                            Calls the start element callback

org.apache.xerces.readers.XMLEntityHandler.                     Is called by the reader subclasses at the EntityReader changeReaders()  end of input

abstract void characters(char[] ch,                                Serves as a callback for charactersint start, int length)

abstract void characters(int data)                                  ‑Serves as a callback for characters using string pools

abstract void comment(int comment)                              Serves as a callback for comment

void commentInDTD(int comment)                                ‑Serves as a callback for comment in DTD

abstract void elementDecl(int elementType,                       Serves as a callback for an element XMLValidator.ContentSpec contentSpec)              declaration

abstract void endCDATA()                                         ‑Serves as a callback for end of the CDATA section

abstract void endDocument()                                      ‑Serves as a callback for the end of the document

abstract void endDTD()                                            ‑Serves as a callback for the end of the DTD

abstract void endElement(int elementType)                       ‑Serves as a callback for end of the element

void endEntityDecl()                                               ‑Serves as a callback for the end of an entity declaration

abstract void endEntityReference                                 Serves as a callback for the end of an (int entityName, int entityType,       entity referenceint entityContext)

abstract void endNamespaceDeclScope                          Serves as a callback for the end of a (int prefix)                           namespace declaration scope

java.lang.String expandSystemId                                  Expands a system ID and returns the (java.lang.String systemId)system ID as an URL

abstract void externalEntityDecl                                   Serves as a callback for an external (int entityName, int publicId, int systemId)           general entity declaration

abstract void externalPEDecl(int entityName,                     Serves as a callback for an external int publicId, int systemId)       parameter entity declaration

protected boolean getAllowJavaEncodings()                       ‑Is true if Java encoding names are allowed in the XML document

int getColumnNumber()                                            ‑Gives the column number of the current position in the document

protected boolean getContinueAfterFatalError()                    ‑Is true if the parser will continue after a fatal error

org.apache.xerces.readers.XMLEntityHandler.                     Gets the Entity readerEntityReader getEntityReader()

EntityResolver getEntityResolver()                               Gets the current entity resolver

ErrorHandler getErrorHandler()                                     Gets the current error handler

boolean getFeature(java.lang.String featureId)                    Gets the state of a feature

java.lang.String[] getFeaturesRecognized()                        ‑Gets a list of features recognized by this parser

int getLineNumber()                                                ‑Gets the current line number in the document

Locator getLocator()                                               Gets the locator used by the parser

protected boolean getNamespaces()                               ‑Is true if the parser preprocesses namespaces

java.lang.String[] getPropertiesRecognized()                       ‑‑Gets the list of recognized properties for the parser

java.lang.Object getProperty(java.lang.                           Gets the value of a propertyString propertyId)

java.lang.String getPublicId()                                      Gets the public ID of the InputSource

protected org.apache.xerces.validators.                           Gets the current XML schema schema.XSchemaValidator getSchemaValidator()              validator

java.lang.String getSystemId()                                    Gets the system ID of the InputSource

protected boolean getValidation()                                  Is true if validation is turned on

protected boolean getValidationDynamic()                         ‑Is true if validation is determined based on whether a document contains a grammar

protected boolean getValidation                                    Is true if an error is created when an WarnOnDuplicateAttdef()       attribute is redefined in the grammar

protected boolean getValidation                                    Is true if the parser creates an error WarnOnUndeclaredElemdef()   ‑when an undeclared element is referenced

abstract void ignorableWhitespace                                Serves as a callback for ignorable (char[] ch, int start, int length)     whitespace

abstract void ignorableWhitespace(int data)                       ‑Serves as a callback for ignorable whitespace based on string pools

abstract void internalEntityDecl                                   Serves as a callback for internal general(int entityName, int entityValue)   entity declaration

abstract void internalPEDecl                                       Serves as a callback for an internal (int entityName, int entityValue)           parameter entity declaration

abstract void internalSubset                                                    Supports DOM Level 2 (int internalSubset)                                          internalSubsets

boolean isFeatureRecognized                                      Is true if the given feature is recognized(java.lang.String featureId)

boolean isPropertyRecognized                                     Is true if the given property is (java.lang.String propertyId)                 recognized

abstract void notationDecl(int notationName,                      Serves as a callback for a notation int publicId, int systemId)         declaration

void parse(InputSource source)                                    Parses the given input source

void parse(java.lang.String systemId)                             ‑Parses the input source given by a system identifier

boolean parseSome()                                              Supports application-driven parsing

boolean parseSomeSetup(InputSource source)                    Sets up application-driven parsing

void processCharacters(char[] chars,                              Processes character data given a int offset, int length)                  character array

void processCharacters(int data)                                  Processes character data

abstract void processingInstruction                                Serves as a callback for processing(int target, int data)                  instructions

void processingInstructionInDTD                                  Serves as a callback for processing (int target, int data)                instructions in a DTD

void processWhitespace(char[] chars,                             Processes whitespaceint offset, int length)

void processWhitespace(int data)                                 ‑Processes whitespace based on string pools

void reportError(Locator locator,                                   Reports errorsjava.lang.String errorDomain, int majorCode, int minorCode, java.lang.Object[] args, int errorType)

void reset()                                                        ‑Resets the parser so that it can be reused

protected void resetOrCopy()                                                  Resets or copies the parser

int scanAttributeName(org.apache.xerces.                                Scans an attribute namereaders.XMLEntityHandler.EntityReader entityReader, int elementType)

int scanAttValue(int elementType,                                            Scans an attribute valueint attrName)

void scanDoctypeDecl(boolean standalone)                              Scans a doctype declaration

int scanElementType(org.apache.xerces.                                  Scans an element typereaders.XMLEntityHandler.EntityReader entityReader, char fastchar)

boolean scanExpectedElementType                                         Scans an expected element type(org.apache.xerces.readers.XMLEntityHandler.EntityReader entityReader, char fastchar)

protected void setAllowJavaEncodings                                     Supports the use of Java encoding (boolean allow)                         names

protected void setContinueAfterFatalError                                 Lets the parser continue after fatal (boolean continueAfterFatalError)           errors

void setEntityResolver(EntityResolver resolver)                       ‑Specifies the resolver (resolves external entities)

void setErrorHandler(ErrorHandler handler)                                Sets the error handler

void setFeature(java.lang.String                                              Sets the state of a featurefeatureId, boolean state)

void setLocale(java.util.Locale locale)                                       Sets the locale

void setLocator(Locator locator)                                               Sets the locator

protected void setNamespaces(boolean process)                       ‑Specifies whether the parser preprocesses namespaces

void setProperty(java.lang.String propertyId,                             Sets the value of a propertyjava.lang.Object value)

void setReaderFactory(org.apache.xerces.                               Sets the reader factoryreaders.XMLEntityReaderFactory readerFactory)

protected void setSendCharDataAsCharArray)                          Sets character data processing prefer-(boolean flag)                    ences

void setValidating(boolean flag)                                               ‑Indicates to the parser that we are validating

protected void setValidation(boolean validate)                            Specifies whether the parser validates

protected void setValidationDynamic                                        Lets the parser validate a document (boolean dynamic)                 only if it contains a grammar

protected void setValidationWarnOn)                                        Specifies whether an error is created DuplicateAttdef(boolean warn)           ‑when attributes are redefined in the grammar

protected void setValidationWarnOn                                         Specifies whether the parser causes an UndeclaredElemdef(boolean warn)                ‑error when an element's content model references an element by name that is not declared

abstract void startCDATA()                                                     ‑Serves as a callback for start of the CDATA section

abstract void startDocument(int version,                                  Serves as a callback for the start of theint encoding, int standAlone)          document

abstract void startDTD(int rootElementType,                             Serves as a callback for the start of int publicId, int systemId)        the DTD

abstract void startElement(int elementType,                              Serves as a callback for the start of theXMLAttrList attrList, int attrListHandle)            element

boolean startEntityDecl(boolean isPE,                                      Serves as a callback for the start of an int entityName)                entity declaration

abstract void startEntityReference                                          Serves as a callback for start of an (int entityName, int entityType, int        entity referenceentityContext)

abstract void startNamespaceDeclScope                                  Serves as a callback for the start of a (int prefix, int uri)                namespace declaration scope

boolean startReadingFromDocument                                        Starts reading from a document(InputSource source)

boolean startReadingFromEntity(int entityName,                       Starts reading from an external entityint readerDepth, int context) 

void startReadingFromExternalSubset                                      Starts reading from an external DTD(java.lang.String publicId, java.lang.String             subsetsystemId, int readerDepth)

void stopReadingFromExternalSubset()                                    ‑Stops reading from an external DTD subset

abstract void unparsedEntityDecl                                            Serves as a callback for unparsed entity(int entityName, int publicId, int systemId,    declarationsint notationName)

boolean validEncName(java.lang.String encoding)                      Is true if the given encoding is valid

boolean validVersionNum(java.lang.String                                 Is true if the given version is valid version)                            

To actually parse the XML document, you use the parse method of the parser object. I'll let the user specify the name of the document to parse on the command by parsing args[0]. Note that you don't need to pass the name of a local file to the parse method-you can pass the URL of a document on the Internet, and the parse method will retrieve that document.

When you use the parse method, you need to enclose your code in a try block to catch possible errors, like this:

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]);

            .

            .

            .

        } catch (Exception e) {

            e.printStackTrace(System.err);

        }

    }

}

If the document is successfully parsed, you can get a Document object based on the W3C DOM, corresponding to the parsed document, using the parser's getDocument method:

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();

            .

            .

            .

        } catch (Exception e) {

            e.printStackTrace(System.err);

        }

    }

}

The Document interface is part of the W3C DOM, and you can find the methods of this interface in Table 11.3.

 

Page 4 of 13

 

Previous Page Table Of Contents Next Page
 

Recent Jobs

An immediate job opportunity as a B
Software Developers Needed in Charl
Sr. Software Engineer - Analytics
Immediate Mainframe openings for Ch
Immediate TANDEM-TAL openings for C

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



answering service
help desk support
swimming pool contractor
conference call
water softener
Teleconference
Host Department NOLIMIT Web Hosting
MSN
sunglasses


    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