@Restricted(value=org.kohsuke.accmod.restrictions.NoExternalUse.class) public final class XMLUtils extends Object
Constructor and Description |
---|
XMLUtils() |
Modifier and Type | Method and Description |
---|---|
static String |
getValue(String xpath,
Document document)
The a "value" from an XML file using XPath.
|
static String |
getValue(String xpath,
File file)
The a "value" from an XML file using XPath.
|
static String |
getValue(String xpath,
File file,
String fileDataEncoding)
The a "value" from an XML file using XPath.
|
static Document |
parse(File file,
String encoding)
Parse the supplied XML file data to a
Document . |
static Document |
parse(Reader stream)
Parse the supplied XML stream data to a
Document . |
static void |
safeTransform(Source source,
Result out)
Transform the source to the output in a manner that is protected against XXE attacks.
|
public static void safeTransform(@Nonnull Source source, @Nonnull Result out) throws TransformerException, SAXException
disableXXEPrevention
to true
.source
- The XML input to transform. - This should be a StreamSource
or a
SAXSource
in order to be able to prevent XXE attacks.out
- The Result of transforming the source
.TransformerException
SAXException
@Nonnull public static Document parse(@Nonnull Reader stream) throws SAXException, IOException
Document
.
This function does not close the stream.
stream
- The XML stream.Document
.SAXException
- Error parsing the XML stream data e.g. badly formed XML.IOException
- Error reading from the steam.@Nonnull public static Document parse(@Nonnull File file, @Nonnull String encoding) throws SAXException, IOException
Document
.file
- The file to parse.encoding
- The encoding of the XML in the file.SAXException
- Error parsing the XML file data e.g. badly formed XML.IOException
- Error reading from the file.@Nonnull public static String getValue(@Nonnull String xpath, @Nonnull File file) throws IOException, SAXException, XPathExpressionException
Uses the system encoding for reading the file.
xpath
- The XPath expression to select the value.file
- The file to read.String
is returned when the expression does not evaluate
to anything in the document.IOException
- Error reading from the file.SAXException
- Error parsing the XML file data e.g. badly formed XML.XPathExpressionException
- Invalid XPath expression.@Nonnull public static String getValue(@Nonnull String xpath, @Nonnull File file, @Nonnull String fileDataEncoding) throws IOException, SAXException, XPathExpressionException
xpath
- The XPath expression to select the value.file
- The file to read.fileDataEncoding
- The file data format.String
is returned when the expression does not evaluate
to anything in the document.IOException
- Error reading from the file.SAXException
- Error parsing the XML file data e.g. badly formed XML.XPathExpressionException
- Invalid XPath expression.public static String getValue(String xpath, Document document) throws XPathExpressionException
xpath
- The XPath expression to select the value.document
- The document from which the value is to be extracted.String
is returned when the expression does not evaluate
to anything in the document.XPathExpressionException
- Invalid XPath expression.Copyright © 2004–2017. All rights reserved.