本文整理了Java中play.libs.XML
类的一些代码示例,展示了XML
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XML
类的具体详情如下:
包路径:play.libs.XML
类名称:XML
[英]XML utilities.
[中]XML实用程序。
代码示例来源:origin: com.typesafe.play/play_2.10
/**
* Parse an XML string as DOM.
*/
public static Document fromString(String xml) {
try {
return fromInputStream(
new ByteArrayInputStream(xml.getBytes("utf-8")),
"utf-8"
);
} catch(UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: com.typesafe.play/play
/**
* Parses an InputStream as DOM.
* @param in the inputstream to parse.
* @param encoding the encoding of the input stream, if not null.
* @return the parsed XML DOM.
*/
public static Document fromInputStream(InputStream in, String encoding) {
InputSource is = new InputSource(in);
if (encoding != null) {
is.setEncoding(encoding);
}
return fromInputSource(is);
}
代码示例来源:origin: com.typesafe.play/play
return ByteString.fromString(Json.stringify((JsonNode) body));
} else if (body instanceof Document) {
return XML.toBytes((Document) body);
} else {
Map<String, String[]> form = asFormUrlEncoded();
代码示例来源:origin: com.google.code.maven-play-plugin.org.playframework/play
private static Document getXml(String response, String encoding) {
try {
InputSource source = new InputSource(new StringReader(response));
source.setEncoding(encoding);
DocumentBuilder builder = XML.newDocumentBuilder();
return builder.parse(source);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: com.google.code.maven-play-plugin.org.playframework/play
public RenderXml(Document document) {
this.xml = XML.serialize(document);
}
代码示例来源:origin: com.google.code.maven-play-plugin.org.playframework/play
public static DocumentBuilder newDocumentBuilder() {
try {
return newDocumentBuilderFactory().newDocumentBuilder();
} catch (ParserConfigurationException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: com.typesafe.play/play_2.12
return ByteString.fromString(Json.stringify((JsonNode) body));
} else if (body instanceof Document) {
return XML.toBytes((Document) body);
} else {
Map<String, String[]> form = asFormUrlEncoded();
代码示例来源:origin: com.google.code.maven-play-plugin.org.playframework/play
/**
* parse and get the response body as a {@link Document DOM document}
*
* @param encoding
* xml charset encoding
* @return a DOM document
*/
public Document getXml(String encoding) {
try {
InputSource source = new InputSource(new StringReader(getString()));
source.setEncoding(encoding);
DocumentBuilder builder = XML.newDocumentBuilder();
return builder.parse(source);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: com.typesafe.play/play_2.11
/**
* Parses an XML string as DOM.
*
* @param xml the input XML string
* @return the parsed XML DOM root.
*/
public static Document fromString(String xml) {
try {
return fromInputStream(
new ByteArrayInputStream(xml.getBytes("utf-8")),
"utf-8"
);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: com.typesafe.play/play_2.11
/**
* Parses an InputStream as DOM.
* @param in the inputstream to parse.
* @param encoding the encoding of the input stream, if not null.
* @return the parsed XML DOM.
*/
public static Document fromInputStream(InputStream in, String encoding) {
InputSource is = new InputSource(in);
if (encoding != null) {
is.setEncoding(encoding);
}
return fromInputSource(is);
}
代码示例来源:origin: com.typesafe.play/play_2.11
return ByteString.fromString(Json.stringify((JsonNode) body));
} else if (body instanceof Document) {
return XML.toBytes((Document) body);
} else {
Map<String, String[]> form = asFormUrlEncoded();
代码示例来源:origin: com.google.code.maven-play-plugin.org.playframework/play
/**
* Parse an XML string content to DOM
*
* @param xml
* The XML string
* @return null if an error occurs during parsing.
*/
public static Document getDocument(String xml) {
InputSource source = new InputSource(new StringReader(xml));
try {
return newDocumentBuilder().parse(source);
} catch (SAXException e) {
Logger.warn("Parsing error when building Document object from xml data.", e);
} catch (IOException e) {
Logger.warn("Reading error when building Document object from xml data.", e);
}
return null;
}
代码示例来源:origin: com.typesafe.play/play_2.12
/**
* Parses an XML string as DOM.
*
* @param xml the input XML string
* @return the parsed XML DOM root.
*/
public static Document fromString(String xml) {
try {
return fromInputStream(
new ByteArrayInputStream(xml.getBytes("utf-8")),
"utf-8"
);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: com.typesafe.play/play_2.12
/**
* Parses an InputStream as DOM.
* @param in the inputstream to parse.
* @param encoding the encoding of the input stream, if not null.
* @return the parsed XML DOM.
*/
public static Document fromInputStream(InputStream in, String encoding) {
InputSource is = new InputSource(in);
if (encoding != null) {
is.setEncoding(encoding);
}
return fromInputSource(is);
}
代码示例来源:origin: com.google.code.maven-play-plugin.org.playframework/play
/**
* Parse an XML coming from an input stream to DOM
*
* @param stream
* The XML stream
* @return null if an error occurs during parsing.
*/
public static Document getDocument(InputStream stream) {
try {
return newDocumentBuilder().parse(stream);
} catch (SAXException e) {
Logger.warn("Parsing error when building Document object from xml data.", e);
} catch (IOException e) {
Logger.warn("Reading error when building Document object from xml data.", e);
}
return null;
}
代码示例来源:origin: com.typesafe.play/play
/**
* Parses an XML string as DOM.
*
* @param xml the input XML string
* @return the parsed XML DOM root.
*/
public static Document fromString(String xml) {
try {
return fromInputStream(
new ByteArrayInputStream(xml.getBytes("utf-8")),
"utf-8"
);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: com.typesafe.play/play_2.12
/**
* Set a XML to this request.
* The <tt>Content-Type</tt> header of the request is set to <tt>application/xml</tt>.
*
* @param xml the XML
* @return the modified builder
*/
public RequestBuilder bodyXml(InputSource xml) {
return bodyXml(XML.fromInputSource(xml));
}
代码示例来源:origin: com.google.code.maven-play-plugin.org.playframework/play
/**
* Parse an XML file to DOM
*
* @param file
* The XML file
* @return null if an error occurs during parsing.
*
*/
public static Document getDocument(File file) {
try {
return newDocumentBuilder().parse(file);
} catch (SAXException e) {
Logger.warn("Parsing error when building Document object from xml file '" + file + "'.", e);
} catch (IOException e) {
Logger.warn("Reading error when building Document object from xml file '" + file + "'.", e);
}
return null;
}
代码示例来源:origin: com.typesafe.play/play
@Override
protected Document parse(Http.RequestHeader request, ByteString bytes) throws Exception {
return XML.fromInputStream(bytes.iterator().asInputStream(), request.charset().orElse(null));
}
}
代码示例来源:origin: com.typesafe.play/play_2.11
/**
* Set a XML to this request.
* The <tt>Content-Type</tt> header of the request is set to <tt>application/xml</tt>.
*
* @param xml the XML
* @return the modified builder
*/
public RequestBuilder bodyXml(InputSource xml) {
return bodyXml(XML.fromInputSource(xml));
}
内容来源于网络,如有侵权,请联系作者删除!