[
Lists Home |
Date Index |
Thread Index
]
Hi,
I'd like to get the value of a float from a XML file, but when I get the
value with:
hr = pNodeAttrPrice->get_nodeValue(&value);
it's stored as a string and not as a float.
if(value.vt == VT_BSTR) //shows the value as a string
printf("is a string %s\n", value.bstrVal);
printf("valor: %f\n", value.fltVal); //shows 0.000
What I am doing wrong?
Thanks in advance.
Davinia.
These are the files I'm using:
/**********myfile.xml****************/
<?xml version="1.0"?>
<Library xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="myfile.xsd">
<Book price = "20.5"></Book>
</Library>
/******myfile.xsd**********/
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="Library">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Book" maxOccurs="unbounded">
<xsd:complexType>
<xsd:attribute name="price" type="xsd:float" use="required"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
//File .cpp I'm using MSXML 4.0 in VisualC++
int main()
{
IXMLDOMDocument2Ptr pXMLDom;
IXMLDOMNodeListPtr pNodeChildrenLibrary = NULL;
IXMLDOMNodePtr pNodeBook = NULL;
IXMLDOMNamedNodeMapPtr pAttrListBook = NULL;
IXMLDOMNodePtr pNodeAttrPrice = NULL;
HRESULT hr;
CoInitialize(NULL);
hr = pXMLDom.CreateInstance(__uuidof(DOMDocument40));
if (FAILED(hr))
{
printf("Failed to instantiate DOMDocument40 class\n");
return NULL;
}
pXMLDom->async = VARIANT_FALSE;
pXMLDom->validateOnParse = VARIANT_TRUE;
pXMLDom->resolveExternals = VARIANT_TRUE;
if ( pXMLDom->load("myfile.xml") != VARIANT_TRUE)
{
printf("Failed load xml data from file.\n%s\n",
(LPCSTR)pXMLDom->parseError->Getreason());
return NULL;
}
pNodeChildrenLibrary = pXMLDom->selectNodes("//Library[1]/*");
printf("Lenght: %d\n",pNodeChildrenLibrary->length);
pNodeBook = pNodeChildrenLibrary->item[0];
pAttrListBook = pNodeBook->attributes;
pNodeAttrPrice = pAttrListBook->item[0];
MessageBox(NULL, (LPCSTR)pNodeAttrPrice->text, "Price:", MB_OK);
VARIANT value;
hr = pNodeAttrPrice->get_nodeValue(&value);
if(value.vt == VT_BSTR)
printf("is a string %s\n", value.bstrVal);
printf("valor: %f\n", value.fltVal);
pNodeChildrenLibrary.Release();
pNodeBook.Release();
pAttrListBook.Release();
pNodeAttrPrice.Release();
CoUninitialize();
return NULL;
}
_________________________________________________________________
¿Todavía no conoces el nuevo MSN Messenger? Descárgatelo gratis aquí.
http://messenger.microsoft.com/es
|