我有我的资源和它们处理 POST 请求的典型重写方法。
public void acceptRepresentation(Representation rep) {
if (MediaType.APPLICATION_XML.equals(rep.getMediaType())) {
//Do stuff here
}
else {
//complain!
}
}
我想知道的是处理我的 XML 数据包的最佳实践。我看到很多使用 Form 的示例 - 但肯定有一种方法可以使用 Representation 对象本身或将其转换为一些有用的 XML 对象???
对于您应该如何解析资源中传入的 XML 的任何帮助,我们都非常感激。
最佳答案
这更像是我想要的回应。感谢Thierry Boileau答案:
You can use two kinds of "XML representations": DomRepresentation and SaxRepresentation. You can instantiate both of them with the posted representation. E.g.: DomRepresentation xmlRep = new DomRepresentation(rep);
The DomRepresentation gives you access to the Dom document. The SaxRepresentation allows you to parse the XML doc with your own contentHandler. See the javadocs here 1 and here 2.
关于java - REST Web 服务使用 ReSTLet 接受 POST - 最佳实践,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/440989/