You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by bu...@apache.org on 2002/07/25 02:02:51 UTC
DO NOT REPLY [Bug 11153] New: -
getOwnerDocument() on PI that's child of Document returns NULL. (w/patch)
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=11153>.
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=11153
getOwnerDocument() on PI that's child of Document returns NULL. (w/patch)
Summary: getOwnerDocument() on PI that's child of Document
returns NULL. (w/patch)
Product: Xerces-C++
Version: Nightly build (please specify the date)
Platform: PC
OS/Version: Windows XP
Status: NEW
Severity: Normal
Priority: Other
Component: DOM
AssignedTo: xerces-c-dev@xml.apache.org
ReportedBy: ncodding@pureedge.com
Calling getOwnerDocument() on a Processing Instruction node that's a child of
the Document node should return that Document node. Instead, it is returning
NULL. If the PI is a child of the Document Element instead, it works fine.
Here's an example XML document to reproduce the problem:
----------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<?foo bar="test"?>
<xfa>
<?test foo="bar"?>
</xfa>
-----------------------------------------
After parsing this XML, calling getOwnerDocument() on the DOMNode that
represents <?foo bar="test"?> returns NULL. Calling getOwnerDocument() on the
DOMNode that represents <?test foo="bar"?> returns the proper Document node.
Here's a snippet of C++ code that demonstrates the problem. It assumes that the
DOMDocument "doc" is returned from parsing the document given above. For my
testing, I stuck this code before the counts are output in the DOMCount sample.
------------------------------------------------------------
DOMNode *currChild = doc->getFirstChild();
while (currChild)
{
if (currChild->getNodeType() == DOMNode::PROCESSING_INSTRUCTION_NODE)
{
cout << "Found a PI node child of the document node." << endl;
if (currChild->getOwnerDocument() == 0)
{
cout << ".. And its getOwnerDocument() returns NULL."
<< endl;
}
else
{
cout << ".. And its getOwnerDocument() does NOT return
NULL!" << endl;
}
}
currChild = currChild->getNextSibling();
}
currChild = ((DOMNode*)doc->getDocumentElement())->getFirstChild();
while (currChild)
{
if (currChild->getNodeType() == DOMNode::PROCESSING_INSTRUCTION_NODE)
{
cout << "Found a PI node child of the document element node."
<< endl;
if (currChild->getOwnerDocument() == 0)
{
cout << ".. And its getOwnerDocument() returns NULL."
<< endl;
}
else
{
cout << ".. And its getOwnerDocument() does NOT return
NULL!" << endl;
}
}
currChild = currChild->getNextSibling();
}
------------------------------------------------------------
The results of running this code are:
Found a PI node child of the document node.
.. And its getOwnerDocument() returns NULL.
Found a PI node child of the document element node.
.. And its getOwnerDocument() does NOT return NULL!
c:\pi_test.xft: 10 ms (1 elems).
I've created a patch that fixes this problem. It's attached, and included below:
Index: DOMNodeImpl.cpp
===================================================================
RCS file: /home/cvspublic/xml-xerces/c/src/xercesc/dom/impl/DOMNodeImpl.cpp,v
retrieving revision 1.6
diff -c -2 -r1.6 DOMNodeImpl.cpp
*** DOMNodeImpl.cpp 15 Jul 2002 19:22:22 -0000 1.6
--- DOMNodeImpl.cpp 24 Jul 2002 23:49:22 -0000
***************
*** 200,204 ****
// Leaf node types - those that cannot have children, like Text.
if (isOwned()) {
! return fOwnerNode->getOwnerDocument();
} else {
assert (fOwnerNode->getNodeType() == DOMNode::DOCUMENT_NODE);
--- 200,211 ----
// Leaf node types - those that cannot have children, like Text.
if (isOwned()) {
! if (fOwnerNode->getNodeType() == DOMNode::DOCUMENT_NODE)
! {
! return (DOMDocument*)fOwnerNode;
! }
! else
! {
! return fOwnerNode->getOwnerDocument();
! }
} else {
assert (fOwnerNode->getNodeType() == DOMNode::DOCUMENT_NODE);
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org