Note that ConstraintTypes->getFirstChild()->getNextSibling() assumes there
will be whitespace between the ConstraintTypes and AccessControlGroups start
tags. It would be more robust to check the type of each node you encounter
and skip it if you determine that it's text you don't care about.

That said, I don't see where in your code you navigate from the
AccessControlGroups element to its next sib. You're navigating through its
children, but AccessControlGroups has no children (other than a text node
for the whitespace between the start and end tags) in your sample document.
In the document provided,
AccessControlGroups->getNextSibling()->getNextSibling() should return the
Type element (not that I'm recommending such unsafe code!).

-----Original Message-----
From: Andreas B. Thun [mailto:[EMAIL PROTECTED]
Sent: Wednesday, March 19, 2003 1:03 PM
To: [EMAIL PROTECTED]
Subject: parsing DOM tree: how can I access two different siblings?


Hi,

how can I get the node for the element <Type>?
With my code I only get the node for <AccessControlGroups>.
Both are siblings, but getNextSibling() does not return any <Type>...

ConstraintTypes->getFirstChild()->getNextSibling();
<Type> is definitely not the first child, but there
is nothing like getNextChild()...

part of my code:
----------------
     // XML doc root element
     DOMDocument *DomDoc = parser->getDocument();
     DOMElement *rootElem = DomDoc->getDocumentElement();

     // <ConstraintTypes> (1)
     DOMNode *ConstraintTypes = DomDoc->getDocumentElement();
     nodeName = ConstraintTypes->getNodeName();
     chNodeName = XMLString::transcode (nodeName);
     std::cout << chNodeName << std::endl;
     delete [] chNodeName;

     // <AccessControlGroups> (0 or 1)
     DOMNode *AccessControlGroups =
ConstraintTypes->getFirstChild()->getNextSibling();
     nodeName = AccessControlGroups->getNodeName();
     chNodeName = XMLString::transcode (nodeName);
     std::cout << " " << chNodeName << std::endl;
     delete [] chNodeName;

     // <AccessControlGroup> (0..*)
     for (AccessControlGroup = AccessControlGroups->getFirstChild();
          AccessControlGroup != 0;
          AccessControlGroup = AccessControlGroup->getNextSibling())
     {
        nodeName = AccessControlGroup->getNodeName();
        chNodeName = XMLString::transcode (nodeName);
        std::cout << "  " << chNodeName << std::endl;
        delete [] chNodeName;
     }


My XML file:
------------

<ConstraintTypes>
         <AccessControlGroups>
         </AccessControlGroups>

         <Type>
         </Type>
</ConstraintTypes>

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

Reply via email to