Re: XMLC digest, Vol 1 #410 - 4 msgs
Aaron Kardell <[email protected]>
| Newsgroups | gmane.comp.java.enhydra.xmlc |
|---|---|
| Message-ID | <[email protected]> |
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 ======
<html>
<head>
<title>Test</title>
</head>
<body>
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?<br><br><br><br>
<form id="RemoveJustTheForm">
1<br>
</form>
2<br><br><br>
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?<br><br><br><br>
<span id="RemoveJustTheSpan">
3<br>
</span>
4<br><br><br>
</body>
</html>
====== 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
>