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 "Andreas B. Thun" <ab...@gmx.net> on 2003/03/19 19:03:13 UTC
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: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
Re: parsing DOM tree: how can I access two different siblings?
Posted by Gareth Reakes <ga...@decisionsoft.com>.
Remember whitespace. From AccessControlGroups you will have to go
getNextSibling()->getNextSibling()->getNextSibling()
Gareth
> 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: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
>
>
--
Gareth Reakes, Head of Product Development +44-1865-203192
DecisionSoft Limited http://www.decisionsoft.com
XML Development and Services
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org