OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help



   problems getting the value of a float with XSD

[ Lists Home | Date Index | Thread Index ]

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.


These are the files I'm using:

<?xml version="1.0"?>
<Library xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
	<Book price = "20.5"></Book>

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";>
    <xsd:element name="Library">
          <xsd:element name="Book" maxOccurs="unbounded">
		<xsd:attribute name="price" type="xsd:float" use="required"/>

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


   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", 
      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);


   return NULL;

¿Todavía no conoces el nuevo MSN Messenger? Descárgatelo gratis aquí. 


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS