Skip navigation links


org.identityconnectors.common
Class XmlUtil

java.lang.Object
  extended by org.identityconnectors.common.XmlUtil


public class XmlUtil
extends java.lang.Object

Field Summary
static char DOUBLE_QUOTE
           
static char NO_DELIM
           
static char SINGLE_QUOTE
           

 

Method Summary
static void escape(java.lang.StringBuilder b, java.lang.String s, char delim)
          Escapes the given string and appends to the given buffer
static org.w3c.dom.Element findImmediateChildElement(org.w3c.dom.Node node, java.lang.String name)
          Find an immediate child of the given name
static java.lang.String getAttribute(org.w3c.dom.Element e, java.lang.String name)
          Return the value of an attribute on an element.
static java.lang.String getContent(org.w3c.dom.Element e)
          Return the content of the given element.
static org.w3c.dom.Element getFirstChildElement(org.w3c.dom.Node node)
          Returns the First child element or null if none found
static org.w3c.dom.Element getNextElement(org.w3c.dom.Node node)
          Get the next right sibling that is an element.
static org.w3c.dom.Document parseString(java.lang.String xml)
          Parses a string without validation and returns the Document.

 

Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

 

Field Detail

NO_DELIM

public static final char NO_DELIM
See Also:
Constant Field Values

DOUBLE_QUOTE

public static final char DOUBLE_QUOTE
See Also:
Constant Field Values

SINGLE_QUOTE

public static final char SINGLE_QUOTE
See Also:
Constant Field Values

Method Detail

parseString

public static org.w3c.dom.Document parseString(java.lang.String xml)
                                        throws java.io.IOException,
                                               org.xml.sax.SAXException,
                                               javax.xml.parsers.ParserConfigurationException
Parses a string without validation and returns the Document.
Throws:
java.io.IOException
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException

getAttribute

public static java.lang.String getAttribute(org.w3c.dom.Element e,
                                            java.lang.String name)
Return the value of an attribute on an element.

The DOM getAttribute method returns an empty string if the attribute doesn't exist. Here, we detect this and return null.


findImmediateChildElement

public static org.w3c.dom.Element findImmediateChildElement(org.w3c.dom.Node node,
                                                            java.lang.String name)
Find an immediate child of the given name

getFirstChildElement

public static org.w3c.dom.Element getFirstChildElement(org.w3c.dom.Node node)
Returns the First child element or null if none found
Parameters:
node - The node. May be null.
Returns:
the First child element or null if none found

getNextElement

public static org.w3c.dom.Element getNextElement(org.w3c.dom.Node node)
Get the next right sibling that is an element.

getContent

public static java.lang.String getContent(org.w3c.dom.Element e)
Return the content of the given element.

We will descend to an arbitrary depth looking for the first text node.

Note that the parser may break what was originally a single string of pcdata into multiple adjacent text nodes. Xerces appears to do this when it encounters a '$' in the text, not sure if there is specified behavior, or if its parser specific.

Here, we will congeal adjacent text nodes.

We will NOT ignore text nodes that have only whitespace.


escape

public static void escape(java.lang.StringBuilder b,
                          java.lang.String s,
                          char delim)
Escapes the given string and appends to the given buffer
Parameters:
b - The buffer
s - The script to be escaped. May be null.
delim - May be SINGLE_QUOTE, DOUBLE_QUOTE, or NO_DELIM.

Skip navigation links


Copyright © 2011, Oracle and/or its affiliates. All rights reserved.