Class EzlibLoader.XmlParser
java.lang.Object
com.saicone.ezlib.EzlibLoader.XmlParser
- Enclosing class:
EzlibLoader
The XML parser to handle documents.
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs an XML parser with default parameters.XmlParser(Supplier<DocumentBuilder> docBuilder, Supplier<Transformer> transformer) Constructs an XML parser with provided parameters.XmlParser(DocumentBuilder docBuilder, Transformer transformer) Constructs an XML parser with provided parameters. -
Method Summary
Modifier and TypeMethodDescriptionGet document from file.Get document from URL.Get document builder used to parse documents.getElement(Element element, String... path) Get element inside element at provided path.getElements(Element element, String tag, String... path) Get element list from provided element path by tag name.Get node from element at provided path.getTextContent(Element document, Element element, String... path) Get text content from element path.getTextContentOrDefault(Element document, Element element, String def, String... path) Get text content from element path or use default value if node don't exists.Get transformed used on this instance.
-
Constructor Details
-
XmlParser
public XmlParser()Constructs an XML parser with default parameters. -
XmlParser
Constructs an XML parser with provided parameters.- Parameters:
docBuilder- the document builder to use.transformer- the element transformer to use.
-
XmlParser
Constructs an XML parser with provided parameters.- Parameters:
docBuilder- the document builder supplier to use.transformer- the element transformer supplier to use.
-
-
Method Details
-
fromUrl
Get document from URL.- Parameters:
url- the URL to connect.- Returns:
- a parsed document from URL or null.
- Throws:
IOException- if an I/O exception occurs.SAXException- if any parse errors occur.
-
fromFile
Get document from file.- Parameters:
file- the file to parse.- Returns:
- the provided file as document or null.
- Throws:
IOException- if an I/O exception occurs.SAXException- if any parse errors occur.
-
getDocBuilder
Get document builder used to parse documents.- Returns:
- a document builder.
-
getTransformer
-
getNode
-
getElement
-
getElements
-
getTextContent
Get text content from element path.- Parameters:
document- the full document if the text content have any node variable to parse.element- the element to see.path- the key path.- Returns:
- a parsed string representing the found text from node at path or null.
-
getTextContentOrDefault
public String getTextContentOrDefault(Element document, Element element, String def, String... path) Get text content from element path or use default value if node don't exists.- Parameters:
document- the full document if the text content have any node variable to parse.element- the element to see.def- the default text.path- the key path.- Returns:
- a parsed string representing the found text from node at path or null.
-
toString
-