Package net.bluemind.utils
Class DOMUtils
java.lang.Object
net.bluemind.utils.DOMUtils
Utility methods to extract data from a DOM.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intcountElementsForTag(Element root, String tagName) static Documentstatic ElementcreateElement(Element parent, String elementName) static ElementcreateElementAndText(Element parent, String elementName, String text) static ElementcreateElementAndText(Element parent, String namespace, String elementName, String text) static ElementfindElementWithUniqueAttribute(Element root, String elementName, String attribute, String attributeValue) static voidforEachElement(Element root, String elementName, Consumer<Element> cons) static String[][]getAttributes(Element root, String elementName, String[] wantedAttributes) Renvoie sous la forme d'un tableau la valeur des attributs donnés pour toutes les occurences d'un élément donnée dans le domet getAttributes(<toto>, "titi", { "id", "val" }) renvoie { { "a", "ba" } { "b", "bb" } }static StringgetElementAttribute(Element root, String elementName, String attribute) Renvoie la valeur de l'attribut donné, d'un élément donné qui doit être unique sous l'élément racinestatic StringgetElementText(Element node) static StringgetElementText(Element root, String elementName) static String[]static ElementgetUniqueElement(Element root, String elementName) Renvoie une élément qui doit être unique dans le document.static Stringstatic Documentstatic Documentparse(InputStream is) static voidsaxParse(InputStream is, DefaultHandler handler) static voidserialise(Document doc, OutputStream out) static final StringThis method ensures that the output String has only valid XML unicode characters as specified by the XML 1.0 standard.
-
Constructor Details
-
DOMUtils
public DOMUtils()
-
-
Method Details
-
getElementText
-
getElementText
-
getTexts
-
countElementsForTag
-
getAttributes
Renvoie sous la forme d'un tableau la valeur des attributs donnés pour toutes les occurences d'un élément donnée dans le domet getAttributes(<toto>, "titi", { "id", "val" }) renvoie { { "a", "ba" } { "b", "bb" } }- Parameters:
root-elementName-wantedAttributes-- Returns:
-
getElementAttribute
Renvoie la valeur de l'attribut donné, d'un élément donné qui doit être unique sous l'élément racine- Parameters:
root-elementName-attribute-- Returns:
-
getUniqueElement
Renvoie une élément qui doit être unique dans le document.- Parameters:
root-elementName-- Returns:
-
forEachElement
-
findElementWithUniqueAttribute
-
stripNonValidXMLCharacters
This method ensures that the output String has only valid XML unicode characters as specified by the XML 1.0 standard. For reference, please see the standard. This method will return an empty String if the input is null or empty.- Parameters:
in- The String whose non-valid characters we want to remove.- Returns:
- The in String, stripped of non-valid characters.
-
createElementAndText
-
createElementAndText
-
createElement
-
serialise
- Throws:
TransformerException
-
logDom
- Throws:
TransformerException
-
parse
public static Document parse(InputStream is) throws SAXException, IOException, ParserConfigurationException, FactoryConfigurationError -
parse
public static Document parse(File f) throws SAXException, IOException, ParserConfigurationException, FactoryConfigurationError -
createDoc
public static Document createDoc(String namespace, String rootElement) throws ParserConfigurationException, FactoryConfigurationError -
saxParse
public static void saxParse(InputStream is, DefaultHandler handler) throws SAXException, IOException, ParserConfigurationException
-