org.openide.xml
Class XMLUtil

java.lang.Object
  |
  +--org.openide.xml.XMLUtil

public final class XMLUtil
extends Object

Utility class collecting library methods related to XML processing.

Since:
release 3.2

Method Summary
static Document createDocument(String rootQName, String namespaceURI, String doctypePublicID, String doctypeSystemID)
          Creates empty DOM Document using JAXP factoring.
static XMLReader createXMLReader()
           
static XMLReader createXMLReader(boolean validate)
           
static XMLReader createXMLReader(boolean validate, boolean namespaceAware)
          Factory SAX XMLReader using JAXP.
static byte[] fromHex(char[] hex, int start, int len)
          Decodes data encoded using toHex.
static Document parse(InputSource input, boolean validate, boolean namespaceAware, ErrorHandler errorHandler, EntityResolver entityResolver)
          Factory a DocumentBuilder and let it create a org.w3c.dom.Document.
static String toAttributeValue(String val)
          Escape passed string as XML attibute value (<, &, ' and " will be escaped.
static String toElementContent(String val)
          Escape passed string as XML element content (<, & and > in ]]> sequences).
static String toHex(byte[] val, int start, int len)
          Can be used to encode values that contain invalid XML characters.
static void write(Document doc, OutputStream out, String enc)
          Write Document into OutputStream using given encoding.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createXMLReader

public static XMLReader createXMLReader()
                                 throws SAXException
Returns:
createXMLReader(false, false);

createXMLReader

public static XMLReader createXMLReader(boolean validate)
                                 throws SAXException
Parameters:
validate - if true validating parser is returned
Returns:
createXMLReader(validate, false);

createXMLReader

public static XMLReader createXMLReader(boolean validate,
                                        boolean namespaceAware)
                                 throws SAXException
Factory SAX XMLReader using JAXP. Result can be used to parse XML files. The parser has set entity resolver to system entity resolver chain.
Parameters:
validate - if true validating parser is returned
ns - if true namespace aware parser is returned
Returns:
XMLReader configured according to passed prameters

createDocument

public static Document createDocument(String rootQName,
                                      String namespaceURI,
                                      String doctypePublicID,
                                      String doctypeSystemID)
                               throws DOMException
Creates empty DOM Document using JAXP factoring. E.g.:

 Document doc = createDocument("book",null,null,null);
 

creates new DOM of a well-formed document with root element named book.

Parameters:
rootQName - qualified name of root element. e.g. myroot or ns:myroot
namespaceURI - URI of root element namespace or null
doctypePublicID - public ID of DOCTYPE or null
doctypeSystemID - system ID of DOCTYPE or null if no DOCTYPE required and doctypePublicID is also null
Returns:
new DOM Document

parse

public static Document parse(InputSource input,
                             boolean validate,
                             boolean namespaceAware,
                             ErrorHandler errorHandler,
                             EntityResolver entityResolver)
                      throws IOException,
                             SAXException
Factory a DocumentBuilder and let it create a org.w3c.dom.Document. This method takes InputSource. After successful finish the document tree is returned.
Parameters:
input - a parser input (for URL users use: new InputSource(url.toExternalForm())
validate - if true validating parser is used
namespaceAware - if true DOM is created by namespace aware parser
errorHandler - a error handler to notify about exception or null
entityResolver - - SAX entity resolver (e.g. EntityCatalog.getDefault())or null
Returns:
org.w3c.dom.Document representing given inout or null if a parsing error occures

write

public static void write(Document doc,
                         OutputStream out,
                         String enc)
                  throws IOException
Write Document into OutputStream using given encoding. It is a shortcut for writing configurations etc. It guarantee just that data will be written. Structure and indentation may change.
Parameters:
doc - DOM Document to be written
out - data sink
enc - - XML defined encoding name (i.e. IANA defined, one of UTF-8, UNICODE, ASCII).

toAttributeValue

public static String toAttributeValue(String val)
                               throws CharConversionException
Escape passed string as XML attibute value (<, &, ' and " will be escaped. Note: An XML processor returns normalized value that can be different.
Parameters:
val - a string to be escaped
Returns:
escaped value
Throws:
CharConversionException - if val contains an inproper XML character
Since:
1.40

toElementContent

public static String toElementContent(String val)
                               throws CharConversionException
Escape passed string as XML element content (<, & and > in ]]> sequences).
Parameters:
val - a string to be escaped
Returns:
escaped value
Throws:
CharConversionException - if val contains an inproper XML character
Since:
1.40

toHex

public static String toHex(byte[] val,
                           int start,
                           int len)
Can be used to encode values that contain invalid XML characters. At SAX parser end must be used pair method to get original value.
Parameters:
val - data to be converted
start - offset
len - count
Since:
1.29

fromHex

public static byte[] fromHex(char[] hex,
                             int start,
                             int len)
                      throws IOException
Decodes data encoded using toHex.
Parameters:
hex - data to be converted
start - offset
len - count
Throws:
IOException - if input does not represent hex encoded value
Since:
1.29


Built on December 12 2001.  |  Portions Copyright 1997-2001 Sun Microsystems, Inc. All rights reserved.