[ http://issues.apache.org/jira/browse/XERCESJ-1180?page=all ]

Michael Glavassevich updated XERCESJ-1180:
------------------------------------------

    Fix Version/s: 2.8.1

> Document root changes indirectly during DeferredDocumentImpl children 
> modification
> ----------------------------------------------------------------------------------
>
>                 Key: XERCESJ-1180
>                 URL: http://issues.apache.org/jira/browse/XERCESJ-1180
>             Project: Xerces2-J
>          Issue Type: Bug
>          Components: DOM (Level 3 Core)
>    Affects Versions: 2.8.0
>         Environment: java version "1.5.0_06"
> Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
> Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)
>            Reporter: Yury Semikhatsky
>         Assigned To: Michael Glavassevich
>             Fix For: 2.8.1
>
>
> In the example below last line causes org.w3c.dom.DOMException because 
> document root is already defined.
> import java.io.ByteArrayInputStream;
> import java.io.InputStream;
> import javax.xml.parsers.DocumentBuilder;
> import javax.xml.parsers.DocumentBuilderFactory;
> import org.w3c.dom.Document;
> import org.w3c.dom.Element;
> public class SetRootTest {
>     public static void main(String[] args) throws Exception {
>         DocumentBuilder builder = 
> DocumentBuilderFactory.newInstance().newDocumentBuilder();
>         InputStream inputStream = new 
> ByteArrayInputStream("<root><a><b/></a></root>".getBytes());
>         Document document = builder.parse(inputStream);
>         Element root = document.getDocumentElement();
>         Element a = (Element) root.getChildNodes().item(0);
>         document.removeChild(root);
>         System.out.println(document.getDocumentElement());
>         
>         a.getFirstChild();
>         
>         System.out.println(document.getDocumentElement());
>         
>         document.appendChild(root);//exception here
>     }
> }
> The program output:
> null
> [b: null]
> Exception in thread "main" org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: 
> An attempt was made to insert a node where it is not permitted. 
>     at 
> com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.insertBefore(CoreDocumentImpl.java:419)
>     at 
> com.sun.org.apache.xerces.internal.dom.NodeImpl.appendChild(NodeImpl.java:275)
>     at SetRootTest.main(SetRootTest.java:27)

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to