Class XmlDomUtils
java.lang.Object
gov.nasa.pds.registry.common.util.xml.XmlDomUtils
Utility class to work with XML DOM model.
NOTE: Don't use XML DOM API for big files.
DOM API loads the whole XML file into memory.
- Author:
- karpenko
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intcountChildNodes(Node node, String name) Count child nodes.static StringgetAttribute(Node node, String attributeName) Get attribute of a node by name.static NamedNodeMapgetAttributes(Node node) Get all attributes of a node.getChildNodes(Node node, String name) Get all child nodes.static NodegetFirstChild(Node node, String name) Get first child node.static DocumentParse XML file and create a DOM model.static DocumentreadXml(File xmlFile, File xsdFile, ErrorHandler eh) Parse XML file and create a DOM model.static DocumentreadXml(DocumentBuilderFactory dbf, File file) Parse XML file and create a DOM model.
-
Constructor Details
-
XmlDomUtils
public XmlDomUtils()
-
-
Method Details
-
readXml
Parse XML file and create a DOM model. This method reads the whole XML document into memory.- Parameters:
dbf- Document builder factoryfile- XML file to parse- Returns:
- XML DOM model
- Throws:
Exception- Generic exception
-
readXml
Parse XML file and create a DOM model. This method reads the whole XML document into memory.- Parameters:
file- XML file to parse- Returns:
- XML DOM model
- Throws:
Exception- Generic exception
-
readXml
Parse XML file and create a DOM model. This method reads the whole XML document into memory.- Parameters:
xmlFile- XML file to parsexsdFile- XSD schema file for XML validationeh- custom error handler- Returns:
- XML DOM model
- Throws:
Exception- Generic exception
-
getAttribute
Get attribute of a node by name.- Parameters:
node- DOM nodeattributeName- attribute name- Returns:
- attribute value
-
getAttributes
Get all attributes of a node.- Parameters:
node- DOM node- Returns:
- attribute map
-
countChildNodes
Count child nodes.- Parameters:
node- Parent node objectname- child node name- Returns:
- node count
-
getFirstChild
Get first child node.- Parameters:
node- parent nodename- child node name- Returns:
- a child node
-
getChildNodes
Get all child nodes.- Parameters:
node- parent node.name- child node name.- Returns:
- a list of nodes
-