I have a scenario where context should be restricted when certain elements from the absolute reference element, for example, under the element ADE referenced in ADCNfig, I do not want to specify only element, domain name, username, password hostname, portal number
& lt; Element name = "AD" & gt; & Lt; ComplexType & gt; & Lt; Sequence & gt; & Lt; Element name = "hostName" type = "string" / & gt; & Lt; Element name = "portNumber" type = "string" / & gt; & Lt; Element name = "domainName" type = "string" / & gt; & Lt; Element name = "userName" type = "string" / & gt; & Lt; Element name = "password" type = "string" /> & Lt; / Sequence & gt; & Lt; / ComplexType & gt; & Lt; / Element & gt; & Lt; Element name = "ADConfig" & gt; & Lt; ComplexType & gt; & Lt; Sequence & gt; & Lt; Element ref = "tns: AD" /> & Lt; / Sequence & gt; & Lt; / ComplexType & gt; & Lt; / Element & gt; In terms of example documents I think that you are saying that you want ed.
element that is the ADConfig
element There are children, only the name of the domain name, username and passwords are of the order. Otherwise, in this example document you may have a AD
element, which was in all five children listed above.
Believing that I am right, I am afraid that your exact requirement is not just possible in the current version of XSD. I believe the XML Schema 1.1 can solve your problem. However, if it is possible to rewrite your schema then it may be possible that by creating two complex types, you can create two models for the elements with the same name (in different contexts) for example,
& lt ;? XML version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Xs: schema xmlns: xs = "http://www.w3.org/2001/XMLSchema" elementFormat = "ineligible" & gt; & Lt; X: complex type name = "ADType 1" & gt; & Lt; XS: Sequence & gt; & Lt; Xs: element name = "hostname" type = "x: string" /> & Lt; Xs: element name = "port number" type = "x: string" /> & Lt; Xs: element name = "domain name" type = "x: string" /> & Lt; Xs: element name = "user name" type = "x: string" /> & Lt; Xs: element name = "password" type = "x: string" /> & Lt; / XS: sequence & gt; & Lt; / XS: complexType & gt; & Lt; X: complex type name = "ADType2" & gt; & Lt; XS: Sequence & gt; & Lt; Xs: element name = "domain name" type = "x: string" /> & Lt; Xs: element name = "user name" type = "x: string" /> & Lt; Xs: element name = "password" type = "x: string" /> & Lt; / XS: sequence & gt; & Lt; / XS: complexType & gt; & Lt; Xs: element name = "edited" & gt; & Lt; XS: complexType & gt; & Lt; XS: Sequence & gt; & Lt; Xs: element ref = "adiconfig 1" /> & Lt; Xs: element ref = "adiconfig 2" /> & Lt; / XS: sequence & gt; & Lt; / XS: complexType & gt; & Lt; / XS: element & gt; & Lt; Xs: element name = "ADConfig1" & gt; & Lt; XS: complexType & gt; & Lt; XS: Sequence & gt; & Lt; Xs: element type = "ADTIP1" name = "ads" /> & Lt; / XS: sequence & gt; & Lt; / XS: complexType & gt; & Lt; / XS: element & gt; & Lt; Xs: element name = "ADConfig2" & gt; & Lt; XS: complexType & gt; & Lt; XS: Sequence & gt; & Lt; Xs: element type = "ADType2" name = "ads" /> & Lt; / XS: sequence & gt; & Lt; / XS: complexType & gt; & Lt; / XS: element & gt; & Lt; / XS: Schema & gt;
The above two models are ADType1
and ADType2
each of which is named AD
. In your situation, you can create a global type for AD
, which is used within the ADConfig
element and another type that can be used elsewhere .
If you can not use this kind of model (perhaps the type is defined elsewhere for AD
), then you have to provide the same type of rules Annotations can be used by XML Schema 1.1
Comments
Post a Comment