Groups | Blog | Home
all groups > dotnet xml > october 2005 >

dotnet xml : Decimal Type in a XSD Schema and problems with DataAdapter


Andres
10/4/2005 2:14:04 PM
Hi every body, I am having a problem and I need your help, please

I am using a XSD file; it has several nodes that have the following
definition:
<element name="guarantyPercent" type="decimal" />
As you can see, the type of guarantyPercent is decimal.

In the XML file the guarantyPercent can be empty:
< guarantyPercent />

(note: the XML File is not mine, this file comes from another company and is
sent to me every five minutes, and for this reason I cannot change the form
of this file is formed. But I can edit the XSD file)

When I tried to load the XML File into a dataset which has the corresponding
schema (XSD) assigned, an exception of “Invalid input string” is raise.

I investigated a lot, and I found that if the type of the element
guarantyPercent is String the problem don’t occurs, in another words: when
a XML element is in the form: <XXX/>, .net always load an empty string, and
for this reason failed when try to load into a decimal type. And .net doesn’t
indicate which XML element has the error.


My questions are the following:
- How can I manage the elements of this type: <xxxx/> with a decimal type.
(I tried with nillable, minOccurs attributes but nothing good happens, the
exception always raise)
- I am reading that .net classes that manage XML files don’t indicate which
XML element has the error, only report an error in general. How can I
validate de XML (without parsing manually) and I case of error indicate the
specific element that has the error.

Thanks so much…
Priya Lakshminarayanan [MSFT]
10/4/2005 4:52:36 PM
For empty elements that are not of type xs:string or derived from it, you
need to use xsi:nil in the instance (along with nillable="true" specified
for the element in the schema) if you want the empty elements to valdiate
against the schema.

In the schema:
<element name="guarantyPercent" type="decimal" nillable="true"/>

in the instance:
< guarantyPercent xsi:nil="true"/>

If you are using .NET 1.1 and the XmlValidatingReader to validate the xml
against the schema, the XmlSchemaException raised during validation should
have the LineNumber and LinePosition of the error.

Thanks,
Priya

[quoted text, click to view]

AddThis Social Bookmark Button