Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - How do I get the value out of an IXMLDOMNodePtr? >Thread Next - Re: How do I get the value out of an IXMLDOMNodePtr? Re: How do I get the value out of an IXMLDOMNodePtr?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
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
