Re: XSD with "required" attribute option related query
Loren Cahlander <[email protected]> Mon, 24 Feb 2020 10:27:45 -0500
| Newsgroups | gmane.text.xml.schema.devel |
|---|---|
| Message-ID | <[email protected]> |
--Apple-Mail=_9B1F095D-2173-44FD-AC13-E9B425D37CD5 Content-Type: multipart/alternative; boundary="Apple-Mail=_2619CA83-C0FE-459A-B469-173ABEC04C1E" --Apple-Mail=_2619CA83-C0FE-459A-B469-173ABEC04C1E Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii If you cannot use XSD 1.1, then I would recommend that you utilize = Schematron. https://www.xml.com/pub/a/2003/11/12/schematron.html = <https://www.xml.com/pub/a/2003/11/12/schematron.html> > On Feb 24, 2020, at 10:00 AM, Rajneesh Shukla = <[email protected]> wrote: >=20 > Hi Mukul, >=20 > One more help please: >=20 > Is it possible to impose required constraint at value level? > for example in below xml, I wnt to make sure value for alias1, coli1 = and operator is always populated in condition element within where = element. >=20 > functionalView name=3D"CLAIMS_FV" description=3D"Learning Purpose"> >=20 > <columns> >=20 > <column name=3D"CLAI.CODE" columnAlias=3D"CODE" = description=3D"The code of the claim" /> >=20 > <column name=3D"CLLI.CODE" columnAlias=3D"LINE_CODE" = description=3D"The code of the claim line" /> >=20 > <column name=3D"PROC.CODE" columnAlias=3D"PROC_CODE" = description=3D"The code of the claim line procedure" /> >=20 > </columns> >=20 > <fromviews> >=20 > <fromview name=3D"CLAIMS_V" alias=3D"CLAI" /> >=20 > <fromview name=3D"LINES_V" alias=3D"CLLI" /> >=20 > <fromview name=3D"PROC_V" alias=3D"PROC" /> >=20 > <fromview name=3D"PROV_V" alias=3D"PROV" /> >=20 > <fromview name=3D"FORMS_V" alias=3D"CLFO"/> >=20 > <fromview name=3D"FORMTYPES_V" alias=3D"CFTY"/> >=20 > </fromviews> >=20 > <joins> >=20 > <join alias1=3D"CLLI" col1=3D"CLAI_ID" condition=3D"=3D" = alias2=3D"CLAI" col2=3D"ID"/> >=20 > <join alias1=3D"CLFO" col1=3D"ID" condition=3D"=3D" = alias2=3D"CFTY" col2=3D"CLFO_ID"/> >=20 > <join alias1=3D"CFTY" col1=3D"ID" condition=3D"=3D" = alias2=3D"PROC" col2=3D"CFTY_ID"/> >=20 > <leftouterjoin alias1=3D"PROV" col1=3D"ID" condition=3D"=3D" = alias2=3D"CLAI" col2=3D"PROVIDER_ID"/> >=20 > </joins> >=20 > <where> >=20 > <condition alias1=3D"CFTY" col1=3D"CODE" operator=3D"=3D" = string=3D"" number=3D"" date=3D "" /> >=20 > </where> >=20 > </functionalView> >=20 > Thanks, > Rajneesh >=20 > On Mon, 24 Feb 2020 at 13:39, Rajneesh Shukla = <[email protected] <mailto:[email protected]>> wrote: > Hi Mukul, >=20 > Thanks for your reply. > I am working inside the database, it won't be possible. >=20 > Oracle XML DB only supports XML Schema 1.0. >=20 >=20 >=20 > Thanks, >=20 > Rajneesh >=20 >=20 > On Sat, 22 Feb 2020 at 11:27, Mukul Gandhi <[email protected] = <mailto:[email protected]>> wrote: > Hi Rajneesh, > Within the XSD document you've attached, following is a XSD issue = to start with (using Xerces-J 2.12.1 as XSD validator), >=20 > [Error] query1.xsd:3:67: s4s-att-not-allowed: Attribute 'maxOccurs' = cannot appear in element 'element'. > [Error] query1.xsd:3:67: s4s-att-not-allowed: Attribute 'minOccurs' = cannot appear in element 'element'. >=20 > i.e, the following is not allowed by XSD language, >=20 > <xs:schema attributeFormDefault=3D"unqualified" = elementFormDefault=3D"qualified" = xmlns:xs=3D"http://www.w3.org/2001/XMLSchema = <http://www.w3.org/2001/XMLSchema>"> >=20 > <xs:element name=3D"functionalView" maxOccurs=3D"1" minOccurs=3D"1">= > ... >=20 > </xs:schema> >=20 > Removing, maxOccurs=3D"1" minOccurs=3D"1" from above shown xs:element = declaration from your attached XSD document, makes your XSD document = correct (with both 1.0 and 1.1 versions of XSD language). >=20 > Now coming to your question. > I think that, the issue you've mentioned can be solved using an XSD = 1.1 <assert> instruction. I guess that, you can rewrite your XSD = fragment to following (I've only added an <assert>), to achieve what = you've mentioned, >=20 > <xs:element name=3D"where" maxOccurs=3D"1" minOccurs=3D"0"> > <xs:complexType> > <xs:sequence> > <xs:element name=3D"condition" = maxOccurs=3D"unbounded" minOccurs=3D"1"> > <xs:complexType> > <xs:simpleContent> > <xs:extension base=3D"xs:string"> > <xs:attribute = type=3D"xs:string" name=3D"alias1" use=3D"required"/> > <xs:attribute = type=3D"xs:string" name=3D"col1" use=3D"required"/> > <xs:attribute = type=3D"xs:string" name=3D"operator" use=3D"required"/> > <xs:attribute = type=3D"xs:string" name=3D"string" use=3D"optional"/> > <xs:attribute = type=3D"xs:string" name=3D"number" use=3D"optional"/> > <xs:attribute = type=3D"xs:string" name=3D"date" use=3D"optional"/> > <xs:assert = test=3D"exists(@string | @number | @date)"/> > </xs:extension> > </xs:simpleContent> > </xs:complexType> > </xs:element> > </xs:sequence> > </xs:complexType> > </xs:element> >=20 > I've not tested, the logic of <assert> I've mentioned above. >=20 > Could be useful information to share that, you may use the full XPath = 2.0 language, to write value of 'test' attribute of an <assert>. Also, 1 = upto any number of <assert> elements can be written as siblings in the = XSD document (all of the sibling <assert> elements, have to evaluate to = true for having the XML instance document valid). >=20 > On Fri, Feb 21, 2020 at 11:16 PM Rajneesh Shukla = <[email protected] <mailto:[email protected]>> wrote: > Hello All, >=20 > I am new to XSD and XML and need to explore if there is option to make = sure that any one attribute in a set of attributes within same element = is required. >=20 > Example: >=20 > <xs:element name=3D"where" maxOccurs=3D"1" minOccurs=3D"0"> > <xs:complexType> > <xs:sequence> > <xs:element name=3D"condition" maxOccurs=3D"unbounded" = minOccurs=3D"1"> > <xs:complexType> > <xs:simpleContent> > <xs:extension base=3D"xs:string"> > <xs:attribute type=3D"xs:string" name=3D"alias1" = use=3D"required"/> > <xs:attribute type=3D"xs:string" name=3D"col1" = use=3D"required"/> > <xs:attribute type=3D"xs:string" name=3D"operator"= use=3D"required"/> > <xs:attribute type=3D"xs:string" name=3D"string" = use=3D"optional"/> > <xs:attribute type=3D"xs:string" name=3D"number" = use=3D"optional"/> > <xs:attribute type=3D"xs:string" name=3D"date" = use=3D"optional"/> > </xs:extension> > </xs:simpleContent> > </xs:complexType> > </xs:element> > </xs:sequence> > </xs:complexType> > </xs:element> >=20 > Here I want to ensure that minimum one attribute in a set of 3 = attributes (mentioned as optional in above) are required. All can not be = optional , however any one (can be more than one also) is required. >=20 > Thanking you in anticipation !!! >=20 > Attachment: > Complete XSD file. >=20 >=20 >=20 > -- > Regards, > Mukul Gandhi --Apple-Mail=_2619CA83-C0FE-459A-B469-173ABEC04C1E Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii <html><head><meta http-equiv=3D"Content-Type" content=3D"text/html; = charset=3Dus-ascii"></head><body style=3D"word-wrap: break-word; = -webkit-nbsp-mode: space; line-break: after-white-space;" class=3D"">If = you cannot use XSD 1.1, then I would recommend that you utilize = Schematron.<div class=3D""><br class=3D""></div><div class=3D""><a = href=3D"https://www.xml.com/pub/a/2003/11/12/schematron.html" = class=3D"">https://www.xml.com/pub/a/2003/11/12/schematron.html</a><br = class=3D""><div><br class=3D""><blockquote type=3D"cite" class=3D""><div = class=3D"">On Feb 24, 2020, at 10:00 AM, Rajneesh Shukla <<a = href=3D"mailto:[email protected]" = class=3D"">[email protected]</a>> wrote:</div><br = class=3D"Apple-interchange-newline"><div class=3D""><div dir=3D"ltr" = class=3D""><div class=3D"">Hi Mukul,</div><div class=3D""><br = class=3D""></div><div class=3D"">One more help please:</div><div = class=3D""><br class=3D""></div><div class=3D"">Is it possible to impose = required constraint at value level?</div><div class=3D"">for example in = below xml, I wnt to make sure value for alias1, coli1 and operator is = always populated in condition element within where element.</div><div = class=3D""><br class=3D""></div><div class=3D"">functionalView = name=3D"CLAIMS_FV" description=3D"Learning Purpose"><br = class=3D""><br class=3D""> <columns><br class=3D""><br = class=3D""> <column name=3D"CLAI.CODE" = columnAlias=3D"CODE" description=3D"The code of the claim" = /><br class=3D""><br class=3D""> <column = name=3D"CLLI.CODE" columnAlias=3D"LINE_CODE" = description=3D"The code of the claim line" /><br class=3D""><br = class=3D""> <column name=3D"PROC.CODE" = columnAlias=3D"PROC_CODE" description=3D"The code of the claim = line procedure" /><br class=3D""><br class=3D""> = </columns><br class=3D""><br class=3D""> = <fromviews><br class=3D""><br class=3D""> = <fromview name=3D"CLAIMS_V" alias=3D"CLAI" /><br class=3D""><br = class=3D""> <fromview name=3D"LINES_V" alias=3D"CLLI" = /><br class=3D""><br class=3D""> <fromview = name=3D"PROC_V" alias=3D"PROC" /><br class=3D""><br class=3D""> = <fromview name=3D"PROV_V" alias=3D"PROV" /><br class=3D""><br= class=3D""> <fromview name=3D"FORMS_V" = alias=3D"CLFO"/><br class=3D""><br class=3D""> = <fromview name=3D"FORMTYPES_V" alias=3D"CFTY"/><br class=3D""><br = class=3D""> </fromviews><br class=3D""><br class=3D""> = <joins><br class=3D""><br class=3D""> <join = alias1=3D"CLLI" col1=3D"CLAI_ID" condition=3D"=3D" = alias2=3D"CLAI" col2=3D"ID"/><br class=3D""><br class=3D""> = <join alias1=3D"CLFO" col1=3D"ID" condition=3D"=3D" = alias2=3D"CFTY" col2=3D"CLFO_ID"/><br class=3D""><br = class=3D""> <join alias1=3D"CFTY" col1=3D"ID" = condition=3D"=3D" alias2=3D"PROC" col2=3D"CFTY_ID"/><br = class=3D""><br class=3D""> <leftouterjoin = alias1=3D"PROV" col1=3D"ID" condition=3D"=3D" alias2=3D"CLAI" = col2=3D"PROVIDER_ID"/><br class=3D""><br class=3D""> = </joins><br class=3D""><br class=3D""> <where><br = class=3D""><br class=3D""> <condition alias1=3D"CFTY" = col1=3D"CODE" operator=3D"=3D" string=3D"" number=3D"" = date=3D "" /><br class=3D""><br class=3D""> = </where><br class=3D""><br = class=3D""></functionalView></div><div class=3D""><br = class=3D""></div><div class=3D"">Thanks,</div><div class=3D"">Rajneesh<br = class=3D""></div></div><br class=3D""><div class=3D"gmail_quote"><div = dir=3D"ltr" class=3D"gmail_attr">On Mon, 24 Feb 2020 at 13:39, Rajneesh = Shukla <<a href=3D"mailto:[email protected]" = class=3D"">[email protected]</a>> wrote:<br = class=3D""></div><blockquote class=3D"gmail_quote" style=3D"margin:0px = 0px 0px 0.8ex;border-left:1px solid = rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr" class=3D""><div = class=3D"">Hi Mukul,</div><div class=3D""><br class=3D""></div><div = class=3D"">Thanks for your reply.</div><div class=3D""><p class=3D"">I = am working inside the database, it won't be possible.</p><p = class=3D"">Oracle XML DB only supports XML Schema 1.0.</p><p = class=3D""><br class=3D""></p><p class=3D"">Thanks,</p><p = class=3D"">Rajneesh<br class=3D""></p> </div></div><br class=3D""><div class=3D"gmail_quote"><div dir=3D"ltr" = class=3D"gmail_attr">On Sat, 22 Feb 2020 at 11:27, Mukul Gandhi <<a = href=3D"mailto:[email protected]" target=3D"_blank" = class=3D"">[email protected]</a>> wrote:<br = class=3D""></div><blockquote class=3D"gmail_quote" style=3D"margin:0px = 0px 0px 0.8ex;border-left:1px solid = rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr" class=3D""><div = dir=3D"ltr" class=3D"">Hi Rajneesh, <br class=3D""></div> = Within the XSD document you've attached, following is a XSD issue = to start with (using Xerces-J 2.12.1 as XSD validator),<br class=3D""><br = class=3D"">[Error] query1.xsd:3:67: s4s-att-not-allowed: Attribute = 'maxOccurs' cannot appear in element 'element'.<br class=3D"">[Error] = query1.xsd:3:67: s4s-att-not-allowed: Attribute 'minOccurs' cannot = appear in element 'element'.<br class=3D""><br class=3D"">i.e, the = following is not allowed by XSD language,<br class=3D""><br = class=3D""><xs:schema attributeFormDefault=3D"unqualified" = elementFormDefault=3D"qualified" xmlns:xs=3D"<a = href=3D"http://www.w3.org/2001/XMLSchema" target=3D"_blank" = class=3D"">http://www.w3.org/2001/XMLSchema</a>"><br class=3D""><br = class=3D""> <xs:element name=3D"functionalView" = maxOccurs=3D"1" minOccurs=3D"1"><br class=3D""> ...<br = class=3D""><br class=3D""></xs:schema><br class=3D""><br = class=3D"">Removing, maxOccurs=3D"1" minOccurs=3D"1" from above shown = xs:element declaration from your attached XSD document, makes your XSD = document correct (with both 1.0 and 1.1 versions of XSD language).<br = class=3D""><br class=3D"">Now coming to your question.<br class=3D"">I = think that, the issue you've mentioned can be solved using an XSD 1.1 = <assert> instruction. I guess that, you can rewrite your XSD = fragment to following (I've only added an <assert>), to achieve = what you've mentioned,<br class=3D""><br class=3D""><xs:element = name=3D"where" maxOccurs=3D"1" minOccurs=3D"0"><br class=3D""> = <xs:complexType><br class=3D""> = <xs:sequence><br class=3D""> = = <xs:element name=3D"condition" maxOccurs=3D"unbounded" = minOccurs=3D"1"><br class=3D""> = = <xs:complexType><br class=3D""> = = <xs:simpleContent><br class=3D""> = = <xs:extension = base=3D"xs:string"><br class=3D""> = = <xs:attribute = type=3D"xs:string" name=3D"alias1" use=3D"required"/><br = class=3D""> = = <xs:attribute type=3D"xs:string" = name=3D"col1" use=3D"required"/><br class=3D""> = = = <xs:attribute type=3D"xs:string" name=3D"operator" = use=3D"required"/><br class=3D""> = = <xs:attribute = type=3D"xs:string" name=3D"string" use=3D"optional"/><br = class=3D""> = = <xs:attribute type=3D"xs:string" = name=3D"number" use=3D"optional"/><br class=3D""> = = = <xs:attribute type=3D"xs:string" name=3D"date" use=3D"optional"/><br= class=3D""> = = <xs:assert test=3D"exists(@string | = @number | @date)"/><br class=3D""> = = </xs:extension><br class=3D""> = = </xs:simpleContent><br class=3D""> = = </xs:complexType><br class=3D""> = = </xs:element><br class=3D""> = </xs:sequence><br class=3D""> = </xs:complexType><div = class=3D""></xs:element></div><div class=3D""><br = class=3D""></div><div class=3D"">I've not tested, the logic of = <assert> I've mentioned above.</div><div class=3D""><br = class=3D""></div><div class=3D"">Could be useful information to share = that, you may use the full XPath 2.0 language, to write value of 'test' = attribute of an <assert>. Also, 1 upto any number of = <assert> elements can be written as siblings in the XSD document = (all of the sibling <assert> elements, have to evaluate to true = for having the XML instance document valid).</div><div class=3D""><br = class=3D""><div class=3D"gmail_quote"><div dir=3D"ltr" = class=3D"gmail_attr">On Fri, Feb 21, 2020 at 11:16 PM Rajneesh Shukla = <<a href=3D"mailto:[email protected]" target=3D"_blank" = class=3D"">[email protected]</a>> wrote:<br = class=3D""></div><blockquote class=3D"gmail_quote" style=3D"margin:0px = 0px 0px 0.8ex;border-left:1px solid = rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr" class=3D"">Hello = All,<br class=3D""><br class=3D"">I am new to XSD and XML and need to = explore if there is option to make sure that any one attribute in a set = of attributes within same element is required.<br class=3D""><br = class=3D"">Example:<br class=3D""><br class=3D""> <xs:element = name=3D"where" maxOccurs=3D"1" minOccurs=3D"0"><br class=3D""> = <xs:complexType><br class=3D""> = <xs:sequence><br = class=3D""> = <xs:element name=3D"condition" maxOccurs=3D"unbounded" = minOccurs=3D"1"><br class=3D""> = <xs:complexType><br class=3D""> = = <xs:simpleContent><br class=3D""> = <xs:extension = base=3D"xs:string"><br class=3D""> = <xs:attribute = type=3D"xs:string" name=3D"alias1" use=3D"required"/><br = class=3D""> = <xs:attribute type=3D"xs:string" name=3D"col1" = use=3D"required"/><br class=3D""> = <xs:attribute = type=3D"xs:string" name=3D"operator" use=3D"required"/><br = class=3D""> = <xs:attribute type=3D"xs:string" name=3D"string" = use=3D"optional"/><br class=3D""> = <xs:attribute = type=3D"xs:string" name=3D"number" use=3D"optional"/><br = class=3D""> = <xs:attribute type=3D"xs:string" name=3D"date" = use=3D"optional"/><br class=3D""> = </xs:extension><br = class=3D""> = </xs:simpleContent><br class=3D""> = </xs:complexType><br = class=3D""> = </xs:element><br class=3D""> = </xs:sequence><br class=3D""> = </xs:complexType><br class=3D""> = </xs:element><br class=3D""><br class=3D""><div class=3D"">Here I = want to ensure that minimum one attribute in a set of 3 = attributes (mentioned as optional in above) are required. All can not be = optional , however any one (can be more than one also) is = required.</div><div class=3D""><br class=3D""></div><div = class=3D"">Thanking you in anticipation !!!<br class=3D""></div><div = class=3D""><br class=3D""></div><div class=3D"">Attachment:</div><div = class=3D"">Complete XSD file.</div></div></blockquote><div = class=3D""> </div></div><br clear=3D"all" class=3D""><div = class=3D""><br class=3D""></div>-- <br class=3D""><div dir=3D"ltr" = class=3D""><div dir=3D"ltr" class=3D""><div dir=3D"ltr" class=3D""><div = dir=3D"ltr" class=3D""><div class=3D"">Regards,<br class=3D"">Mukul = Gandhi</div></div></div></div></div></div></div> </blockquote></div> </blockquote></div> </div></blockquote></div><br class=3D""></div></body></html>= --Apple-Mail=_2619CA83-C0FE-459A-B469-173ABEC04C1E-- --Apple-Mail=_9B1F095D-2173-44FD-AC13-E9B425D37CD5 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEw/EcbIGq7kaeGs37lrAunrDrhAUFAl5T63EACgkQlrAunrDr hAWVSA//bjHdFuhimLlH9hZoXWdEV8o+wTN5XcZ3O/q0zE5UddM5DBDoWKlz78my N2TKgok21VyAEFEgtCXGUa/kX1sO/JbMye+nkmcnuZ0Hsm6YCmoJOhXanZR7O6kG 1pZTQ7mq6X0HsMHnp4DsmJ5BphR4DySJafkIh7bFX63OGjo9BNv6pzAd4Ep6EPD6 W3vsTbDCwXTJUSRdBFbDhfiDTaWBOBElZh/+niqHOpCaM7jD9SMs6kpoOUwpCfHr lWK6YXOM8P00unBXDCBIDuKeY6P8BRta4Lj6WJ6aTUzIQmEQHQTouHB9ER3DF3Bh YNuu0GcpeC2znWnJFGtbyMnj66VbECx64tL81TLmepBN1MhCtzjht92K391fTOLV Se1CvKbh0JMKgmYZJ3ChfRp5/DMZLGwxbmiys/QHcj4qbl3JN7xgHfF3o1iaF0UB 6IeSqa0DUrkX2AQh7T8u//60JVTwJ2ZZqGQRnP1eMQu9sJ3WoGOAl3D4VUhenZKT Q4LDeBCwQuwA6fr0/6452X/P0f2UTh+g+smWiv507Iwl22gPmEM/TC4xhV+wqaty MdGc6X9XodGqU1JZtzyUgJBN2yTke/kO/GRbpUtE4cGoTwQdARGoONUdbrLroDJv B9QpqIJs/DNZbywjL7NgyvyOeVfsFp2gopCjA0h1H3LfKXPT8jw= =4Gh8 -----END PGP SIGNATURE----- --Apple-Mail=_9B1F095D-2173-44FD-AC13-E9B425D37CD5--