Package org.hl7.fhir.utilities.xml
Class XMLUtil
java.lang.Object
org.hl7.fhir.utilities.xml.XMLUtil
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Elementstatic ElementaddTextTag(Document doc, Element element, String name, String text, int indent) static voidstatic booleancharSetImpliesAscii(String charset) static Node[]static voidclearChildren(Node node) static voiddeleteAttr(Element e, String namespaceURI, String localName) static voiddeleteByName(Element e, String name) static StringdetermineEncoding(InputStream stream) static Stringstatic StringConverts the raw characters to XML escape characters.static StringgetDirectText(Element node) static Elementstatic ElementgetFirstChild(Element res, String... names) static Elementstatic ElementgetLastChild(Element res, String... names) static ElementgetNamedChild(Element e, String name) static StringgetNamedChildAttribute(Element element, String name, String aname) static ElementgetNamedChildByAttribute(Element e, String name, String nname, String nvalue) getNamedChildren(Element e, String name) static voidgetNamedChildren(Element e, String name, List<Element> set) static voidgetNamedChildrenWithTails(Element focus, String name, List<Element> children, Set<String> typeTails) static voidgetNamedChildrenWithWildcard(Element focus, String name, List<Element> children) static StringgetNamedChildText(Element element, String name) static StringgetNamedChildValue(Element element, String name) static Elementstatic Elementstatic StringgetXsiType(Element element) static XMLReaderThis method is used to create a new XMLReader instance from a passed SAXParserFactory with external processing features configured securely.static booleanhasNamedChild(Element e, String name) static StringhtmlToXmlEscapedPlainText(String definition) static Stringstatic ElementinsertChild(Document doc, Element element, String name, String namespace, int indent) static Elementstatic booleanstatic booleanisNMTokenChar(char c) static DocumentBuilderFactoryThis method is used to create a new DocumentBuilderFactory instance with external processing features configured securely.static SAXParserFactoryThis method is used to create a new SAXParserFactory instance with external processing features configured securely.static TransformerFactoryThis method is used to create a new TransformerFactory instance with external processing features configured securely.static DocumentparseFileToDom(String filename) static DocumentparseFileToDom(String filename, boolean ns) static DocumentparseToDom(byte[] content) static DocumentparseToDom(byte[] content, boolean ns) static DocumentparseToDom(String content) static DocumentparseToDom(String content, boolean ns) static voidsaveToFile(Element root, OutputStream stream) static voidsetNamedChildValue(Element element, String name, String value) static voidstatic voidwriteDomToFile(Document doc, String filename)
-
Field Details
-
SPACE_CHAR
- See Also:
-
SAX_FEATURES_EXTERNAL_GENERAL_ENTITIES
- See Also:
-
APACHE_XML_FEATURES_DISALLOW_DOCTYPE_DECL
- See Also:
-
-
Constructor Details
-
XMLUtil
public XMLUtil()
-
-
Method Details
-
isNMToken
-
isNMTokenChar
-
determineEncoding
- Throws:
IOException
-
charSetImpliesAscii
-
escapeXML
Converts the raw characters to XML escape characters.- Parameters:
rawContent-charset- Null when charset is not known, so we assume it's unicodeisNoLines-- Returns:
- escape string
-
getFirstChild
-
getNamedChild
-
getNamedChildByAttribute
-
getNextSibling
-
getNamedChildren
-
getNamedChildren
-
htmlToXmlEscapedPlainText
-
htmlToXmlEscapedPlainText
public static String htmlToXmlEscapedPlainText(String definition) throws ParserConfigurationException, SAXException, IOException -
elementToString
-
getNamedChildValue
-
setNamedChildValue
public static void setNamedChildValue(Element element, String name, String value) throws FHIRException - Throws:
FHIRException
-
getNamedChildrenWithWildcard
-
getNamedChildrenWithTails
-
hasNamedChild
-
parseToDom
public static Document parseToDom(String content) throws ParserConfigurationException, SAXException, IOException -
parseToDom
public static Document parseToDom(byte[] content) throws ParserConfigurationException, SAXException, IOException -
parseToDom
public static Document parseToDom(String content, boolean ns) throws ParserConfigurationException, SAXException, IOException -
parseToDom
public static Document parseToDom(byte[] content, boolean ns) throws ParserConfigurationException, SAXException, IOException -
parseFileToDom
public static Document parseFileToDom(String filename) throws ParserConfigurationException, SAXException, IOException -
parseFileToDom
public static Document parseFileToDom(String filename, boolean ns) throws ParserConfigurationException, SAXException, IOException -
getLastChild
-
getPrevSibling
-
getNamedChildAttribute
-
newXXEProtectedTransformerFactory
This method is used to create a new TransformerFactory instance with external processing features configured securely. IMPORTANT This method should be the only place where TransformerFactory is instantiated in this project.- Returns:
- A TransformerFactory instance external processing features configured securely.
-
newXXEProtectedDocumentBuilderFactory
public static DocumentBuilderFactory newXXEProtectedDocumentBuilderFactory() throws ParserConfigurationExceptionThis method is used to create a new DocumentBuilderFactory instance with external processing features configured securely. IMPORTANT This method should be the only place where DocumentBuilderFactory is instantiated in this project.- Returns:
- A DocumentBuilderFactory instance external processing features configured securely.
- Throws:
ParserConfigurationException- If a DocumentBuilder cannot be configured with the requested features.
-
newXXEProtectedSaxParserFactory
public static SAXParserFactory newXXEProtectedSaxParserFactory() throws SAXNotSupportedException, SAXNotRecognizedException, ParserConfigurationExceptionThis method is used to create a new SAXParserFactory instance with external processing features configured securely. IMPORTANT This method should be the only place where SAXParserFactory is instantiated in this project.- Returns:
- A SAXParserFactory instance external processing features configured securely.
- Throws:
SAXNotSupportedException- When the underlying XMLReader recognizes the property name but doesn't support the property.SAXNotRecognizedException- When the underlying XMLReader does not recognize the property name.ParserConfigurationException- If a SAXParser cannot be configured with the requested features.
-
getXXEProtectedXMLReader
public static XMLReader getXXEProtectedXMLReader(SAXParserFactory spf) throws ParserConfigurationException, SAXException This method is used to create a new XMLReader instance from a passed SAXParserFactory with external processing features configured securely. IMPORTANT This method should be the only place where getXMLReader() is called in this project.- Parameters:
spf- The SAXParserFactory to create the XMLReader from.- Returns:
- A XMLReader instance external processing features configured securely.
- Throws:
ParserConfigurationException- If a SAXParser cannot be configured with the requested features.SAXException- If any SAX exceptions occur during the creation of the XMLReader.
-
writeDomToFile
public static void writeDomToFile(Document doc, String filename) throws TransformerException, IOException - Throws:
TransformerExceptionIOException
-
getXsiType
-
getDirectText
-
deleteByName
-
deleteAttr
-
children
-
addChild
-
insertChild
-
insertChild
-
addTextTag
-
addTextTag
-
saveToFile
- Throws:
TransformerException
-
spacer
-
getNamedChildText
-
getFirstChild
-
getLastChild
-
clearChildren
-