How To Using Dom Importnode Without Domexception
Solution 1:
I ran into this problem too. I was getting this exception when calling either importNode() or cloneNode(). And BTW, the XML I was parsing/generating was not using namespaces.
It seems that the DOM parser (from Apache Harmony) that is included in Android is buggy. See this link: Issue 2735: Harmony DOM implementation is buggy and noncompliant. Everything works fine if the same code is executed using plain Java 1.6 (which isn't based on Harmony of course).
I tried setting setNamespaceAware(true) on the DocumentBuilder, but this did not help.
Eventually, I gave up and worked around the issue by using adoptNode() rather than importNode(). This is kind of incestuous, because it is stealing a node from one Document tree and putting it into another. But in my case, the first Document tree was only temporary, so I could do things this way.
Solution 2:
I'm guessing, but it seems that you are trying to import node with namespace defined, where your target document does not have this namespace declared.
So, what namespaces are declared in source document? Did you declare any namespaces in target document?
Solution 3:
The input is a smil String shown below:
<smil><head><layout><root-layoutheight="720"width="1280"/><transitionid="fade"type="fade"subtype="crossfade"dur="1s"/><regionid="_33_32_bkgd_image"left="0"top="0"width="1280"height="720"background-color="#c12121"showBackground="whenActive"z-index="0"></region><regionid="_33_32_I001"left="380"top="27"width="405"height="352"z-index="1"></region><regionid="_33_32_I002"left="0"top="365"width="354"height="354"z-index="2"></region></layout></head><body><seqbegin="wallclock(2011-09-22T01:52:00)"end="wallclock(2011-09-23T00:00:00)"><pardur="10s"xml:id="32"repeatCount="1"><brushcolor="#c12121"region="_33_32_bkgd_image"></brush><seqrepeatCount="indefinite"><imgxml:id="30"region="_33_32_I001"src="http://127.0.0.1/Service/User/2_user/Media/Image/30_image.jpg?JFBukihsTu"dur="5s"fit="meet"regPoint="center"regAlign="center"><metadataxml:id="meta-rdf"><metaname="MD5"content="7c8b59b28ea2247f20bc538dcb7108f3"></meta><metaname="width"content="531"></meta><metaname="height"content="720"></meta></metadata></img><imgxml:id="27"region="_33_32_I001"src="http://127.0.0.1/Service/User/2_user/Media/Image/27_image.jpg?jTqCMuIxsX"dur="5s"fit="meet"regPoint="center"regAlign="center"><metadataxml:id="meta-rdf"><metaname="MD5"content="db51409f243f79c566811d1b307a77a1"></meta><metaname="width"content="427"></meta><metaname="height"content="602"></meta></metadata></img></seq></par></seq></body></smil>
and the original Document is generated by:
DocumentBuilderFactoryfactory= DocumentBuilderFactory.newInstance();
DocumentBuilderbuilder= factory.newDocumentBuilder();
Documentdom= builder.parse(newByteArrayInputStream(smil.getBytes()));
and the seqNode represents the "seq" node (the child of body tag)
I want to copy "seq" and all of it's childs to new Document
Post a Comment for "How To Using Dom Importnode Without Domexception"