You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xml.apache.org by Dane Foster <df...@equitytg.com> on 2000/11/08 19:11:08 UTC
Schema Question
I know that most of the post to this list deal with Xerces and Xalan so this may not be the place to ask this question. If it's not please let me know. Anyway, my question is this, in the current Schema specification (..2000/10/XMLSchema), how do I specify that if an element contains a particular attribute it's children must be a specific element?
Example:
Notes*: The myElement node's 'type' attribute can be one of two values "type1" or "type2". If the value is type1 then the root node(s) of the myElement sub-tree must be 'type-1-element'. If the value is type2 then the root node(s) of the myElement sub-tree must be 'type-2-element'.
<!--Scenario one-->
<myElement type="type1">
<type-1-element>Element data goes here</type-1-element>
</myElement>
<!--Scenario two-->
<myElement type="type2">
<type-2-element>Element data goes here</type-2-element>
</myElement>
Dane Foster
Re: Schema Question
Posted by Eric Ye <er...@locus.apache.org>.
Actually, there is a small problem in my first solution, such a restriction will violate a Schema contraint on particle derivation. Here is the modified solution:
<schema ....xmlns:NS="your targetNamespace" targetNamespace ="your targetNamesapce">
< complexType name ="baseType" content="empty"/>
<complexType name="type1" base = "NS:baseType" derivedBy = "extension">
<element name="type-1-element"/> <!-- this will define a content model of (type-1-element) for type1 -->
</complexType>
<complexType name="type2" base="NS:baseType" derivedBy="extension">
<element name="type-2-element"/> <!-- this will define a content model of (type-2-element) for type2 -->
</complexType>
<element name="myelement" type="NS:baseType"/>
</schema>
then the Scenario 3 and 4 would be invalid:
<!--Scenario Three -->
<myElement xsi:type="type1">
<type-2-element>This is an incorrect construct because the value of the 'TYPE' attribute of 'myElement' is "type1", therefore the children of 'myElement' should be 'type-1-element's, not 'type-2-element's</type-2-element>
</myElement>
<!--Scenario Four -->
<myElement xsi:type="type2">
<type-1-element>Element data goes here</type-1-element>
</myElement>
_____
Eric Ye * IBM, JTC - Silicon Valley * ericye@locus.apache.org
----- Original Message -----
From: Dane Foster
To: general@xml.apache.org ; Eric Ye
Sent: Wednesday, November 08, 2000 4:43 PM
Subject: Re: Schema Question
I don't see it. The restriction that I'm trying to apply is based upon the value of the parent type's attribute, not it's element type. I sent out another email with additional samples of what I'm trying to accomplish but I'll do it here again.
The following scenario is an invalid constructs:
<!--Scenario Three -->
<myElement TYPE="type1">
<type-2-element>This is an incorrect construct because the value of the 'TYPE' attribute of 'myElement' is "type1", therefore the children of 'myElement' should be 'type-1-element's, not 'type-2-element's</type-2-element>
</myElement>
----- Original Message -----
From: Eric Ye
To: general@xml.apache.org
Cc: xerces-j-dev@xml.apache.org ; dfoster@equitytg.com
Sent: Wednesday, November 08, 2000 6:28 PM
Subject: Re: Schema Question
Good question to demonstrate powerfulness of schema:
With 04/07 schema spec, here is the syntax:
in your schema :
<schema ....xmlns:NS="your targetNamespace" targetNamespace ="your targetNamesapce">
<complexType name="type1">
<element name="type-1-element"/>
</complexType>
<complexType name="type2" base="NS:type1" derivedBy="restriction">
<element name="type-2-element"/>
</complexType>
<element name="myelement" type="NS:type1"/>
</schema>
in your instance XML document use xsi:type attribute:
by default myelement will have "type1"'s content model , if you do this:
<NS:myelement xmlns:xsi="...." xsi:type="type2"......
then myelement will have "type2"'s content model.
With the CR(10/24) version, the syntax is a little bit different for the schema part, here it is:
<complexType name="type1">
<sequence>
<element name="type-1-element"/>
</sequence>
</complexType>
<complexType name="type2" >
<complexContent >
<restriction base="type1>
<sequence>
<element name="type-2-element"/>
</sequence>
</restriction>
</complexContent>
</complexType>
See, it is much more cumbersome than the 04/07 version, we should let the W3C working Group know that schema syntax is getting more and more diverted from simplicity and flexibility.
_____
Eric Ye * IBM, JTC - Silicon Valley * ericye@locus.apache.org
----- Original Message -----
From: Dane Foster
To: general@xml.apache.org
Sent: Wednesday, November 08, 2000 10:11 AM
Subject: Schema Question
I know that most of the post to this list deal with Xerces and Xalan so this may not be the place to ask this question. If it's not please let me know. Anyway, my question is this, in the current Schema specification (..2000/10/XMLSchema), how do I specify that if an element contains a particular attribute it's children must be a specific element?
Example:
Notes*: The myElement node's 'type' attribute can be one of two values "type1" or "type2". If the value is type1 then the root node(s) of the myElement sub-tree must be 'type-1-element'. If the value is type2 then the root node(s) of the myElement sub-tree must be 'type-2-element'.
<!--Scenario one-->
<myElement type="type1">
<type-1-element>Element data goes here</type-1-element>
</myElement>
<!--Scenario two-->
<myElement type="type2">
<type-2-element>Element data goes here</type-2-element>
</myElement>
Dane Foster
Re: Schema Question
Posted by Eric Ye <er...@locus.apache.org>.
Actually, there is a small problem in my first solution, such a restriction will violate a Schema contraint on particle derivation. Here is the modified solution:
<schema ....xmlns:NS="your targetNamespace" targetNamespace ="your targetNamesapce">
< complexType name ="baseType" content="empty"/>
<complexType name="type1" base = "NS:baseType" derivedBy = "extension">
<element name="type-1-element"/> <!-- this will define a content model of (type-1-element) for type1 -->
</complexType>
<complexType name="type2" base="NS:baseType" derivedBy="extension">
<element name="type-2-element"/> <!-- this will define a content model of (type-2-element) for type2 -->
</complexType>
<element name="myelement" type="NS:baseType"/>
</schema>
then the Scenario 3 and 4 would be invalid:
<!--Scenario Three -->
<myElement xsi:type="type1">
<type-2-element>This is an incorrect construct because the value of the 'TYPE' attribute of 'myElement' is "type1", therefore the children of 'myElement' should be 'type-1-element's, not 'type-2-element's</type-2-element>
</myElement>
<!--Scenario Four -->
<myElement xsi:type="type2">
<type-1-element>Element data goes here</type-1-element>
</myElement>
_____
Eric Ye * IBM, JTC - Silicon Valley * ericye@locus.apache.org
----- Original Message -----
From: Dane Foster
To: general@xml.apache.org ; Eric Ye
Sent: Wednesday, November 08, 2000 4:43 PM
Subject: Re: Schema Question
I don't see it. The restriction that I'm trying to apply is based upon the value of the parent type's attribute, not it's element type. I sent out another email with additional samples of what I'm trying to accomplish but I'll do it here again.
The following scenario is an invalid constructs:
<!--Scenario Three -->
<myElement TYPE="type1">
<type-2-element>This is an incorrect construct because the value of the 'TYPE' attribute of 'myElement' is "type1", therefore the children of 'myElement' should be 'type-1-element's, not 'type-2-element's</type-2-element>
</myElement>
----- Original Message -----
From: Eric Ye
To: general@xml.apache.org
Cc: xerces-j-dev@xml.apache.org ; dfoster@equitytg.com
Sent: Wednesday, November 08, 2000 6:28 PM
Subject: Re: Schema Question
Good question to demonstrate powerfulness of schema:
With 04/07 schema spec, here is the syntax:
in your schema :
<schema ....xmlns:NS="your targetNamespace" targetNamespace ="your targetNamesapce">
<complexType name="type1">
<element name="type-1-element"/>
</complexType>
<complexType name="type2" base="NS:type1" derivedBy="restriction">
<element name="type-2-element"/>
</complexType>
<element name="myelement" type="NS:type1"/>
</schema>
in your instance XML document use xsi:type attribute:
by default myelement will have "type1"'s content model , if you do this:
<NS:myelement xmlns:xsi="...." xsi:type="type2"......
then myelement will have "type2"'s content model.
With the CR(10/24) version, the syntax is a little bit different for the schema part, here it is:
<complexType name="type1">
<sequence>
<element name="type-1-element"/>
</sequence>
</complexType>
<complexType name="type2" >
<complexContent >
<restriction base="type1>
<sequence>
<element name="type-2-element"/>
</sequence>
</restriction>
</complexContent>
</complexType>
See, it is much more cumbersome than the 04/07 version, we should let the W3C working Group know that schema syntax is getting more and more diverted from simplicity and flexibility.
_____
Eric Ye * IBM, JTC - Silicon Valley * ericye@locus.apache.org
----- Original Message -----
From: Dane Foster
To: general@xml.apache.org
Sent: Wednesday, November 08, 2000 10:11 AM
Subject: Schema Question
I know that most of the post to this list deal with Xerces and Xalan so this may not be the place to ask this question. If it's not please let me know. Anyway, my question is this, in the current Schema specification (..2000/10/XMLSchema), how do I specify that if an element contains a particular attribute it's children must be a specific element?
Example:
Notes*: The myElement node's 'type' attribute can be one of two values "type1" or "type2". If the value is type1 then the root node(s) of the myElement sub-tree must be 'type-1-element'. If the value is type2 then the root node(s) of the myElement sub-tree must be 'type-2-element'.
<!--Scenario one-->
<myElement type="type1">
<type-1-element>Element data goes here</type-1-element>
</myElement>
<!--Scenario two-->
<myElement type="type2">
<type-2-element>Element data goes here</type-2-element>
</myElement>
Dane Foster
Re: Schema Question
Posted by Dane Foster <df...@equitytg.com>.
I don't see it. The restriction that I'm trying to apply is based upon the value of the parent type's attribute, not it's element type. I sent out another email with additional samples of what I'm trying to accomplish but I'll do it here again.
The following scenario is an invalid constructs:
<!--Scenario Three -->
<myElement TYPE="type1">
<type-2-element>This is an incorrect construct because the value of the 'TYPE' attribute of 'myElement' is "type1", therefore the children of 'myElement' should be 'type-1-element's, not 'type-2-element's</type-2-element>
</myElement>
----- Original Message -----
From: Eric Ye
To: general@xml.apache.org
Cc: xerces-j-dev@xml.apache.org ; dfoster@equitytg.com
Sent: Wednesday, November 08, 2000 6:28 PM
Subject: Re: Schema Question
Good question to demonstrate powerfulness of schema:
With 04/07 schema spec, here is the syntax:
in your schema :
<schema ....xmlns:NS="your targetNamespace" targetNamespace ="your targetNamesapce">
<complexType name="type1">
<element name="type-1-element"/>
</complexType>
<complexType name="type2" base="NS:type1" derivedBy="restriction">
<element name="type-2-element"/>
</complexType>
<element name="myelement" type="NS:type1"/>
</schema>
in your instance XML document use xsi:type attribute:
by default myelement will have "type1"'s content model , if you do this:
<NS:myelement xmlns:xsi="...." xsi:type="type2"......
then myelement will have "type2"'s content model.
With the CR(10/24) version, the syntax is a little bit different for the schema part, here it is:
<complexType name="type1">
<sequence>
<element name="type-1-element"/>
</sequence>
</complexType>
<complexType name="type2" >
<complexContent >
<restriction base="type1>
<sequence>
<element name="type-2-element"/>
</sequence>
</restriction>
</complexContent>
</complexType>
See, it is much more cumbersome than the 04/07 version, we should let the W3C working Group know that schema syntax is getting more and more diverted from simplicity and flexibility.
_____
Eric Ye * IBM, JTC - Silicon Valley * ericye@locus.apache.org
----- Original Message -----
From: Dane Foster
To: general@xml.apache.org
Sent: Wednesday, November 08, 2000 10:11 AM
Subject: Schema Question
I know that most of the post to this list deal with Xerces and Xalan so this may not be the place to ask this question. If it's not please let me know. Anyway, my question is this, in the current Schema specification (..2000/10/XMLSchema), how do I specify that if an element contains a particular attribute it's children must be a specific element?
Example:
Notes*: The myElement node's 'type' attribute can be one of two values "type1" or "type2". If the value is type1 then the root node(s) of the myElement sub-tree must be 'type-1-element'. If the value is type2 then the root node(s) of the myElement sub-tree must be 'type-2-element'.
<!--Scenario one-->
<myElement type="type1">
<type-1-element>Element data goes here</type-1-element>
</myElement>
<!--Scenario two-->
<myElement type="type2">
<type-2-element>Element data goes here</type-2-element>
</myElement>
Dane Foster
Re: Schema Question
Posted by Eric Ye <er...@locus.apache.org>.
Good question to demonstrate powerfulness of schema:
With 04/07 schema spec, here is the syntax:
in your schema :
<schema ....xmlns:NS="your targetNamespace" targetNamespace ="your targetNamesapce">
<complexType name="type1">
<element name="type-1-element"/>
</complexType>
<complexType name="type2" base="NS:type1" derivedBy="restriction">
<element name="type-2-element"/>
</complexType>
<element name="myelement" type="NS:type1"/>
</schema>
in your instance XML document use xsi:type attribute:
by default myelement will have "type1"'s content model , if you do this:
<NS:myelement xmlns:xsi="...." xsi:type="type2"......
then myelement will have "type2"'s content model.
With the CR(10/24) version, the syntax is a little bit different for the schema part, here it is:
<complexType name="type1">
<sequence>
<element name="type-1-element"/>
</sequence>
</complexType>
<complexType name="type2" >
<complexContent >
<restriction base="type1>
<sequence>
<element name="type-2-element"/>
</sequence>
</restriction>
</complexContent>
</complexType>
See, it is much more cumbersome than the 04/07 version, we should let the W3C working Group know that schema syntax is getting more and more diverted from simplicity and flexibility.
_____
Eric Ye * IBM, JTC - Silicon Valley * ericye@locus.apache.org
----- Original Message -----
From: Dane Foster
To: general@xml.apache.org
Sent: Wednesday, November 08, 2000 10:11 AM
Subject: Schema Question
I know that most of the post to this list deal with Xerces and Xalan so this may not be the place to ask this question. If it's not please let me know. Anyway, my question is this, in the current Schema specification (..2000/10/XMLSchema), how do I specify that if an element contains a particular attribute it's children must be a specific element?
Example:
Notes*: The myElement node's 'type' attribute can be one of two values "type1" or "type2". If the value is type1 then the root node(s) of the myElement sub-tree must be 'type-1-element'. If the value is type2 then the root node(s) of the myElement sub-tree must be 'type-2-element'.
<!--Scenario one-->
<myElement type="type1">
<type-1-element>Element data goes here</type-1-element>
</myElement>
<!--Scenario two-->
<myElement type="type2">
<type-2-element>Element data goes here</type-2-element>
</myElement>
Dane Foster
setDeferNodeExpansion
Posted by Gagan Gaur <ga...@dtius.com>.
Hi,
I am using DOMParser to create a DOM tree from an InputSource and using a
DTD to validate the XML. Also some of the attributes in the XML are
defaulted from the DTD. When I call the DOMParser's parse() method, it adds
those attributes to the resulting DOM tree. But when I use
setDeferNodeExpansion(false), I find that each attribute has been added
twice to the XML. Anybody can tell me why it adds them twice and how to
avoid it?
I am using Xerces version 1.1.2. I tried 1.1.3 and 1.2.0 and I get the same
error. It works fine with 1.2.1 though. Is it a known bug in earlier
versions of Xerces?
Thanks for help
Gagan
Re: Schema Question
Posted by Eric Ye <er...@locus.apache.org>.
Good question to demonstrate powerfulness of schema:
With 04/07 schema spec, here is the syntax:
in your schema :
<schema ....xmlns:NS="your targetNamespace" targetNamespace ="your targetNamesapce">
<complexType name="type1">
<element name="type-1-element"/>
</complexType>
<complexType name="type2" base="NS:type1" derivedBy="restriction">
<element name="type-2-element"/>
</complexType>
<element name="myelement" type="NS:type1"/>
</schema>
in your instance XML document use xsi:type attribute:
by default myelement will have "type1"'s content model , if you do this:
<NS:myelement xmlns:xsi="...." xsi:type="type2"......
then myelement will have "type2"'s content model.
With the CR(10/24) version, the syntax is a little bit different for the schema part, here it is:
<complexType name="type1">
<sequence>
<element name="type-1-element"/>
</sequence>
</complexType>
<complexType name="type2" >
<complexContent >
<restriction base="type1>
<sequence>
<element name="type-2-element"/>
</sequence>
</restriction>
</complexContent>
</complexType>
See, it is much more cumbersome than the 04/07 version, we should let the W3C working Group know that schema syntax is getting more and more diverted from simplicity and flexibility.
_____
Eric Ye * IBM, JTC - Silicon Valley * ericye@locus.apache.org
----- Original Message -----
From: Dane Foster
To: general@xml.apache.org
Sent: Wednesday, November 08, 2000 10:11 AM
Subject: Schema Question
I know that most of the post to this list deal with Xerces and Xalan so this may not be the place to ask this question. If it's not please let me know. Anyway, my question is this, in the current Schema specification (..2000/10/XMLSchema), how do I specify that if an element contains a particular attribute it's children must be a specific element?
Example:
Notes*: The myElement node's 'type' attribute can be one of two values "type1" or "type2". If the value is type1 then the root node(s) of the myElement sub-tree must be 'type-1-element'. If the value is type2 then the root node(s) of the myElement sub-tree must be 'type-2-element'.
<!--Scenario one-->
<myElement type="type1">
<type-1-element>Element data goes here</type-1-element>
</myElement>
<!--Scenario two-->
<myElement type="type2">
<type-2-element>Element data goes here</type-2-element>
</myElement>
Dane Foster