Package fr.becpg.common.dom
Class DOMUtils
java.lang.Object
fr.becpg.common.dom.DOMUtils
Méthodes utilitaires pour extraire des infos d'un DOM.
- Version:
- $Id: $Id
- Author:
- tom, matthieu
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic DocumentcreateDoc.static ElementcreateDoc.static ElementcreateElement(Element parent, String elementName) createElement.static ElementcreateElementAndText(Element parent, String elementName, String text) createElementAndText.static ElementfindElementWithUniqueAttribute(Element root, String elementName, String attribute, String attributeValue) findElementWithUniqueAttribute.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 domstatic 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 root) getElementText.static StringgetElementText(Element root, String elementName) getElementText.static String[]getTexts.static ElementgetUniqueElement(Element root, String elementName) Renvoie une élément qui doit être unique dans le document.static ElementgetUniqueXPathElement(Element root, String xpath) getUniqueXPathElement.static StringgetUniqueXPathTextElement(Element root, String xpath) getUniqueXPathTextElement.static NodeListgetXPathNodes(Element root, String xpath) getXPathNodes.static voidlogDom.static Documentparse(InputStream is) parse.static voidserialise(Document doc, OutputStream out) serialise.static voidserialise(Document doc, OutputStream out, boolean keepXmlDecl) serialise.
-
Field Details
-
logger
private static final org.apache.commons.logging.Log logger
-
-
Constructor Details
-
DOMUtils
private DOMUtils()
-
-
Method Details
-
getElementText
getElementText.
-
getElementText
getElementText.
-
getTexts
getTexts.
-
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 dom<toto> <titi id="a" val="ba"/> <titi id="b" val="bb"/> </toto>et getAttributes(<toto>, "titi", { "id", "val" }) renvoie { { "a", "ba" } { "b", "bb" } } -
getElementAttribute
Renvoie la valeur de l'attribut donné, d'un élément donné qui doit être unique sous l'élément racine -
getUniqueElement
Renvoie une élément qui doit être unique dans le document. -
getUniqueXPathElement
public static Element getUniqueXPathElement(Element root, String xpath) throws XPathExpressionException getUniqueXPathElement.
- Parameters:
root- aElementobject.xpath- aStringobject.- Returns:
- a
Elementobject. - Throws:
XPathExpressionException- if any.
-
getUniqueXPathTextElement
public static String getUniqueXPathTextElement(Element root, String xpath) throws XPathExpressionException getUniqueXPathTextElement.
- Parameters:
root- aElementobject.xpath- aStringobject.- Returns:
- a
Stringobject. - Throws:
XPathExpressionException- if any.
-
getXPathNodes
getXPathNodes.
- Parameters:
root- aElementobject.xpath- aStringobject.- Returns:
- a
NodeListobject. - Throws:
XPathExpressionException- if any.
-
findElementWithUniqueAttribute
public static Element findElementWithUniqueAttribute(Element root, String elementName, String attribute, String attributeValue) findElementWithUniqueAttribute.
-
createElementAndText
createElementAndText.
-
createElement
createElement.
-
serialise
serialise.
- Parameters:
doc- aDocumentobject.out- aOutputStreamobject.- Throws:
TransformerException- if any.
-
serialise
public static void serialise(Document doc, OutputStream out, boolean keepXmlDecl) throws TransformerException serialise.
- Parameters:
doc- aDocumentobject.out- aOutputStreamobject.keepXmlDecl- a boolean.- Throws:
TransformerException- if any.
-
logDom
logDom.
- Parameters:
doc- aDocumentobject.- Throws:
TransformerException- if any.
-
parse
public static Document parse(InputStream is) throws SAXException, IOException, ParserConfigurationException, FactoryConfigurationError parse.
- Parameters:
is- aInputStreamobject.- Returns:
- a
Documentobject. - Throws:
SAXException- if any.IOException- if any.ParserConfigurationException- if any.FactoryConfigurationError- if any.
-
createDoc
createDoc.
- Returns:
- a
Documentobject. - Throws:
ParserConfigurationException- if any.FactoryConfigurationError- if any.
-
createDoc
public static Element createDoc(String rootNodeName) throws ParserConfigurationException, FactoryConfigurationError createDoc.
- Parameters:
rootNodeName- aStringobject.- Returns:
- a
Elementobject. - Throws:
ParserConfigurationException- if any.FactoryConfigurationError- if any.
-