[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

problems getting the value of a float with XSD

  • To: xml-dev@l...
  • Subject: problems getting the value of a float with XSD
  • From: "Davinia Lopez" <davlobe@h...>
  • Date: Wed, 24 Mar 2004 11:54:31 +0000
  • Bcc:

get_nodevalue
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


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.