问题是,由于某种原因,我无法理解,我把一个bytearyoutputstream包在一个
. 因此,可能输出的前缀是对象元数据的某种序列化。
我刚刚直接使用了ByteArrayOutputStream,现在的输出如我所料。
String result = "error";
String uri = "http://example.com/uri";
String xpath = textArea.getText();
ByteArrayOutputStream bytestream = new ByteArrayOutputStream();
try {
Builder builder = new Builder();
Canonicalizer canonicalizer = new Canonicalizer(bytestream,
Canonicalizer.EXCLUSIVE_XML_CANONICALIZATION);
nu.xom.Document input = builder.build(xml, uri);
Node node = input.getRootElement();
XPathContext context = new XPathContext("a", "http://example.com/a");
Nodes nodes = node.query(xpath, context);
if (nodes.size() > 0) {
canonicalizer.write(nodes.get(0));
bytestream.close();
result = bytestream.toString("UTF8");
}
catch (...){ ... }