Package com.aeontronix.commons.xml
Class XmlUtils
java.lang.Object
com.aeontronix.commons.xml.XmlUtils
Various XML related utility functions
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic XMLGregorianCalendarconvertDate(Date date) static Datestatic Documentstatic DocumentcreateDocument(boolean namespaceAware) static ElementcreateElement(String name, Node parent, Object... attrs) static org.w3c.dom.traversal.TreeWalkercreateElementTreeWalker(Node node) static org.w3c.dom.traversal.TreeWalkercreateElementTreeWalker(Node node, boolean entityReferenceExpansion) static org.w3c.dom.traversal.TreeWalkercreateElementTreeWalker(Node node, org.w3c.dom.traversal.NodeFilter nodeFilter, boolean entityReferenceExpansion) static Elementstatic ElementcreateNSElement(String name, Node parent, Object... attrs) static SchemacreateSchema(Reader schema) static SchemacreateSchema(Source... sources) static SchemacreateSchema(LSResourceResolver rsResolver, Source... sources) static org.w3c.dom.traversal.TreeWalkercreateTreeWalker(Node node, int whatToShow) As callingcreateTreeWalker(org.w3c.dom.Node, int, org.w3c.dom.traversal.NodeFilter, boolean)with nodeFilter=null, entityReferenceExpansion=true }static org.w3c.dom.traversal.TreeWalkercreateTreeWalker(Node node, int whatToShow, org.w3c.dom.traversal.NodeFilter nodeFilter, boolean entityReferenceExpansion) static Nodestatic Nodestatic ElementgetChildElement(Node parent, String elementName, boolean create) Search for a child element, with the option to automatically create it if the create flag is true.static ElementgetChildElement(Node parent, String namespace, String elementName, boolean create) Search for a child element, with the option to automatically create it if the create flag is true.getChildNodes(Node node, Class<X> type) static DocumentBuilderstatic DocumentBuildergetDocumentBuilder(boolean namespaceAware) static DocumentBuilderFactorystatic DocumentBuilderFactorygetDocumentBuilderFactory(boolean namespaceAware) static DocumentBuilderFactorygetDocumentBuilderFactory(boolean namespaceAware, boolean disableDtdXxe) static DOMImplementationRegistrystatic intgetSiblingNumber(Node node) Calculate how many previous siblings of the same node type exists, and return that value plus one.static StringReturn an xpath expression that matches the provided node.static Documentparse(byte[] data) static Documentparse(byte[] data, boolean namespaceAware) static Documentstatic Documentstatic Documentparse(InputStream stream) static Documentparse(InputStream stream, boolean namespaceAware) static Documentstatic Documentstatic Documentstatic Documentstatic Documentstatic Documentstatic voidserialize(Node node, OutputStream stream) static voidserialize(Node node, OutputStream writer, boolean xmlDeclaration, boolean prettyPrint) static voidstatic voidstatic voidsetAttributes(Element element, Object... attrs) toClonedElementList(NodeList nodelist, boolean deep) toClonedList(NodeList nodelist, boolean deep) Clone all the nodes contains in the provided node list, and return them in aList.toElementList(NodeList nodelist) toList(NamedNodeMap attrList) Convert aNamedNodeMapcontains attribute nodesAttrstatic Stringstatic String
-
Field Details
-
DF_NSAWARE
public static final boolean DF_NSAWARE- See Also:
-
-
Constructor Details
-
XmlUtils
public XmlUtils()
-
-
Method Details
-
createDocument
-
createDocument
-
createSchema
- Throws:
SAXException
-
createSchema
- Throws:
SAXException
-
createSchema
public static Schema createSchema(LSResourceResolver rsResolver, Source... sources) throws SAXException - Throws:
SAXException
-
parse
- Throws:
IOExceptionSAXException
-
parse
- Throws:
IOExceptionSAXException
-
parse
- Throws:
IOExceptionSAXException
-
parse
public static Document parse(InputStream stream, boolean namespaceAware) throws IOException, SAXException - Throws:
IOExceptionSAXException
-
parse
- Throws:
IOExceptionSAXException
-
parse
public static Document parse(Reader reader, boolean namespaceAware) throws IOException, SAXException - Throws:
IOExceptionSAXException
-
parse
- Throws:
IOExceptionSAXException
-
parse
- Throws:
IOExceptionSAXException
-
parse
- Throws:
IOExceptionSAXException
-
parse
- Throws:
IOExceptionSAXException
-
parse
- Throws:
IOExceptionSAXException
-
parse
- Throws:
IOExceptionSAXException
-
getChild
-
getChild
-
getChildElement
public static Element getChildElement(Node parent, String elementName, boolean create) throws DOMException Search for a child element, with the option to automatically create it if the create flag is true.- Parameters:
parent- Parent node.elementName- Element name.create- Flag that indicates if the element should be automatically created should it not exist.- Returns:
- Child element or null if it doesn't exist and create is false.
- Throws:
DOMException- If there is an node with the specified name, that isn't an element.
-
getChildElement
public static Element getChildElement(Node parent, String namespace, String elementName, boolean create) throws DOMException Search for a child element, with the option to automatically create it if the create flag is true.- Parameters:
parent- Parent node.namespace- Namespace (optional).elementName- Element name.create- Flag that indicates if the element should be automatically created should it not exist.- Returns:
- Child element or null if it doesn't exist and create is false.
- Throws:
DOMException- If there is an node with the specified name, that isn't an element.
-
serialize
-
serialize
-
serialize
-
serialize
public static void serialize(Node node, OutputStream writer, boolean xmlDeclaration, boolean prettyPrint) -
toString
-
toString
-
getDomImplRegistry
-
getDocumentBuilderFactory
-
getDocumentBuilderFactory
-
getDocumentBuilderFactory
public static DocumentBuilderFactory getDocumentBuilderFactory(boolean namespaceAware, boolean disableDtdXxe) -
getDocumentBuilder
-
getDocumentBuilder
-
getXPath
Return an xpath expression that matches the provided node.- Parameters:
node- Node.- Returns:
- resolved expression.
-
getSiblingNumber
Calculate how many previous siblings of the same node type exists, and return that value plus one.- Parameters:
node- Node- Returns:
- Sibling number.
-
getChildNodes
-
toList
- Parameters:
nodelist- Node list- Returns:
Listof nodes
-
toList
Convert aNamedNodeMapcontains attribute nodesAttr- Parameters:
attrList-NamedNodeMapcontainingAttrobjects exclusively- Returns:
- List of
Attr.
-
toClonedList
Clone all the nodes contains in the provided node list, and return them in aList.- Parameters:
nodelist- Node listdeep- If true, recursively clone the subtree under each node; if false, clone only the node itself (and its attributes, if it is an Element).- Returns:
Listof cloned nodes
-
toElementList
Clone all the nodes contains in the provided node list, assuming they are of typeElement, and return them in aList.- Parameters:
nodelist- Node list- Returns:
Listof cloned nodes
-
toClonedElementList
Clone all the nodes contains in the provided node list, assuming they are of typeElement, and return them in aList.- Parameters:
nodelist- Node listdeep- If true, recursively clone the subtree under each node; if false, clone only the node itself (and its attributes, if it is an Element).- Returns:
Listof cloned nodes
-
createElement
-
createNSElement
-
createNSElement
-
setAttributes
-
createTreeWalker
As callingcreateTreeWalker(org.w3c.dom.Node, int, org.w3c.dom.traversal.NodeFilter, boolean)with nodeFilter=null, entityReferenceExpansion=true }- Parameters:
node- The node which will serve as the root for the TreeWalker. The whatToShow flags and the NodeFilter are not considered when setting this value; any node type will be accepted as the root. The currentNode of the TreeWalker is initialized to this node, whether or not it is visible. The root functions as a stopping point for traversal methods that look upward in the document structure, such as parentNode and nextNode. The root must not be null.whatToShow- This flag specifies which node types may appear in the logical view of the tree presented by the TreeWalker. See the description of NodeFilter for the set of possible SHOW_ values.These flags can be combined using OR.- Returns:
- TreeWalker
-
createTreeWalker
public static org.w3c.dom.traversal.TreeWalker createTreeWalker(Node node, int whatToShow, org.w3c.dom.traversal.NodeFilter nodeFilter, boolean entityReferenceExpansion) -
createElementTreeWalker
-
createElementTreeWalker
public static org.w3c.dom.traversal.TreeWalker createElementTreeWalker(Node node, boolean entityReferenceExpansion) -
createElementTreeWalker
public static org.w3c.dom.traversal.TreeWalker createElementTreeWalker(Node node, org.w3c.dom.traversal.NodeFilter nodeFilter, boolean entityReferenceExpansion) -
convertDate
-
convertDate
-