Issues extending an XSD schema with any elements
I have an application that tries to validate the following XML:
<?xml version="1.0" encoding="UTF-8"?>
<cnt:agenda xmlns:cnt="urn:ppp:contacts"
xmlns:cnt2="urn:ppp:contactsv2"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:ppp:contactsv2 contactsv2.xsd urn:ppp:contacts contacts.xsd ">
<cnt:entry>
<cnt:number>12345678</cnt:number>
</cnt:entry>
<cnt:entry>
<cnt:number>12345678</cnt:number>
<cnt2:personal-info>
<cnt2:genre>male</cnt2:genre>
<cnt2:age>30</cnt2:age>
</cnt2:personal-info>
</cnt:entry>
</cnt:agenda>
In order to fulfill that, I have these two XSD schemas:
contacts.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
targetNamespace="urn:ppp:contacts"
xmlns="urn:ppp:contacts"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="agenda">
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:element name="entry" type="entry-type"/>
<xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="entry-type">
<xs:sequence>
<xs:element name="display-name" type="xs:string" minOccurs="0"/>
<xs:element name="number" type="xs:string"/>
<xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:anyAttribute namespace="##other" processContents="lax"/>
</xs:complexType>
</xs:schema>
and contactsv2.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="urn:ppp:contactsv2"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:cnt2="urn:ppp:contactsv2"
xmlns:cnt="urn:ppp:contacts"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:import namespace="urn:ppp:contacts" schemaLocation="contacts.xsd"/>
<!-- Child of entry element -->
<xs:element name="personal-info"
type="cnt2:personal-infoType" />
<xs:complexType name="personal-infoType">
<xs:sequence>
<xs:element name="genre"
type="xs:string" />
<xs:element name="age" type="xs:unsignedByte" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
As you can see, the second schema extends the first one for adding some new child to entry element. At this point, I have found some issues:
If an extended element is typed incorrectly (for example, gere instead of genre) the validator does not give any error. I know that this is because of having lax as the value of processContents attribute of all the any elements, but I'm not supposed to change contacts.xsd schema. So, can I bypass this behavior somehow?
Can I control somehow where are the extended elements added? Because if I add the personal-info element as a child of agenda the validator says that the document is valid, and I want to let only appear that element as a child of entry.
Note: I cannot use XSD 1.1 version
Thanks in advance
xml xsd xml-validation
add a comment |
I have an application that tries to validate the following XML:
<?xml version="1.0" encoding="UTF-8"?>
<cnt:agenda xmlns:cnt="urn:ppp:contacts"
xmlns:cnt2="urn:ppp:contactsv2"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:ppp:contactsv2 contactsv2.xsd urn:ppp:contacts contacts.xsd ">
<cnt:entry>
<cnt:number>12345678</cnt:number>
</cnt:entry>
<cnt:entry>
<cnt:number>12345678</cnt:number>
<cnt2:personal-info>
<cnt2:genre>male</cnt2:genre>
<cnt2:age>30</cnt2:age>
</cnt2:personal-info>
</cnt:entry>
</cnt:agenda>
In order to fulfill that, I have these two XSD schemas:
contacts.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
targetNamespace="urn:ppp:contacts"
xmlns="urn:ppp:contacts"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="agenda">
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:element name="entry" type="entry-type"/>
<xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="entry-type">
<xs:sequence>
<xs:element name="display-name" type="xs:string" minOccurs="0"/>
<xs:element name="number" type="xs:string"/>
<xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:anyAttribute namespace="##other" processContents="lax"/>
</xs:complexType>
</xs:schema>
and contactsv2.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="urn:ppp:contactsv2"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:cnt2="urn:ppp:contactsv2"
xmlns:cnt="urn:ppp:contacts"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:import namespace="urn:ppp:contacts" schemaLocation="contacts.xsd"/>
<!-- Child of entry element -->
<xs:element name="personal-info"
type="cnt2:personal-infoType" />
<xs:complexType name="personal-infoType">
<xs:sequence>
<xs:element name="genre"
type="xs:string" />
<xs:element name="age" type="xs:unsignedByte" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
As you can see, the second schema extends the first one for adding some new child to entry element. At this point, I have found some issues:
If an extended element is typed incorrectly (for example, gere instead of genre) the validator does not give any error. I know that this is because of having lax as the value of processContents attribute of all the any elements, but I'm not supposed to change contacts.xsd schema. So, can I bypass this behavior somehow?
Can I control somehow where are the extended elements added? Because if I add the personal-info element as a child of agenda the validator says that the document is valid, and I want to let only appear that element as a child of entry.
Note: I cannot use XSD 1.1 version
Thanks in advance
xml xsd xml-validation
add a comment |
I have an application that tries to validate the following XML:
<?xml version="1.0" encoding="UTF-8"?>
<cnt:agenda xmlns:cnt="urn:ppp:contacts"
xmlns:cnt2="urn:ppp:contactsv2"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:ppp:contactsv2 contactsv2.xsd urn:ppp:contacts contacts.xsd ">
<cnt:entry>
<cnt:number>12345678</cnt:number>
</cnt:entry>
<cnt:entry>
<cnt:number>12345678</cnt:number>
<cnt2:personal-info>
<cnt2:genre>male</cnt2:genre>
<cnt2:age>30</cnt2:age>
</cnt2:personal-info>
</cnt:entry>
</cnt:agenda>
In order to fulfill that, I have these two XSD schemas:
contacts.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
targetNamespace="urn:ppp:contacts"
xmlns="urn:ppp:contacts"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="agenda">
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:element name="entry" type="entry-type"/>
<xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="entry-type">
<xs:sequence>
<xs:element name="display-name" type="xs:string" minOccurs="0"/>
<xs:element name="number" type="xs:string"/>
<xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:anyAttribute namespace="##other" processContents="lax"/>
</xs:complexType>
</xs:schema>
and contactsv2.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="urn:ppp:contactsv2"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:cnt2="urn:ppp:contactsv2"
xmlns:cnt="urn:ppp:contacts"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:import namespace="urn:ppp:contacts" schemaLocation="contacts.xsd"/>
<!-- Child of entry element -->
<xs:element name="personal-info"
type="cnt2:personal-infoType" />
<xs:complexType name="personal-infoType">
<xs:sequence>
<xs:element name="genre"
type="xs:string" />
<xs:element name="age" type="xs:unsignedByte" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
As you can see, the second schema extends the first one for adding some new child to entry element. At this point, I have found some issues:
If an extended element is typed incorrectly (for example, gere instead of genre) the validator does not give any error. I know that this is because of having lax as the value of processContents attribute of all the any elements, but I'm not supposed to change contacts.xsd schema. So, can I bypass this behavior somehow?
Can I control somehow where are the extended elements added? Because if I add the personal-info element as a child of agenda the validator says that the document is valid, and I want to let only appear that element as a child of entry.
Note: I cannot use XSD 1.1 version
Thanks in advance
xml xsd xml-validation
I have an application that tries to validate the following XML:
<?xml version="1.0" encoding="UTF-8"?>
<cnt:agenda xmlns:cnt="urn:ppp:contacts"
xmlns:cnt2="urn:ppp:contactsv2"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:ppp:contactsv2 contactsv2.xsd urn:ppp:contacts contacts.xsd ">
<cnt:entry>
<cnt:number>12345678</cnt:number>
</cnt:entry>
<cnt:entry>
<cnt:number>12345678</cnt:number>
<cnt2:personal-info>
<cnt2:genre>male</cnt2:genre>
<cnt2:age>30</cnt2:age>
</cnt2:personal-info>
</cnt:entry>
</cnt:agenda>
In order to fulfill that, I have these two XSD schemas:
contacts.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
targetNamespace="urn:ppp:contacts"
xmlns="urn:ppp:contacts"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="agenda">
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:element name="entry" type="entry-type"/>
<xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="entry-type">
<xs:sequence>
<xs:element name="display-name" type="xs:string" minOccurs="0"/>
<xs:element name="number" type="xs:string"/>
<xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:anyAttribute namespace="##other" processContents="lax"/>
</xs:complexType>
</xs:schema>
and contactsv2.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="urn:ppp:contactsv2"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:cnt2="urn:ppp:contactsv2"
xmlns:cnt="urn:ppp:contacts"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:import namespace="urn:ppp:contacts" schemaLocation="contacts.xsd"/>
<!-- Child of entry element -->
<xs:element name="personal-info"
type="cnt2:personal-infoType" />
<xs:complexType name="personal-infoType">
<xs:sequence>
<xs:element name="genre"
type="xs:string" />
<xs:element name="age" type="xs:unsignedByte" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
As you can see, the second schema extends the first one for adding some new child to entry element. At this point, I have found some issues:
If an extended element is typed incorrectly (for example, gere instead of genre) the validator does not give any error. I know that this is because of having lax as the value of processContents attribute of all the any elements, but I'm not supposed to change contacts.xsd schema. So, can I bypass this behavior somehow?
Can I control somehow where are the extended elements added? Because if I add the personal-info element as a child of agenda the validator says that the document is valid, and I want to let only appear that element as a child of entry.
Note: I cannot use XSD 1.1 version
Thanks in advance
xml xsd xml-validation
xml xsd xml-validation
asked Nov 22 at 19:43
Jon Ander
13
13
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I'm not sure whether "no" counts as an answer, but I don't think there is an easy solution to either problem. You could try modifying the given schema without really modifying it by using xs:redefine, but personally I hate that feature, and find it far preferable to modify the supplied schema as a source document (perhaps controlling the process by making the modifications repeatable, via an XSLT stylesheet).
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53437243%2fissues-extending-an-xsd-schema-with-any-elements%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I'm not sure whether "no" counts as an answer, but I don't think there is an easy solution to either problem. You could try modifying the given schema without really modifying it by using xs:redefine, but personally I hate that feature, and find it far preferable to modify the supplied schema as a source document (perhaps controlling the process by making the modifications repeatable, via an XSLT stylesheet).
add a comment |
I'm not sure whether "no" counts as an answer, but I don't think there is an easy solution to either problem. You could try modifying the given schema without really modifying it by using xs:redefine, but personally I hate that feature, and find it far preferable to modify the supplied schema as a source document (perhaps controlling the process by making the modifications repeatable, via an XSLT stylesheet).
add a comment |
I'm not sure whether "no" counts as an answer, but I don't think there is an easy solution to either problem. You could try modifying the given schema without really modifying it by using xs:redefine, but personally I hate that feature, and find it far preferable to modify the supplied schema as a source document (perhaps controlling the process by making the modifications repeatable, via an XSLT stylesheet).
I'm not sure whether "no" counts as an answer, but I don't think there is an easy solution to either problem. You could try modifying the given schema without really modifying it by using xs:redefine, but personally I hate that feature, and find it far preferable to modify the supplied schema as a source document (perhaps controlling the process by making the modifications repeatable, via an XSLT stylesheet).
answered Nov 22 at 23:29
Michael Kay
108k659114
108k659114
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53437243%2fissues-extending-an-xsd-schema-with-any-elements%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown