XInclude and XSchema

Discussion in 'XML' started by Tjerk Wolterink, Oct 11, 2005.

  1. I have an xml document that
    conforms to my xschema document.

    Now i wanted to use xinclude in my xml document.

    But when i want to validate the xml document to the xschema
    i get the following error:

    --
    [Xerces-J 2.7.1] Validating "structure.xml" against
    "file:/D:/development/webapps/XCManager/web/WEB-INF/schemas/structure.xsd"
    ....
    Ln 48 Col 70 - cvc-complex-type.2.4.a: Invalid content was found
    starting with element 'xi:include'. One of
    '{"http://www.wolterinkwebdesign.com/xml/structure":class}' is expected.
    --


    What should i do?

    I want to be able to use the xi:include element anywhere in
    my xml document.
    Should i change my xschema?
    Tjerk Wolterink, Oct 11, 2005
    #1
    1. Advertising

  2. Tjerk Wolterink writes:

    > I have an xml document that conforms to my xschema document.
    >
    > Now i wanted to use xinclude in my xml document.
    >
    > But when i want to validate the xml document to the xschema i get
    > the following error:
    >
    > I want to be able to use the xi:include element anywhere in my xml
    > document. Should i change my xschema?


    Yeah, this is a real pain. I don't know of a good general solution.

    One could imagine writing an XSLT transform which produced a new
    XInclude-friendly schema from an ordinary original, but the result
    would be O(n^2) in size . . .

    ht
    --
    Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
    Half-time member of W3C Team
    2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
    Fax: (44) 131 650-4587, e-mail:
    URL: http://www.ltg.ed.ac.uk/~ht/
    [mail really from me _always_ has this .sig -- mail without it is forged spam]
    Henry S. Thompson, Oct 12, 2005
    #2
    1. Advertising

  3. Henry S. Thompson wrote:
    > Tjerk Wolterink writes:
    >
    >
    >>I have an xml document that conforms to my xschema document.
    >>
    >>Now i wanted to use xinclude in my xml document.
    >>
    >>But when i want to validate the xml document to the xschema i get
    >>the following error:
    >>
    >>I want to be able to use the xi:include element anywhere in my xml
    >>document. Should i change my xschema?

    >
    >
    > Yeah, this is a real pain. I don't know of a good general solution.
    >
    > One could imagine writing an XSLT transform which produced a new
    > XInclude-friendly schema from an ordinary original, but the result
    > would be O(n^2) in size . . .
    >
    > ht


    Should'nt the xml schema xinclude elements be first processed before
    it is validated against an xschema document??

    Does'nt the w3c define how it must be done?

    I'm using Xerces 2.7.1, they claim they support xinclude.
    Tjerk Wolterink, Oct 12, 2005
    #3
  4. Tjerk Wolterink wrote:
    > Should'nt the xml schema xinclude elements be first processed before
    > it is validated against an xschema document??
    >
    > Does'nt the w3c define how it must be done?


    I re-read the XInclude recommendation, it is not clear to me. The
    recommendation talks about including "infosets", which I understand as
    the product of an XML Schema validation (right?).

    Suppose that file A "xincludes" file B: this would mean that both A and
    B are supposed to be validated against their respective XML schemas
    first, and then merged. Hence, it would not be allowed to have 2 invalid
    files A and B, whose merge however is valid. (I guess the 2 files have
    to be at least well formed in order to produce infosets).

    The question can be summarized simply as: "do you first Xinclude and
    then check schema conformance, or first check schema conformance and
    then Xinclude ?"

    Pascal
    Pascal Sartoretti, Oct 12, 2005
    #4
  5. Pascal Sartoretti wrote:
    > Tjerk Wolterink wrote:
    >
    >> Should'nt the xml schema xinclude elements be first processed before
    >> it is validated against an xschema document??
    >>
    >> Does'nt the w3c define how it must be done?

    >
    >
    > I re-read the XInclude recommendation, it is not clear to me. The
    > recommendation talks about including "infosets", which I understand as
    > the product of an XML Schema validation (right?).
    >
    > Suppose that file A "xincludes" file B: this would mean that both A and
    > B are supposed to be validated against their respective XML schemas
    > first, and then merged. Hence, it would not be allowed to have 2 invalid
    > files A and B, whose merge however is valid. (I guess the 2 files have
    > to be at least well formed in order to produce infosets).
    >
    > The question can be summarized simply as: "do you first Xinclude and
    > then check schema conformance, or first check schema conformance and
    > then Xinclude ?"
    >


    anyone has an anwser?
    Tjerk Wolterink, Oct 12, 2005
    #5
  6. Infoset is not necessarily post schema-validation infoset. XInclude
    and W3C XML Schema are independent RECs, and can and should be
    implemented independently.

    There is no unique correct ordering of the two -- I might wish to
    constrain where xi:include elements may go in my document, so write a
    schema which specifies thes and schema-validate first, then XInclude,
    or I might only care about the validity of the result, so I XInclude
    first, then schema-validate, or I might have _two_ schemas, and do
    schema-validate, XInclude, schema-validate.

    There are a number of XML Pipelining languages/tools around, to allow
    you to specify which operations you want performed in which order.

    I don't know if Xerces easily allows you to specify
    XInclude-then-schema-validate, which appears to be what the OP wants.

    ht
    --
    Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
    Half-time member of W3C Team
    2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
    Fax: (44) 131 650-4587, e-mail:
    URL: http://www.ltg.ed.ac.uk/~ht/
    [mail really from me _always_ has this .sig -- mail without it is forged spam]
    Henry S. Thompson, Oct 12, 2005
    #6
  7. Tjerk Wolterink wrote:
    > Pascal Sartoretti wrote:
    >
    >> Tjerk Wolterink wrote:
    >>
    >>> Should'nt the xml schema xinclude elements be first processed before
    >>> it is validated against an xschema document??
    >>>
    >>> Does'nt the w3c define how it must be done?

    >>
    >>
    >>
    >> I re-read the XInclude recommendation, it is not clear to me. The
    >> recommendation talks about including "infosets", which I understand as
    >> the product of an XML Schema validation (right?).
    >>
    >> Suppose that file A "xincludes" file B: this would mean that both A
    >> and B are supposed to be validated against their respective XML
    >> schemas first, and then merged. Hence, it would not be allowed to have
    >> 2 invalid files A and B, whose merge however is valid. (I guess the 2
    >> files have to be at least well formed in order to produce infosets).
    >>
    >> The question can be summarized simply as: "do you first Xinclude and
    >> then check schema conformance, or first check schema conformance and
    >> then Xinclude ?"
    >>

    >
    > anyone has an anwser?
    >
    >



    i think i found the answer here:
    http://www.xml.com/pub/a/2002/07/31/xinclude.html?page=2

    CopyPaste:
    ===
    One of the most common questions about XInclude is how inclusion
    interacts with validation, XSL transformation, and other processes
    that may be applied to an XML document. The short answer is that it
    doesn't. XInclusion is not part of any other XML process. It is a
    separate step which you may or may not perform when and where it is
    useful to you.

    For example, consider validation against a schema. A document can be
    validated before inclusion, after inclusion, or both. If you validate
    the document before the xi:include elements are replaced, then the
    schema has to declare the xi:include elements just like it would
    declare any other element. If you validate the document after the
    xi:include elements are replaced, then the schema has to declare the
    replacement elements. Inclusion and validation are separate,
    orthogonal processes that can be performed in any order which is
    convenient in the local environment.
    ===
    Tjerk Wolterink, Oct 12, 2005
    #7
  8. Henry S. Thompson wrote:
    > Infoset is not necessarily post schema-validation infoset. XInclude
    > and W3C XML Schema are independent RECs, and can and should be
    > implemented independently.
    >
    > There is no unique correct ordering of the two -- I might wish to
    > constrain where xi:include elements may go in my document, so write a
    > schema which specifies thes and schema-validate first, then XInclude,
    > or I might only care about the validity of the result, so I XInclude
    > first, then schema-validate, or I might have _two_ schemas, and do
    > schema-validate, XInclude, schema-validate.
    >
    > There are a number of XML Pipelining languages/tools around, to allow
    > you to specify which operations you want performed in which order.
    >
    > I don't know if Xerces easily allows you to specify
    > XInclude-then-schema-validate, which appears to be what the OP wants.
    >


    Yes that is what i want, i
    think is it easily possible with the api,
    but my xml editor does not have an option
    to xlinclude-then-schema-validate.

    too bad.


    But.. there is one strange thing:

    When i have a document like this:

    <?xml version="1.0"?>
    <human-interface
    xmlns="http://www.wolterinkwebdesign.com/xml/human-interface"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.wolterinkwebdesign.com/xml/human-interface
    ../schemas/human-interface.xsd"
    xmlns:xi="http://www.w3.org/2001/XInclude">

    <xi:include href="validation-messages.xml" parse="xml"/>

    </human-interface>


    Then there is enough information in the document to validate the
    document against the schema (./schemas/human-interface.xsd)

    But the validator does not know wether it must
    xinclude-then-schema-validate
    or just start schema-validate right away.

    Should'nt w3c define a attribute like
    xi:includeBeforeValidate="true"
    ??

    Now i do'nt know how to document is validated with a validator.
    ( must i really programmatically setup the validator to work right?)
    Tjerk Wolterink, Oct 12, 2005
    #8
  9. Tjerk Wolterink wrote:
    > i think i found the answer here:
    > http://www.xml.com/pub/a/2002/07/31/xinclude.html?page=2
    >
    > CopyPaste:
    > ===
    > One of the most common questions about XInclude is how inclusion
    > interacts with validation, XSL transformation, and other processes that
    > may be applied to an XML document. The short answer is that it doesn't.
    > XInclusion is not part of any other XML process. It is a separate step
    > which you may or may not perform when and where it is useful to you.
    >
    > For example, consider validation against a schema. A document can be
    > validated before inclusion, after inclusion, or both.


    Very good source, thanks (Elliotte Rusty Harold is always a goldmine...).

    So it seems that everything is possible, however it would be nice to
    have real-world experience or "best practices" to know what works well
    (or not!). Can anybody provide such information?

    Pascal
    Pascal Sartoretti, Oct 13, 2005
    #9
  10. Tjerk Wolterink wrote:
    > Henry S. Thompson wrote:
    >
    >> Infoset is not necessarily post schema-validation infoset. XInclude
    >> and W3C XML Schema are independent RECs, and can and should be
    >> implemented independently.
    >>
    >> There is no unique correct ordering of the two -- I might wish to
    >> constrain where xi:include elements may go in my document, so write a
    >> schema which specifies thes and schema-validate first, then XInclude,
    >> or I might only care about the validity of the result, so I XInclude
    >> first, then schema-validate, or I might have _two_ schemas, and do
    >> schema-validate, XInclude, schema-validate.
    >>
    >> There are a number of XML Pipelining languages/tools around, to allow
    >> you to specify which operations you want performed in which order.
    >>
    >> I don't know if Xerces easily allows you to specify
    >> XInclude-then-schema-validate, which appears to be what the OP wants.
    >>

    >
    > Yes that is what i want, i
    > think is it easily possible with the api,
    > but my xml editor does not have an option
    > to xlinclude-then-schema-validate.
    >
    > too bad.
    >
    >
    > But.. there is one strange thing:
    >
    > When i have a document like this:
    >
    > <?xml version="1.0"?>
    > <human-interface
    > xmlns="http://www.wolterinkwebdesign.com/xml/human-interface"
    > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    > xsi:schemaLocation="http://www.wolterinkwebdesign.com/xml/human-interface
    > ./schemas/human-interface.xsd"
    > xmlns:xi="http://www.w3.org/2001/XInclude">
    >
    > <xi:include href="validation-messages.xml" parse="xml"/>
    >
    > </human-interface>
    >
    >
    > Then there is enough information in the document to validate the
    > document against the schema (./schemas/human-interface.xsd)
    >
    > But the validator does not know wether it must
    > xinclude-then-schema-validate
    > or just start schema-validate right away.
    >
    > Should'nt w3c define a attribute like
    > xi:includeBeforeValidate="true"
    > ??
    >
    > Now i do'nt know how to document is validated with a validator.
    > ( must i really programmatically setup the validator to work right?)


    anyone??
    Tjerk Wolterink, Oct 13, 2005
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Karl
    Replies:
    3
    Views:
    351
  2. Binesh Bannerjee
    Replies:
    3
    Views:
    1,631
    Martin Honnen
    Nov 27, 2004
  3. SL
    Replies:
    0
    Views:
    519
  4. Tjerk Wolterink

    XSchema: help

    Tjerk Wolterink, Sep 1, 2005, in forum: XML
    Replies:
    1
    Views:
    551
    Soren Kuula
    Sep 1, 2005
  5. Tjerk Wolterink

    xschema: problem

    Tjerk Wolterink, Sep 1, 2005, in forum: XML
    Replies:
    0
    Views:
    397
    Tjerk Wolterink
    Sep 1, 2005
Loading...

Share This Page