DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=21869>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=21869

Discrepancy in behviour of adoptNode and its children

           Summary: Discrepancy in behviour of adoptNode and its children
           Product: Xerces2-J
           Version: 2.4.0
          Platform: Sun
        OS/Version: Solaris
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: DOM
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]
                CC: [EMAIL PROTECTED]


I am attaching a zip file with the code, xml files and README to reproduce this
problem. According to the spec all descendants of the source element are
recursively adopted when using the adoptNode of Document.

However note the FirstName element in following outputs. See output 1 where it
fails to get the child nodes. Output 2 is obtained by uncommenting line 58 and 59


public class Test {
    final static String XML_SCHEMA = "http://www.w3.org/2001/XMLSchema";;

    final static String SCHEMA_LANGUAGE =
        "http://java.sun.com/xml/jaxp/properties/schemaLanguage";;

    public static void main (String args[]){

        MyErrorHandler eh = new MyErrorHandler();


        try {
            System.setProperty(DOMImplementationRegistry.PROPERTY,
                "org.apache.xerces.dom.DOMImplementationSourceImpl");

            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

            dbf.setNamespaceAware(true);
            dbf.setValidating(true);

            DocumentBuilder docBuilder = dbf.newDocumentBuilder();
            docBuilder.setErrorHandler(eh);

            //1. Parsing the first xml file

            Document document = docBuilder.parse("userInfo.xml");

            //2. Getting the element        

            Element firstName1 = (Element)document.getElementsByTagName
                           ("FirstName").item(0);


           // Uncomment this line and you will see the child nodes values

            /*System.out.println("TextContent of the node to be adopted: " 
                  +firstName1.getTextContent());*/


            // I am setting the schema validation property once
            // the xml file with external dtd is parsed

            dbf.setAttribute(SCHEMA_LANGUAGE, XML_SCHEMA);

            DocumentBuilder docBuilder1 = dbf.newDocumentBuilder();
            docBuilder1.setErrorHandler(eh);


            //3. Parsing the second xml file
            Document accDocument = docBuilder1.parse("accountInfo.xml");

            //4. Not sure if right but trying to get the right place to
            //   fit the adopted node

           Element firstName =(Element) accDocument.getElementsByTagNameNS
                 ("http://www.auctionportal.org/Accounts","FirstName";).item(0);

           Element parent =(Element) firstName.getParentNode();

            //5. Now invoking the adoptNode
            Element adoptedAccount = (Element)accDocument.adoptNode(firstName1);

           //6.  Using the  adoptedAccount is this right?
           parent.replaceChild(adoptedAccount,firstName);


           DOMImplementationRegistry registry = DOMImplementationRegistry
                  .newInstance();
           DOMImplementationLS impl = (DOMImplementationLS)registry.
                  getDOMImplementation("LS-Load");

           DOMWriter writer = impl.createDOMWriter();
           writer.writeNode(System.out,accDocument);

        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}



Output 1
=============
<?xml version="1.0"?>
<acc:Account acc:accountID="1" xmlns="http://www.auctionportal.org/Accounts";
xmlns:acc="http://www.auctionportal.org/Accounts";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:schemaLocation="http://www.auctionportal.org/Accounts accountInfo.xsd">

   <FirstName xmlns="">
   </FirstName><LastName>Green</LastName>
   <UserID>744</UserID>
   <Role><Sell/></Role>




Output 2
==============
<?xml version="1.0"?>
<acc:Account acc:accountID="1" xmlns="http://www.auctionportal.org/Accounts";
xmlns:acc="http://www.auctionportal.org/Accounts";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:schemaLocation="http://www.auctionportal.org/Accounts accountInfo.xsd">

   <FirstName xmlns="">King
      </FirstName>
   <LastName>Green</LastName>
   <UserID>744</UserID>
   <Role><Sell/></Role>

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

Reply via email to