|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.springframework.shell.support.util.XmlUtils
public final class XmlUtils
Utilities related to XML usage.
Method Summary | |
---|---|
static void |
assertElementLegal(String element)
Checks the presented element for illegal characters that could cause malformed XML. |
static boolean |
compareNodes(Node node1,
Node node2)
Compares two DOM nodes by comparing the representations of the nodes as XML strings |
static String |
convertId(String proposed)
Converts a XHTML compliant id (used in jspx) to a CSS3 selector spec compliant id. |
static Transformer |
createIndentingTransformer()
|
static Element |
createTextElement(Document document,
String tagName,
String text)
Creates an Element containing the given text |
static List<Element> |
findElements(String xPathExpression,
Element root)
Checks in under a given root element whether it can find a child elements which match the XPath expression supplied. |
static Node |
findFirstAttribute(String xPathExpression,
Element element)
Checks for a given element whether it can find an attribute which matches the XPath expression supplied. |
static Element |
findFirstElement(String xPathExpression,
Node parent)
Searches the given parent element for a child element matching the given XPath expression. |
static Element |
findFirstElementByName(String name,
Element root)
Deprecated. use DomUtils.findFirstElementByName(String, Element) instead |
static Node |
findNode(String xPathExpression,
Node root)
Checks in under a given root element whether it can find a child node which matches the XPath expression supplied. |
static Element |
findRequiredElement(String xPathExpression,
Element root)
Checks in under a given root element whether it can find a child element which matches the XPath expression supplied. |
static Element |
getConfiguration(Class<?> clazz)
Returns the root element of an addon's configuration file. |
static DocumentBuilder |
getDocumentBuilder()
|
static Element |
getRootElement(Class<?> clazz,
String xmlFilePath)
Returns the root element of the given XML file. |
static String |
getTextContent(String path,
Element parentElement)
|
static String |
getTextContent(String path,
Element parentElement,
String valueIfNull)
|
static String |
nodeToString(Node node)
Converts a node to an XML string |
static Document |
readXml(InputStream inputStream)
Read an XML document from the supplied input stream and return a document. |
static void |
removeTextNodes(Node node)
Deprecated. use DomUtils.removeTextNodes(Node) instead |
static Element |
stringToElement(String xml)
Returns the given XML as the root Element of a new Document |
static void |
writeFormattedXml(OutputStream outputStream,
Document document)
Write an XML document to the OutputStream provided. |
static void |
writeXml(OutputStream outputStream,
Document document)
Write an XML document to the OutputStream provided. |
static void |
writeXml(Transformer transformer,
OutputStream outputStream,
Document document)
Write an XML document to the OutputStream provided. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static Element stringToElement(String xml)
Element
of a new Document
xml
- the XML to convert; can be blank
null
if the given XML is blankpublic static Element createTextElement(Document document, String tagName, String text)
Element
containing the given text
document
- the document to contain the new elementtagName
- the element's tag name (required)text
- the text to set; can be null
for none
null
elementpublic static Document readXml(InputStream inputStream)
inputStream
- the input stream to read from (required). The stream is closed upon completion.
IllegalStateException
- if the stream could not be readpublic static void writeXml(OutputStream outputStream, Document document)
outputStream
- the output stream to write to. The stream is closed upon completion.document
- the document to write.public static void writeXml(Transformer transformer, OutputStream outputStream, Document document)
transformer
- the transformer (can be obtained from XmlUtils.createIndentingTransformer())outputStream
- the output stream to write to. The stream is closed upon completion.document
- the document to write.public static void writeFormattedXml(OutputStream outputStream, Document document)
outputStream
- the output stream to write to. The stream is closed upon completion.document
- the document to write.public static boolean compareNodes(Node node1, Node node2)
nodes
by comparing the representations of the nodes as XML strings
node1
- the first nodenode2
- the second node
public static String nodeToString(Node node)
node
to an XML string
node
- the first element
public static Element findFirstElement(String xPathExpression, Node parent)
<beans><sec:http>
, you
need to use the following XPath expression '/beans/http'.
xPathExpression
- the xPathExpression (required)parent
- the parent DOM element (required)
Element
found)public static Node findNode(String xPathExpression, Node root)
Node
if
exists.
Please note that the XPath parser used is NOT namespace aware. So if you
want to find a element <beans><sec:http>
, you
need to use the XPath expression '/beans/http
'.
xPathExpression
- the XPath expression (required)root
- the parent DOM element (required)
public static Element findRequiredElement(String xPathExpression, Element root)
Element
must
exist. Returns Element
if exists.
Please note that the XPath parser used is NOT namespace aware. So if you
want to find a element
xPathExpression
- the XPath expression (required)root
- the parent DOM element (required)
public static List<Element> findElements(String xPathExpression, Element root)
List
of
Element
if they exist.
Please note that the XPath parser used is NOT namespace aware. So if you
want to find a element
xPathExpression
- the xPathExpressionroot
- the parent DOM element
List
of type Element
if discovered, otherwise an empty list (never null)public static Node findFirstAttribute(String xPathExpression, Element element)
Node
if exists.
xPathExpression
- the xPathExpression (required)element
- (required)
public static Transformer createIndentingTransformer()
public static DocumentBuilder getDocumentBuilder()
public static Element getRootElement(Class<?> clazz, String xmlFilePath)
clazz
- the class from whose package to open the file (required)xmlFilePath
- the path of the XML file relative to the given class'
package (required)
null
elementDocument.getDocumentElement()
public static Element getConfiguration(Class<?> clazz)
clazz
- which owns the configuration
public static String convertId(String proposed)
proposed
- Id
public static void assertElementLegal(String element)
element
- the content of the XML element
IllegalArgumentException
- if the element is null, has no text or contains illegal characterspublic static String getTextContent(String path, Element parentElement)
public static String getTextContent(String path, Element parentElement, String valueIfNull)
@Deprecated public static Element findFirstElementByName(String name, Element root)
DomUtils.findFirstElementByName(String, Element)
instead
Element
if exists.
name
- the Element name (required)root
- the parent DOM element (required)
@Deprecated public static void removeTextNodes(Node node)
DomUtils.removeTextNodes(Node)
instead
node
- the element where empty text nodes will be removed
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |