Re: Problem with implementation of getChildNodes on HTMLFormElement?

Jacob Kjome <[email protected]>
Newsgroups gmane.comp.java.enhydra.xmlc
Message-ID <[email protected]>
Hi Aaron,

Thanks for the testcase.  I have replicated the behavior but, like you, I'm 
not sure what exactly is causing it.  It should definitely be figured 
out.  I'm attaching an archive with the files so others can more easily 
test things out.  I've included a Windows batch file in addition to your 
shell script.  I also modified things very slightly, but not much.

It would be helpful if someone else would look into this.  Could be a hard 
issue to track down.  I wonder if this happens with any element other than 
an HTMLFormElement?

later,

Jake

At 10:07 AM 9/10/2003 -0500, you wrote:
>Hi Jake,
>
>I apologize for the delay in my response, but I now have a reproducible test
>case.  Below I have included three files, Test.java, TestHTML.java, and
>compile-and-run.sh.  The third file is just for ease of testing the test 
>case.
>The test case basically proves that the problem affects an HTMLFormElement but
>not an HTMLSpanElement.  Let me know if you have any questions.
>
>Regards,
>
>Aaron
>
>====== Test.java BEGIN ======
>import org.w3c.dom.*;
>import org.w3c.dom.html.*;
>
>public class Test {
>     public static void removeNodeButNotChildren(Node node, boolean
>callGetFirstChild) {
>         Node parentNode = node.getParentNode();
>         Node siblingNode = node.getNextSibling();
>         if (callGetFirstChild)
>             node.getFirstChild();     // Detected a bug wherein sometimes
>childNodeList would have a length of 0, when there obviously were child nodes;
>calling getFirstChild first apparently clears this up??
>         NodeList childNodeList = node.getChildNodes();
>         Node[] childNodes = new Node[childNodeList.getLength()];
>         for (int x = 0; x < childNodeList.getLength(); x++)
>             childNodes[x] = childNodeList.item(x);
>
>         for (int x = 0; x < childNodes.length; x++) {
>             Node nextNode = childNodes[x];
>
>             node.removeChild(nextNode);
>             if (siblingNode != null)
>                 parentNode.insertBefore(nextNode, siblingNode);
>             else
>                 parentNode.appendChild(nextNode);
>         }
>         parentNode.removeChild(node);
>     }
>
>     public static void main(String [] args) {
>         System.out.println("First test involves NOT calling getFirstChild 
> before
>getChildNodes().");
>         TestHTML testHTML1 = new TestHTML();
>         removeNodeButNotChildren(testHTML1.getElementRemoveJustTheForm(), 
> false);
>         removeNodeButNotChildren(testHTML1.getElementRemoveJustTheSpan(), 
> false);
>         System.out.println(testHTML1.toDocument());
>         System.out.println("");
>
>         System.out.println("First test involves calling getFirstChild before
>getChildNodes().");
>         TestHTML testHTML2 = new TestHTML();
>         removeNodeButNotChildren(testHTML2.getElementRemoveJustTheSpan(), 
> true);
>         System.out.println(testHTML2.toDocument());
>         System.out.println("");
>     }
>}
>====== Test.java END ======
>
>====== TestHTML.html BEGIN ======
>Below you will see a test. If you see the numbers 1 and 2, the test worked 
>as it should. If you only see the number 2, then there is an error in the 
>implementation of getChildNodes at least on a HTMLFormElement and perhaps 
>on others?
>
>
>
>1
>2
>
>
>Below you will see another test. If you see the numbers 3 and 4, the test 
>worked as it should. If you only see the number 4, then there is an error 
>in the implementation of getChildNodes at least on a HTMLSpanElement and 
>perhaps on others?
>
>
>
>3
>4
>
>
>====== TestHTML.html END ======
>
>====== compile-and-run.sh BEGIN ======
>#!/bin/sh
>
>java -classpath
>"xercesImpl.jar:xmlc-all-runtime.jar:xml-apis.jar:gnu-regexp.jar:jtidy.jar"
>org.enhydra.xml.xmlc.commands.xmlc.XMLC -keep -nocompile TestHTML.html
>javac -classpath
>"xercesImpl.jar:xmlc-all-runtime.jar:xml-apis.jar:gnu-regexp.jar:jtidy.jar"
>TestHTML.java
>javac -classpath
>".:xercesImpl.jar:xmlc-all-runtime.jar:xml-apis.jar:gnu-regexp.jar:jtidy.jar"
>Test.java
>java -classpath
>".:xercesImpl.jar:xmlc-all-runtime.jar:xml-apis.jar:gnu-regexp.jar:jtidy.jar" 
>Test
>====== compile-and-run.sh END ======
>
> > Date: Thu, 04 Sep 2003 23:26:25 -0500
> > To: [email protected]
> > From: Jacob Kjome <[email protected]>
> > Subject: Re: Xmlc:  Problem with implementation of getChildNodes on
> >   HTMLFormElement?
> > Reply-To: [email protected]
> >
> > Hi Aaron,
> >
> > Does this only happen with an HTMLFormElement?  Can you reproduce this
> > consistently with any other elements?  Have you checked Apache's bug
> > database ( http://issues.apache.org/bugzilla/ ) for something like this
> > reported against Xerces-1.x.x?  Also, can you provide a simple testcase
> > that we can try out to reproduce the bug?  If this truly is a bug, it
> > definitely is something that needs fixing.  Maybe an XMLC-2.2.1 release
> > would be in order after this bug gets fixed.
> >
> > Jake
> >
> > At 11:04 AM 9/4/2003 -0500, you wrote:
> > >Greetings,
> > >
> > >I've noticed an interesting bug that I'm wondering if anyone else can
> > >duplicate.
> > >  Given an HTMLFormElement (from an XMLC template), try calling
> > > getChildNodes()
> > >on something that obviously has child nodes.  I have a specific instance
> > where
> > >it is returning a NodeList with a length of 0.  However, the interesting
> > thing
> > >is that if I call getFirstChild before I call getChildNodes, it returns a
> > >NodeList with the appropriate children filled in.  Briefly skimming
> > >through the
> > >code that implements this, it appears that maybe there's some kind of a
> > >synchronization problem; however, I was unable to pinpoint it.
> > >
> > >Any thoughts?
> > >
> > >Aaron
> > >---
> > >Aaron Kardell
> > >Development Manager & Chief Architect of SIPS
> > >Altona Ed, LLC <http://www.altonaed.com/>
> > >[email protected]
> > >
> > >_______________________________________________
> > >XMLC mailing list
> > >[email protected]
> > >http://www.enhydra.org/mailman/listinfo.cgi/xmlc
> >
> >
> >
> > --__--__--
> >
> > _______________________________________________
> > XMLC mailing list
> > [email protected]
> > http://www.enhydra.org/mailman/listinfo.cgi/xmlc
> >
> >
> > End of XMLC Digest
> >
>
>----- End forwarded message -----
>
>_______________________________________________
>XMLC mailing list
>[email protected]
>http://www.enhydra.org/mailman/listinfo.cgi/xmlc
form_childnodes_test.zip (application/zip, 1.8 KB) - not displayed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.