I'm using a 2.0 XmlReaderSettings object with setting.ValidationType set
to ValdationType.Schema to validate a document against a schema.
Following is a schema fragment (names altered):
<xsd:element name="Stuff">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="RequiredSimpleThing1"/>
<xsd:element ref="RequiredSimpleThing2"/>
<xsd:element name="OptionalSimpleThing1" type="OptionalType"
minOccurs="0"/>
<xsd:element name="OptionalSimpleThing2" type="OptionalType"
minOccurs="0"/>
<xsd:element name="ComplexThing" minOccurs="0">
<xsd:complexType>
<xsd:sequence maxOccurs="unbounded">
<xsd:element name="ChildThing" type="ChildType"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
Following is a document fragment:
<Stuff>
<RequiredSimpleThing1>86876</RequiredSimpleThing1>
<RequiredSimpleThing2>MC</RequiredSimpleThing2>
<ComplexThing>
<!-- several ChildThing elements -->
</ComplexThing>
</Stuff>
The error I recieve from the validator is "The element 'Stuff' has
invalid child element 'ComplexThing'. List of possible elements
expected: 'OptionalSimpleThing1, OptionalSimpleThing2'."
Why is the validator requiring these optional (minOccurs = 0) elements? 16 5991
"Brad Wood" <bradley|.wood|@ndsu|.edu> wrote in message
news:uz**************@TK2MSFTNGP09.phx.gbl... I'm using a 2.0 XmlReaderSettings object with setting.ValidationType set to ValdationType.Schema to validate a document against a schema.
Following is a schema fragment (names altered): <xsd:element name="Stuff"> <xsd:complexType> <xsd:sequence> <xsd:element ref="RequiredSimpleThing1"/> <xsd:element ref="RequiredSimpleThing2"/> <xsd:element name="OptionalSimpleThing1" type="OptionalType" minOccurs="0"/> <xsd:element name="OptionalSimpleThing2" type="OptionalType" minOccurs="0"/> <xsd:element name="ComplexThing" minOccurs="0"> <xsd:complexType> <xsd:sequence maxOccurs="unbounded"> <xsd:element name="ChildThing" type="ChildType"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element>
Following is a document fragment: <Stuff> <RequiredSimpleThing1>86876</RequiredSimpleThing1> <RequiredSimpleThing2>MC</RequiredSimpleThing2> <ComplexThing> <!-- several ChildThing elements --> </ComplexThing> </Stuff>
The error I recieve from the validator is "The element 'Stuff' has invalid child element 'ComplexThing'. List of possible elements expected: 'OptionalSimpleThing1, OptionalSimpleThing2'."
Why is the validator requiring these optional (minOccurs = 0) elements?
Looks OK to me. Perhaps you have oversimplified in your post.
Post some real files (cut down and names changed if necessary) that produce
the error.
I am new to XSD, but here I go anyway, speaking up and showing myself to be
a fool :-)
01) I use xs:all rather than xs:sequence if the order of the elements is not
important. (Not really relevant)
02) You have "xsd:" everywhere, a newsgroup typo?
03) "xs:sequence maxOccurs", shouldn't the maxOccures not be in xs;sequence
but in the xs:element beneath it?
Pete
"Peter Morris [Droopy eyes software]" <pete@droopyeyes[dot]comREMOVETHIS>
wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl... I am new to XSD, but here I go anyway, speaking up and showing myself to be a fool :-)
01) I use xs:all rather than xs:sequence if the order of the elements is not important. (Not really relevant)
There are good reasons not to use "all".
Yes - in abstract modelling terms it is correct but in practice it is never
a good idea.
Hi Nick There are good reasons not to use "all".
Yes - in abstract modelling terms it is correct but in practice it is never a good idea.
I'd be interested in hearing them, as I am using xs:all quite a lot at the
moment.
Pete
Peter Morris [Droopy eyes software] wrote: 01) I use xs:all rather than xs:sequence if the order of the elements is not important. (Not really relevant) 02) You have "xsd:" everywhere, a newsgroup typo? 03) "xs:sequence maxOccurs", shouldn't the maxOccures not be in xs;sequence but in the xs:element beneath it?
The xsd is generated by Altova's XMLSpy.
"Peter Morris [Droopy eyes software]" <pete@droopyeyes[dot]comREMOVETHIS>
wrote in message news:u$*************@tk2msftngp13.phx.gbl... Hi Nick
There are good reasons not to use "all".
Yes - in abstract modelling terms it is correct but in practice it is never a good idea.
I'd be interested in hearing them, as I am using xs:all quite a lot at the moment.
Get "XML Schema" by Eric Van Der Vlist published by O'Reilly.
I quote briefly:
"unordered content models not only increase the risk of non-deterministic
content models but are also an important complexity factor for schema
processors. For the sake of implementation simplicity the recommendation has
imposed huge limitations on the xs:all element which makes it hardly usable
in practice."
In particular xs:all
1) cannot be used as a particle
2) cannot have a number of occurences > 1
3) the particles included within xs:all must be xs:element and must not
specify maxOccurences > 1
In simple schemas you will be OK but once you get into groups, choices,
extension and restriction you will wish that you hadn't used them.
The book explains the limitations in detail but it is easier to just
remember not to use it.
Hi Brad,
LicensingStatus and InsuranceStatus are required (you don't have
minOccurs="0" on them), and they are missing.
Hope that helps,
Priscilla
------------------------------------------------------------------
Priscilla Walmsley
Author, Definitive XML Schema / XML in Office 2003 http://www.datypic.com
------------------------------------------------------------------
"Brad Wood" <bradley|.wood|@ndsu|.edu> wrote in message
news:uJ*************@tk2msftngp13.phx.gbl... Nick Hounsome wrote: Looks OK to me. Perhaps you have oversimplified in your post. Post some real files (cut down and names changed if necessary) that produce the error.
The schema will be public in a day or 2, so I attached it. The basic validation code I'm using can be found a couple posts prior in this group with subject "validating XML with XmlValidatingReader" (my response to question).
Here is the doc I'm validating: <?xml version="1.0" encoding="utf-16"?> <LicensingInsurance> <CompanyUSDOTNum>123</CompanyUSDOTNum> <CompanyDocketPrefixCode>MC</CompanyDocketPrefixCode> <CompanyDocketNum>123</CompanyDocketNum> <CompanyLegalName>Company A</CompanyLegalName> <CompanyDBAName>Company A</CompanyDBAName> <InsurancePolicies> <InsurancePolicy> <InsuranceTypeCode>1</InsuranceTypeCode> <InsurerName>INSURANCE COMPANY</InsurerName> <PolicyNumber>123</PolicyNumber> <PolicyEffectiveDate>2004-10-03</PolicyEffectiveDate> <PolicyCoverageLowAmount>0</PolicyCoverageLowAmount> <PolicyCoverageHighAmount>5000000</PolicyCoverageHighAmount> </InsurancePolicy> </InsurancePolicies> </LicensingInsurance>
Or buy my book, Definitive XML Schema. It's on page 289. :-)
I too avoid xs:all, for the reasons described below.
------------------------------------------------------------------
Priscilla Walmsley
Author, Definitive XML Schema / XML in Office 2003 http://www.datypic.com
------------------------------------------------------------------
"Nick Hounsome" <nh***@nickhounsome.me.uk> wrote in message
news:Tb*****************@fe2.news.blueyonder.co.uk ... "Peter Morris [Droopy eyes software]" <pete@droopyeyes[dot]comREMOVETHIS> wrote in message news:u$*************@tk2msftngp13.phx.gbl... Hi Nick
There are good reasons not to use "all".
Yes - in abstract modelling terms it is correct but in practice it is never a good idea.
I'd be interested in hearing them, as I am using xs:all quite a lot at the moment.
Get "XML Schema" by Eric Van Der Vlist published by O'Reilly.
I quote briefly:
"unordered content models not only increase the risk of non-deterministic content models but are also an important complexity factor for schema processors. For the sake of implementation simplicity the recommendation has imposed huge limitations on the xs:all element which makes it hardly usable in practice."
In particular xs:all
1) cannot be used as a particle 2) cannot have a number of occurences > 1 3) the particles included within xs:all must be xs:element and must not specify maxOccurences > 1
In simple schemas you will be OK but once you get into groups, choices, extension and restriction you will wish that you hadn't used them.
The book explains the limitations in detail but it is easier to just remember not to use it.
Hi Peter,
There's nothing wrong with using the xsd: prefix instead of xs:, as long as
you declare it. Prefixes are technically irrelevant. You could use "bob:"
if you wanted.
About maxOccurs, it can occur on the xs:sequence. In this case, since there
is one element child, it doesn't make a difference whether you put it on the
xs:sequence or on the xs:element. If there were multiple element
declarations in the sequence group, you could use maxOccurs on the sequence
to allow the entire sequence of elements to appear multiple times.
Hope that helps,
Priscilla
------------------------------------------------------------------
Priscilla Walmsley
Author, Definitive XML Schema / XML in Office 2003 http://www.datypic.com
------------------------------------------------------------------
"Peter Morris [Droopy eyes software]" <pete@droopyeyes[dot]comREMOVETHIS>
wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl... I am new to XSD, but here I go anyway, speaking up and showing myself to be a fool :-)
01) I use xs:all rather than xs:sequence if the order of the elements is not important. (Not really relevant) 02) You have "xsd:" everywhere, a newsgroup typo? 03) "xs:sequence maxOccurs", shouldn't the maxOccures not be in xs;sequence but in the xs:element beneath it?
Pete
Priscilla Walmsley wrote: Hi Brad,
LicensingStatus and InsuranceStatus are required (you don't have minOccurs="0" on them), and they are missing.
OK, this is what threw me for a loop: the error I get is, "The element
'LicensingInsurance' has invalid child element 'InsurancePolicies'. List
of possible elements expected: 'CarrierClassPropertyFlag,
CarrierClassPassengerFlag, CarrierClassHouseholdFlag,
CarrierBOC3FormFlag, CompanyAddress, CompanyContact, LicensingStatus'."
So the list of expected elements includes all of the optional elements
and only one out of two of the required elements. I was being dumb and
didn't even notice the required element in the list - only all the
optional ones. It is kind of strange that one of the required elements
is missing from the list in the error message.
Now when I try to validate, I get the error, "The 'PolicyEffectiveDate'
element is invalid - The value '2003-10-4' is invalid according to its
datatype 'http://www.w3.org/2001/XMLSchema:date' - The string
'2003-10-4' is not a valid XsdDateTime value."
Judging from the spec, '2003-10-4' is a valid date. The data type for
the element is date (not DateTime), but the end of the error message
refers to XsdDateTime??
Hi Brad,
I think the reason it didn't list the required InsuranceStatus element is
that it couldn't possibly appear there (where InsurancePolicies erroneously
appears) - LicensingStatus would have to appear first. So, it was telling
you what the valid elements after CompanyDBAName.
Hope that helps,
Priscilla
------------------------------------------------------------------
Priscilla Walmsley
Author, Definitive XML Schema / XML in Office 2003 http://www.datypic.com
------------------------------------------------------------------
"Brad Wood" <bradley|.wood|@ndsu|.edu> wrote in message
news:Om**************@TK2MSFTNGP09.phx.gbl... Priscilla Walmsley wrote: Hi Brad,
LicensingStatus and InsuranceStatus are required (you don't have minOccurs="0" on them), and they are missing.
OK, this is what threw me for a loop: the error I get is, "The element 'LicensingInsurance' has invalid child element 'InsurancePolicies'. List of possible elements expected: 'CarrierClassPropertyFlag, CarrierClassPassengerFlag, CarrierClassHouseholdFlag, CarrierBOC3FormFlag, CompanyAddress, CompanyContact, LicensingStatus'."
So the list of expected elements includes all of the optional elements and only one out of two of the required elements. I was being dumb and didn't even notice the required element in the list - only all the optional ones. It is kind of strange that one of the required elements is missing from the list in the error message.
Hi Again,
The day has to be two digits long, so it should be 2003-10-04. I'm not
sure why it says XsdDateTime.
Hope that helps,
Priscilla
------------------------------------------------------------------
Priscilla Walmsley
Author, Definitive XML Schema / XML in Office 2003 http://www.datypic.com
------------------------------------------------------------------
"Brad Wood" <bradley|.wood|@ndsu|.edu> wrote in message
news:%2****************@tk2msftngp13.phx.gbl... Now when I try to validate, I get the error, "The 'PolicyEffectiveDate' element is invalid - The value '2003-10-4' is invalid according to its datatype 'http://www.w3.org/2001/XMLSchema:date' - The string '2003-10-4' is not a valid XsdDateTime value."
Judging from the spec, '2003-10-4' is a valid date. The data type for the element is date (not DateTime), but the end of the error message refers to XsdDateTime??
If you are going to plug your book then do it properly :-)
See: http://www.amazon.com/gp/product/013...books&n=283155
Looks OK.
As far as I can tell most books are fairly similar.
It was the practical advice and guidlines that I was most looking for when I
was looking for a book (sorry - didn't see yours at the time) such as
avoiding xs:all and the advantages of groups over extensions.
What is probably considered out of scope but which would be very useful is a
description of the mapping of schemas to classes by xsd.exe. This is
woefully underdocumented anywhere that I know of yet is of great interest to
the .NET community.
"Priscilla Walmsley" <no****@datypic.com> wrote in message
news:eb*************@tk2msftngp13.phx.gbl... Or buy my book, Definitive XML Schema. It's on page 289. :-)
I too avoid xs:all, for the reasons described below.
------------------------------------------------------------------ Priscilla Walmsley Author, Definitive XML Schema / XML in Office 2003 http://www.datypic.com ------------------------------------------------------------------
"Nick Hounsome" <nh***@nickhounsome.me.uk> wrote in message news:Tb*****************@fe2.news.blueyonder.co.uk ... "Peter Morris [Droopy eyes software]" <pete@droopyeyes[dot]comREMOVETHIS> wrote in message news:u$*************@tk2msftngp13.phx.gbl... Hi Nick
There are good reasons not to use "all".
Yes - in abstract modelling terms it is correct but in practice it is never a good idea.
I'd be interested in hearing them, as I am using xs:all quite a lot at the moment.
Get "XML Schema" by Eric Van Der Vlist published by O'Reilly.
I quote briefly:
"unordered content models not only increase the risk of non-deterministic content models but are also an important complexity factor for schema processors. For the sake of implementation simplicity the recommendation has imposed huge limitations on the xs:all element which makes it hardly usable in practice."
In particular xs:all
1) cannot be used as a particle 2) cannot have a number of occurences > 1 3) the particles included within xs:all must be xs:element and must not specify maxOccurences > 1
In simple schemas you will be OK but once you get into groups, choices, extension and restriction you will wish that you hadn't used them.
The book explains the limitations in detail but it is easier to just remember not to use it.
> As far as I can tell most books are fairly similar.
Some books are more equal than others
I think (personal opinion) that Priscilla's book is by far the best book on
XML Schema. It is written in a language that is easy to understand, has
good examples and best practice advise, and is great for reference. I have
gone through a number of schema books and don't think anybody else comes
close to this one. If you want to learn XML Schema and for some reason
don't want to read the spec (which I don't blame you if you don't), read
this book.
--
Stan Kitsis
Program Manager, XML Technologies
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.
"Nick Hounsome" <nh***@nickhounsome.me.uk> wrote in message
news:HU*************@fe1.news.blueyonder.co.uk... If you are going to plug your book then do it properly :-)
See: http://www.amazon.com/gp/product/013...books&n=283155
Looks OK.
As far as I can tell most books are fairly similar.
It was the practical advice and guidlines that I was most looking for when I was looking for a book (sorry - didn't see yours at the time) such as avoiding xs:all and the advantages of groups over extensions.
What is probably considered out of scope but which would be very useful is a description of the mapping of schemas to classes by xsd.exe. This is woefully underdocumented anywhere that I know of yet is of great interest to the .NET community.
"Priscilla Walmsley" <no****@datypic.com> wrote in message news:eb*************@tk2msftngp13.phx.gbl... Or buy my book, Definitive XML Schema. It's on page 289. :-)
I too avoid xs:all, for the reasons described below.
------------------------------------------------------------------ Priscilla Walmsley Author, Definitive XML Schema / XML in Office 2003 http://www.datypic.com ------------------------------------------------------------------
"Nick Hounsome" <nh***@nickhounsome.me.uk> wrote in message news:Tb*****************@fe2.news.blueyonder.co.uk ... "Peter Morris [Droopy eyes software]" <pete@droopyeyes[dot]comREMOVETHIS> wrote in message news:u$*************@tk2msftngp13.phx.gbl... Hi Nick
> There are good reasons not to use "all". > > Yes - in abstract modelling terms it is correct but in practice it is > never a good idea.
I'd be interested in hearing them, as I am using xs:all quite a lot at the moment.
Get "XML Schema" by Eric Van Der Vlist published by O'Reilly.
I quote briefly:
"unordered content models not only increase the risk of non-deterministic content models but are also an important complexity factor for schema processors. For the sake of implementation simplicity the recommendation has imposed huge limitations on the xs:all element which makes it hardly usable in practice."
In particular xs:all
1) cannot be used as a particle 2) cannot have a number of occurences > 1 3) the particles included within xs:all must be xs:element and must not specify maxOccurences > 1
In simple schemas you will be OK but once you get into groups, choices, extension and restriction you will wish that you hadn't used them.
The book explains the limitations in detail but it is easier to just remember not to use it.
Pardon me for jumping in so late...
I understand the reasons for not using xs:all, but I am using it. For one
reason, my XML is generated automatically from my C# classes by using the
XMLSerializer. I couldn't figure out how to control the order of the elements
when serializing the classes, which caused validation errors.
"Priscilla Walmsley" wrote: Or buy my book, Definitive XML Schema. It's on page 289. :-)
I too avoid xs:all, for the reasons described below.
------------------------------------------------------------------ Priscilla Walmsley Author, Definitive XML Schema / XML in Office 2003 http://www.datypic.com ------------------------------------------------------------------
"Nick Hounsome" <nh***@nickhounsome.me.uk> wrote in message news:Tb*****************@fe2.news.blueyonder.co.uk ... "Peter Morris [Droopy eyes software]" <pete@droopyeyes[dot]comREMOVETHIS> wrote in message news:u$*************@tk2msftngp13.phx.gbl... Hi Nick
There are good reasons not to use "all".
Yes - in abstract modelling terms it is correct but in practice it is never a good idea.
I'd be interested in hearing them, as I am using xs:all quite a lot at the moment.
Get "XML Schema" by Eric Van Der Vlist published by O'Reilly.
I quote briefly:
"unordered content models not only increase the risk of non-deterministic content models but are also an important complexity factor for schema processors. For the sake of implementation simplicity the recommendation has imposed huge limitations on the xs:all element which makes it hardly usable in practice."
In particular xs:all
1) cannot be used as a particle 2) cannot have a number of occurences > 1 3) the particles included within xs:all must be xs:element and must not specify maxOccurences > 1
In simple schemas you will be OK but once you get into groups, choices, extension and restriction you will wish that you hadn't used them.
The book explains the limitations in detail but it is easier to just remember not to use it.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Olaf Meyer |
last post by:
Apprentently xerces 2.6.0 (Java) does not validate against contraints
specified in the schema (e.g. constraints specified via unique element).
The validation works with the XML editor I'm using (XMLSpy4) but not
with Xerces 2.6.0.
I've included a really short and simple example to illustrate it. I
would like to get some comments on the...
|
by: Oskar Stuffer |
last post by:
Hi!
I'm using the msv tool which uses xerces to validate a XML document against a
XML Schema
definition.
This is my XML Schema definition:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
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...
|
by: Dan Bass |
last post by:
There's an XML message I have, that has no namespace information.
Then there is a XSD schema that is must validate against, but this has a
targetNamespace and xmlns of "http://www.wbf.org/xml/b2mml-v02".
How do I get this XML to validate against the Schema in C#?
If I use XmlSpy (2005 home edition) to perform the validation, it first...
|
by: Willi |
last post by:
Hallo,
i have to validate many XML's Documents with a XSD. Some XML's throw a Validationerror like "The 'type' attribute has an invalid value according to its data type".
To produce automatically a valid XML i would need the corresponding Schemaelement, to get the Defaultvalue for that Attribute.
Can anybody help me?
From...
| |
by: Doru Roman |
last post by:
Hi,
I am a beginner and I try to understand how can I use C# and Netframework to
validate an XML document. Is XSD a solution? How?
Thanks,
Doru
|
by: Jonny |
last post by:
Hi,
I'm trying to validate my xml against a xsd but I can't get it to work.
Originally, I wanted to validate an xml string but since I didn't get that
to work I tried to validate an xml file instead. Didn't work either.
Actuallty, the xml gets loaded but there are no events raised that says my
xml is incorrect!
I'm using .NET 2.0 and my...
|
by: Nadeeka |
last post by:
Hi, I wrote a Schema Validator in C#.NET.
XmlTextReader R = new XmlTextReader(FileToParse);
XmlValidatingReader V = new XmlValidatingReader(R);
try
{
XmlSchemaCollection xsc = new XmlSchemaCollection();
xsc.Add("", SchemaFile);
...
|
by: jh3an |
last post by:
Please give me your advice!
I made two files according to xml book, but when validating these two
files,
it gives me an error that I totally don't understand.
Is there a problem in these codes?
I checked xml and schema files through these following sites:
http://tools.decisionsoft.com/schemaValidate/
|
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...
|
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. ...
| |
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...
|
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...
|
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...
|
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...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |