Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 26th, 2008, 11:51 AM
Authorized User
 
Join Date: Aug 2008
Posts: 17
Thanks: 1
Thanked 0 Times in 0 Posts
Default Bewildering schema error in validation.

OK, I have a transformed XML document that resembles this:

<SystemContextLog>
<LoggingChange DateTime="numbers" Reason="reasons." />

<SystemContext><DateTime>numbers</DateTime>

child elements...
</SystemContext>
</SystemContextLog>

My schema will fail to validate, giving me the error of "Schema Err - The element "SystemContextLog" has invalid child element of "SystemContext"...blah blah blah.
<SystemContext> elements validate fine based on the schema, with all subsequent child elements, just like the <LoggingChange /> elements on a normal basis...if the <LoggingChange /> element is not before <SystemContext>. BUT if a <LoggingChange /> element is before a <SystemContext> element, like the example above, then I will get the schema error.
Now, the <LoggingChange /> element is not always there. Most of the time it is at the bottom of the document, sometimes in groups, if in the XML doc at all. I have stepped through the validation process and it seems that everything is normal, in terms of what is being read by the xmlreader.
I have no idea what could be causing this validation error. Consider this as well. I can have multiple <LoggingChange /> errors at the end of the document and they will not invalidate each other. I have other instances where another tag, that has no end element (<Stuff />) is before other elements and they are not invalidating like the above.
What could possibly be causing this error?


 
Old August 26th, 2008, 12:23 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You expect us to tell you why your document is invalid against your schema without seeing the schema, and without seeing the instance document (only something that "resembles" it)?

Get real!

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
 
Old August 26th, 2008, 12:49 PM
Authorized User
 
Join Date: Aug 2008
Posts: 17
Thanks: 1
Thanked 0 Times in 0 Posts
Default

No, I don't expect you to tell me what is wrong with my schema, I expect some ideas, possibilities and potential problems. Maybe someone who has seen a similar problem. Maybe someone who knows XSLT/XSD enough that they could give some pointers. Hence why I said, "What could *possibly* be causing this error?".

And what you think "resembles" it, is actually taken from my transformed document, with only the data within the elements removed. Otherwise, it is exactly what it looks like.
Like many other people here, I have removed information that I may think is sensitive or unnecessary and distracting. They aren't the purpose. So what is different about my example than others?

An example that "resembles" the real schema:
<?xml version="1.0" ?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="SystemContextLog">
    <xs:complexType>
     <xs:sequence>
        <xs:element maxOccurs="unbounded" minOccurs="0" name="SystemContext">
         child elements
        </xs:element>
        <xs:element minOccurs="0" maxOccurs="unbounded" name="LoggingChange">
         child elements
        </xs:element>
     </xs:sequence>
    </xs:complexType>
</xs:element>
</xs:schema>

I am wondering if maybe something is being brought over in the transform. Or is it that the sequence is out of order? But that doesn't seem like it's necessary since other schemas validate other documents that are out of order.
 
Old August 26th, 2008, 12:59 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Your schema describes a content model in which the SystemContext elements must always precede any LoggingChange elements (that's what xs:sequence means), but your instance document does not satisfy this constraint.

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
 
Old August 26th, 2008, 01:09 PM
Authorized User
 
Join Date: Aug 2008
Posts: 17
Thanks: 1
Thanked 0 Times in 0 Posts
Default

I would use <xs:all> instead, but that prevents the elements from happening a max of 1 time. How do you get the elements to be valid in any order, with an unbounded number of times?

 
Old August 26th, 2008, 01:16 PM
Authorized User
 
Join Date: Aug 2008
Posts: 17
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Wait, nest a <xs:choice> element within a <xs:sequence> element? with minOccurs="0" and maxOccurs="unbounded"?

seems to have worked as far as validating...






Similar Threads
Thread Thread Starter Forum Replies Last Post
Error in XML Schema example?? witch_hazel BOOK: Beginning XML, 4th Ed ISBN: 978-0-470-11487-2 3 November 1st, 2007 02:14 PM
Schema Validation markus2000 XSLT 1 June 22nd, 2006 08:23 AM
XML schema validation problems BrendonMelville XML 3 February 15th, 2006 06:02 PM
XML validation with Schema/DTD using JAXP Hendrik XML 0 December 28th, 2004 06:58 AM
XML Schema Validation without internet esp5a XML 1 September 5th, 2003 06:22 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.