Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: How do I get the value out of an IXMLDOMNodePtr?

From: "Joe Fawcett" <joefawcett@---------.------>
To: NULL
Date: 11/2/2008 11:30:00 AM

"Christopher" <cpisz@a...> wrote in message 
news:59d371a1-dfcc-44a5-b1c4-ce0689c1934f@p......
> MSDN's examples only seem to show how to get the xml string out of a
> node.
> I don't want the xml string! That's why I'm using your XML library in
> the first place sillies!
>
> Anyway, I've been pooring over the documentation for hours and I can't
> seem to come up with a way to get my value out with anything but
> GetText, which seems to come back with all child node values as well.
> I just want the one single value, preferably as an unsigned int.
>
> xml:
> <economy>
>
> <good>
>   <name>Energy</name>
>   <value>12</value>
>   <tech>1</tech>
> </good>
>
> <good>
>   <name>Ice</name>
>   <value>24</value>
>   <tech>1</tech>
> </good>
>
> <good>
>   <name>Water</name>
>   <value>30</value>
>   <tech>1</tech>
> </good>
>
> </economy>
>
> code:
>
> // The list is loaded and valid. checked the names and the xml output
> already
> //
> void DataManager::ParseGoods(MSXML2::IXMLDOMNodeListPtr &
> goodXMLNodes)
> {
>   for(Good::ID id = 0; id < static_cast<unsigned>(goodXMLNodes-
>>Getlength()); ++id)
>   {
>      MSXML2::IXMLDOMNodePtr node = goodXMLNodes->nextNode();
>
>      Good good;
>      good.m_ID = id;
>
>      std::string nodeName = node->nodeName;
>      std::string nodeText = node->text;
>
>      for(node = node->GetfirstChild(); node != NULL; node = node-
>>GetnextSibling())
>      {
>         nodeName = node->nodeName;
>
>         if( nodeName == "name" || nodeName == "Name" )
>         {
>            good.m_name = node->text;
>         }
>
>         if( nodeName == "value" || nodeName == "Value" )
>         {
>            // This throws an exception. Nowhere on MSDN can I find
> what kind of exception or why it was thrown.
>            // I assume there is some conversion problem...
>            // How do I get my unsigned int out here?
>            good.m_baseValue = node->GetnodeValue().operator unsigned
> int();
>
>         }
>      }
>
>      // Check that all fields got filled out
>
>
>   }
> }
Elements don't have a value, they can have child text nodes which have a 
value though.
I don't really understand C++ but using DomDocument you can either get the 
element's firstChild, if that happens to be a text node and get its value of 
use the nodeTypedValue on the element.
Unless your elements have been validated against a schema the nodeTypedValue 
for an element will be a string so you'll have to convert that to an int 
yourself.

-- 

Joe Fawcett (MVP - XML)
http://joe.fawcett.name 



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent