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 14:02:08 UTC

need help for parsing DOM tree to get element values

Hi,

After evaluation I parse the XML file to get the values
of all <AccessControlGroup> elements.
Unfortunately after AccessControlGroup->getTextContent()
the program stops (does not crash).
The node AccessControlGroup is ok I think but I just cannot get the
values... What's is my problem?


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;

        // Can't get the value here!?
        cout << "value: '" << XMLString::transcode(AccessControlGroup->getTextContent()) << "'" << endl;
     }


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

<ConstraintTypes>
         <AccessControlGroups>
                 <AccessControlGroup>Designer</AccessControlGroup>
                 <AccessControlGroup>Admin</AccessControlGroup>
         </AccessControlGroups>
         <Type>
                 <Name>SYM</Name>
                 <Description>Axis sym</Description>
                 <ElementType type="instance"/>
                 <ElementLength min="2" max="2"/>
         </Type>
</ConstraintTypes>


Program output:
---------------
ConstraintTypes
  AccessControlGroups
   #text
value: '


Program output without line
XMLString::transcode(AccessControlGroup->getTextContent()) << "'" << endl;
--------------------------------------------------------------------------
ConstraintTypes
  AccessControlGroups
   #text
   AccessControlGroup
   #text
   AccessControlGroup
   #text
   AccessControlGroup
   #text

-> looks ok


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: need help for parsing DOM tree to get element values

Posted by Gareth Reakes <ga...@decisionsoft.com>.
Hi,
	name would be the normal way of doing it.

Gareth


On Wed, 19 Mar 2003, Andreas B. Thun wrote:

> Another (newbie) question:
> 
> How can I destinguish between <AccessControlGroups>
> and <Type>? They are both childs of <ConstraintTypes>.
> only by name?
> 
> My XML file:
> ------------
> 
> <ConstraintTypes>
>          <AccessControlGroups>
>                  <AccessControlGroup>Designer</AccessControlGroup>
>                  <AccessControlGroup>Admin</AccessControlGroup>
>          </AccessControlGroups>
>          <Type>
>                  <Name>SYM</Name>
>                  <Description>Axis sym</Description>
>                  <ElementType type="instance"/>
>                  <ElementLength min="2" max="2"/>
>          </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


Re: need help for parsing DOM tree to get element values

Posted by "Andreas B. Thun" <ab...@gmx.net>.
Another (newbie) question:

How can I destinguish between <AccessControlGroups>
and <Type>? They are both childs of <ConstraintTypes>.
only by name?

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

<ConstraintTypes>
         <AccessControlGroups>
                 <AccessControlGroup>Designer</AccessControlGroup>
                 <AccessControlGroup>Admin</AccessControlGroup>
         </AccessControlGroups>
         <Type>
                 <Name>SYM</Name>
                 <Description>Axis sym</Description>
                 <ElementType type="instance"/>
                 <ElementLength min="2" max="2"/>
         </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: need help for parsing DOM tree to get element values

Posted by Gareth Reakes <ga...@decisionsoft.com>.
Hi,

> 
> Hmm,
> if (AccessControlGroup->getNodeType() == DOMNode::ELEMENT_NODE)
> {
>    ...
> }
> 

yep


Gareth


-- 
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


Re: need help for parsing DOM tree to get element values

Posted by "Andreas B. Thun" <ab...@gmx.net>.
> Hi,
> 	I dont have your XML any more but I would suspect that you are 
> trying to getFirstChild on a node that does not have a first child (ie a 
> text node).

Hi,

Hmm,
if (AccessControlGroup->getNodeType() == DOMNode::ELEMENT_NODE)
{
   ...
}

should help?!



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: need help for parsing DOM tree to get element values

Posted by Gareth Reakes <ga...@decisionsoft.com>.
Hi,
	I dont have your XML any more but I would suspect that you are 
trying to getFirstChild on a node that does not have a first child (ie a 
text node).


Gareth



On Wed, 19 Mar 2003, Andreas B. Thun wrote:

> Thx Gareth,
> 
> tried, but it still does not work for me:
> 
> 
>      // <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;
> 
> 
>         // does not work
>         nodeValue = AccessControlGroup->getNodeValue();
> 
>         // core dump
>         // nodeValue = AccessControlGroup->getFirstChild()->getNodeValue();
> 
> 
>         chNodeValue = XMLString::transcode (nodeValue);
>         std::cout << "  val: " << chNodeValue << std::endl;
>         delete [] chNodeValue;
> 
>      }
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> 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


Re: need help for parsing DOM tree to get element values

Posted by "Andreas B. Thun" <ab...@gmx.net>.
Thx Gareth,

tried, but it still does not work for me:


     // <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;


        // does not work
        nodeValue = AccessControlGroup->getNodeValue();

        // core dump
        // nodeValue = AccessControlGroup->getFirstChild()->getNodeValue();


        chNodeValue = XMLString::transcode (nodeValue);
        std::cout << "  val: " << chNodeValue << std::endl;
        delete [] chNodeValue;

     }





---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: need help for parsing DOM tree to get element values

Posted by Gareth Reakes <ga...@decisionsoft.com>.
Hi,
	getTextContent is not yet implemented. Try something like 
getFirstChild() on node.

Gareth	


On Wed, 19 Mar 2003, Andreas B. Thun wrote:

> Hi,
> 
> After evaluation I parse the XML file to get the values
> of all <AccessControlGroup> elements.
> Unfortunately after AccessControlGroup->getTextContent()
> the program stops (does not crash).
> The node AccessControlGroup is ok I think but I just cannot get the
> values... What's is my problem?
> 
> 
> 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;
> 
>         // Can't get the value here!?
>         cout << "value: '" << XMLString::transcode(AccessControlGroup->getTextContent()) << "'" << endl;
>      }
> 
> 
> My XML file:
> ------------
> 
> <ConstraintTypes>
>          <AccessControlGroups>
>                  <AccessControlGroup>Designer</AccessControlGroup>
>                  <AccessControlGroup>Admin</AccessControlGroup>
>          </AccessControlGroups>
>          <Type>
>                  <Name>SYM</Name>
>                  <Description>Axis sym</Description>
>                  <ElementType type="instance"/>
>                  <ElementLength min="2" max="2"/>
>          </Type>
> </ConstraintTypes>
> 
> 
> Program output:
> ---------------
> ConstraintTypes
>   AccessControlGroups
>    #text
> value: '
> 
> 
> Program output without line
> XMLString::transcode(AccessControlGroup->getTextContent()) << "'" << endl;
> --------------------------------------------------------------------------
> ConstraintTypes
>   AccessControlGroups
>    #text
>    AccessControlGroup
>    #text
>    AccessControlGroup
>    #text
>    AccessControlGroup
>    #text
> 
> -> looks ok
> 
> 
> ---------------------------------------------------------------------
> 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