473,687 Members | 3,521 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

xml schema validation

fayazmd
41 New Member
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 4914
jkmyoung
2,057 Recognized Expert Top Contributor
Please post the relevant parts of your schema and xml file.
Jan 17 '08 #2
fayazmd
41 New Member
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="SourceSys tem" 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 Recognized Expert Top Contributor
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 New Member
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 Recognized Expert Top Contributor
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 New Member
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 Recognized Expert Top Contributor
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 New Member
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

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

Similar topics

2
1793
by: Steve | last post by:
Hi, I have xml data containing "line item" elements and a "footer" element which contains control totals for the line items. While I can easily validate the control totals in xslt, I have not been able to do it using a schema, which I need to do. Example: <data> <item><fld1>1</fld2><fld2>2</fld2></item>
9
4436
by: brandon | last post by:
I want to speed up the validation of some of my fairly large and detailed XML files. In particular there is a set of child elements and attributes that does not to be validated after it has completed a certain point in the system, but that will still be present in the file. At points later in the system, when these files are read in, I do not want to validate this section as it has already been validated much earlier, but still need the...
2
9451
by: Shone | last post by:
I would like to perform a 2-pass XML reading from a stream. Once using the Validating reader, just to confirm the validity against the schema, and next time to do a reading to extract the data. Actually, second time I do a deserialization, the data from XML is fed directly to an object. The problem I am experiencing is the error at the second reading attempt, and error description implies that reader is winded to the end of the XML and...
0
1132
by: Ricky Li | last post by:
I went through some article to see how I can add schema validation for my templated control by adding an XSD file into the VS.NET schema folder. Everything works fine for a schema like this: <mycontrolns:mycontrol id="test" runat="server"> <mytemplate>test</mytemplate> </mycontrolns> and I was able to specify the XSD to validate "mytemplate" as the only valid child type for "mycontrol". Here's a challenge: Is there anyway
1
6398
by: billa1972 | last post by:
Hi, I am trying to hook into Yellow Freight's rating webservice. Below is the wsdl. When i try and create a proxy file with wsdl.exe i get the following errors, see below. Also, when i reference this wsdl in .NET it seems to do it fine, yet there are no objects to reference except RateQuoteBeanService. In the WSDL it looks like there should be getRateQuote, and QUOTEREQUEST, etc.
0
2149
by: info | last post by:
Hi, Is it possible to include in the Schema validation file, every custom error message for each validation rules? This mean, in the same xsd file we can have the validation rules (patterns) and the custom error message throw during validation for the end user. I know .NET enable it using errorMessage tag, but with a standard W3C java validation ... If is it possible, does it works in IE too? Like that the same XSD file could be...
5
3681
by: wolf_y | last post by:
My question is simply: under what conditions will empty tags of the form <MOM></MOM> pass schema validation? Of course, the mirror question is: under what conditions will empty tags fail validation? The former seems to be an easier question to answer. XML files will arrive from around the world and must be schema validated before further processing and loading into a database, so I'm trying to foresee the various layouts that might be...
0
1417
by: merryla | last post by:
Hi, I tried to perform schema validation. The code works well. But when I tried with the Sample txlife.xsd file from http://acord.org/ I got error in associating the namespace with the xsd i.e. in the add () method. The add () method returned E_FALSE. When I referred the MSDN library, it states that "E_FAIL is returned if: · The collection is read-only · The document is not a recognized schema
2
3679
by: pnmcosta | last post by:
Hi, I'm fairly new to XML Schema validation. We have XML being imported that must validate against the following schema: <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.temp.com/ContactsImport" xmlns="http://www.temp.com/ContactsImport" elementFormDefault="qualified"> <xs:element name="Contacts"> <xs:complexType> <xs:sequence>
0
1699
by: kenkejas | last post by:
Hello public, Got a problem. While generating proxy classes getting warnings: Schema Validation Errors: Error compiling schema. WSDL descriptor is public: http://eptstest-integra.sodra.lt/orabpel/epts/surastiAsmenis/surastiAsmenis?wsdl Have tried with Altova XML spy and SoapUI 3.5. Descriptors load well except WseWsdl3.exe tool. Using such proxy class is ok until you get fault response, then everything is translated to "business...
0
8590
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9066
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8779
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8783
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6449
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5804
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4320
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4540
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2212
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.