472,145 Members | 1,442 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,145 software developers and data experts.

xml schema validation

fayazmd
41
Hi,

I am validating xml file against a schema. I am able to get errors if the xml tag value data type is not same as of schema. But i am not getting any errors if the tag value is null. I want to get an error whenever tag value is null where in schema it is specified as some data type.

How to get error if the xml tag value is null by validating against schema?
Jan 17 '08 #1
8 4849
jkmyoung
2,057 Expert 2GB
Please post the relevant parts of your schema and xml file.
Jan 17 '08 #2
fayazmd
41
This is the Tag to which i have to validate. If the tag doesnt have any value in it, it should throw an error.
<SourceSystem></SourceSystem>

For that i have written schema as

<xs:element name="SourceSystem" type"xs:string" minOccurs="1" nillable="false" />

But my c# code is not throwing any error.

Please post the relevant parts of your schema and xml file.
Jan 18 '08 #3
jkmyoung
2,057 Expert 2GB
That particular tag is not null, it is the empty string; there is a subtle difference. I think you want instead:

Expand|Select|Wrap|Line Numbers
  1. <xs:element name="SourceSystem" minOccurs="1" nillable="false">
  2. <xs:simpleType>
  3.   <xs:restriction base="xs:string">
  4.     <xs:minLength value="1"/>
  5.   </xs:restriction>
  6. </xs:simpleType>
  7. </xs:element>
  8.  
--If it were null it would have an xsi:null attribute.
Jan 18 '08 #4
fayazmd
41
Yes I understood,

I want to impliment this code but i am getting error. The error message is

{"Expected Schema root. Make sure that the root element is <schema> and the namespace is 'http://www.w3.org/2001/XMLSchema' for an XSD schema or 'urn:schemas-microsoft-com:xml-data' for an XDR schema. An error occurred at , (2, 2)." }

my xsd first two lines are

<?xml version="1.0"?>
<xs:schema xmlns="http://www.w3.org/2001/XMLSchema">

I am giving same namespace even i am getting error.

That particular tag is not null, it is the empty string; there is a subtle difference. I think you want instead:

Expand|Select|Wrap|Line Numbers
  1. <xs:element name="SourceSystem" minOccurs="1" nillable="false">
  2. <xs:simpleType>
  3.   <xs:restriction base="xs:string">
  4.     <xs:minLength value="1"/>
  5.   </xs:restriction>
  6. </xs:simpleType>
  7. </xs:element>
  8.  
--If it were null it would have an xsi:null attribute.
Jan 21 '08 #5
jkmyoung
2,057 Expert 2GB
Small fix, note the :xs
Expand|Select|Wrap|Line Numbers
  1. <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  2.  
Jan 21 '08 #6
fayazmd
41
Thanks a lot!
It's working fine.
But, one request
It is throwing an error "The 'SourceSystem' element has an invalid value according to its data type."
Which i feel is improper for my application, since data is empty but it is throwing dataype error.

I should throw an error that the tag should not be empty or similar to this.

Small fix, note the :xs
Expand|Select|Wrap|Line Numbers
  1. <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  2.  
Jan 22 '08 #7
jkmyoung
2,057 Expert 2GB
That's really an issue for the data validator. The two possible solutions are: use a different validator. Write code changes to the validator.
Jan 22 '08 #8
fayazmd
41
Thank you once again.

i am doing empty validation in c#.

That's really an issue for the data validator. The two possible solutions are: use a different validator. Write code changes to the validator.
Jan 24 '08 #9

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Steve | last post: by
9 posts views Thread by brandon | last post: by
1 post views Thread by billa1972 | last post: by
reply views Thread by Saiars | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.