You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by Dhirendra Pal Singh <dp...@gmail.com> on 2005/08/12 05:40:03 UTC
Help needed in getting the value of a node
Hi All,
I have the following xml...
<my-values name "value 1">
<value>http://127.0.0.1:9955</value>
</my-values>
Now I can read all the attributes of my-values using getAttributes().
Then I can get a DOMElement to value too. But I am unable to get the
value of value which should be "http://127.0.0.1:9955" I have trying
to do it for last 4 hrs, and is unable to do it. Anyhelp would be
greately appreiciated.
I also tryied the following..=
XERCES_CPP_NAMESPACE_QUALIFIER DOMElement* elm1 = (element pointing to va=
lue)
XERCES_CPP_NAMESPACE_QUALIFIER DOMAttr *valueAttr =
elm1->getAttributeNode(XERCES_CPP_NAMESPACE_QUALIFIER
XMLString::transcode("value"));
But valueAttr is always null... Any reason why?
Thanks a ton in advance...
--
Thanks
/dev/dp
Re: Help needed in getting the value of a node
Posted by Dhirendra Pal Singh <dp...@gmail.com>.
Alberto,
Thanks for clearing the concept, and the 2 lines. I can now a breath of
relief... phew.. :)
Thanks once again.
Dp
Alberto Massari wrote:
> At 20.40 11/08/2005 -0700, Dhirendra Pal Singh wrote:
>
>> Hi All,
>>
>> I have the following xml...
>>
>> <my-values name "value 1">
>> <value>http://127.0.0.1:9955</value>
>> </my-values>
>>
>> Now I can read all the attributes of my-values using getAttributes().
>> Then I can get a DOMElement to value too. But I am unable to get the
>> value of value which should be "http://127.0.0.1:9955" I have trying
>> to do it for last 4 hrs, and is unable to do it. Anyhelp would be
>> greately appreiciated.
>>
>> I also tryied the following..=
>>
>> XERCES_CPP_NAMESPACE_QUALIFIER DOMElement* elm1 = (element pointing
>> to va=
>> lue)
>>
>> XERCES_CPP_NAMESPACE_QUALIFIER DOMAttr *valueAttr =
>> elm1->getAttributeNode(XERCES_CPP_NAMESPACE_QUALIFIER
>> XMLString::transcode("value"));
>>
>> But valueAttr is always null... Any reason why?
>
>
> Because there is no "value" attribute on the "value" element... You
> need to retrieve the first child of the element (it's a TEXT_NODE) and
> get its value.
>
> DOMNode* child=elm1->getFirstChild();
> if(child)
> XMLCh* value=child->getNodeValue();
>
> As an alternative, use
>
> elm1->getTextContent()
>
> but this API has implications (memory usage grows, and when used on
> complex elements it returns a string that maybe it's different from
> what you would expect)
>
> Alberto
>
>
>> Thanks a ton in advance...
>> --
>> Thanks
>> /dev/dp
>
>
>
>
Re: Help needed in getting the value of a node
Posted by Alberto Massari <am...@datadirect.com>.
At 20.40 11/08/2005 -0700, Dhirendra Pal Singh wrote:
>Hi All,
>
>I have the following xml...
>
><my-values name "value 1">
> <value>http://127.0.0.1:9955</value>
></my-values>
>
>Now I can read all the attributes of my-values using getAttributes().
>Then I can get a DOMElement to value too. But I am unable to get the
>value of value which should be "http://127.0.0.1:9955" I have trying
>to do it for last 4 hrs, and is unable to do it. Anyhelp would be
>greately appreiciated.
>
>I also tryied the following..=
>
>XERCES_CPP_NAMESPACE_QUALIFIER DOMElement* elm1 = (element pointing to va=
>lue)
>
>XERCES_CPP_NAMESPACE_QUALIFIER DOMAttr *valueAttr =
>elm1->getAttributeNode(XERCES_CPP_NAMESPACE_QUALIFIER
>XMLString::transcode("value"));
>
>But valueAttr is always null... Any reason why?
Because there is no "value" attribute on the "value" element... You
need to retrieve the first child of the element (it's a TEXT_NODE)
and get its value.
DOMNode* child=elm1->getFirstChild();
if(child)
XMLCh* value=child->getNodeValue();
As an alternative, use
elm1->getTextContent()
but this API has implications (memory usage grows, and when used on
complex elements it returns a string that maybe it's different from
what you would expect)
Alberto
>Thanks a ton in advance...
>--
>Thanks
>/dev/dp