Extension: The E4X XML constructor can now create XML directly from a Java

DOM node. Previously the implementation would have converted to a String
and attempted to reparse.
This commit is contained in:
nboyd%atg.com 2007-11-20 16:08:53 +00:00
Родитель 427077fe19
Коммит c48334d311
2 изменённых файлов: 15 добавлений и 0 удалений

Просмотреть файл

@ -422,6 +422,15 @@ public final class XMLLibImpl extends XMLLib implements Serializable {
}
// TODO Technically we should fail on anything except a String, Number or Boolean
// See ECMA357 10.3
// Extension: if object is a DOM node, use that to construct the XML
// object.
if (object instanceof Wrapper) {
object = ((Wrapper) object).unwrap();
}
if (object instanceof org.w3c.dom.Node) {
org.w3c.dom.Node node = (org.w3c.dom.Node) object;
return newXML(XmlNode.createElementFromNode(node));
}
// Instead we just blindly cast to a String and let them convert anything.
String s = ScriptRuntime.toString(object);
// TODO Could this get any uglier?

Просмотреть файл

@ -98,6 +98,12 @@ class XmlNode {
return createImpl( processor.newDocument().createTextNode(value) );
}
static XmlNode createElementFromNode(Node node) {
if (node instanceof Document)
node = ((Document) node).getDocumentElement();
return createImpl(node);
}
static XmlNode createElement(XmlProcessor processor, String namespaceUri, String xml) throws org.xml.sax.SAXException {
return createImpl( processor.toXml(namespaceUri, xml) );
}