更新时间:2021-12-05 00:40:27
你可以在java - 你应该能够得到Rhino等价物:
You can do this in java - you should be able to derive the Rhino equivalent:
DocumentBuilderFactory dbFactory = javax.xml.parsers.DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.newDocument();
Element el = doc.createElement('test');
doc.appendChild(el);
String xml = "<foo bar=\"1\">Hi <baz>there</baz></foo>";
Document doc2 = builder.parse(new ByteArrayInputStream(xml.getBytes()));
Node node = doc.importNode(doc2.getDocumentElement(), true);
el.appendChild(node);
由于 doc
和 doc2
是两个不同的文档
,诀窍是将节点从一个文档导入到另一个文档,这是通过 importNode
api高于
Since doc
and doc2
are two different Document
s the trick is to import the node from one document to another, which is done with the importNode
api above