XSD a node with a choice must exist with a specific type of node chosen - validation

So I have the following xsd types
<xs:complexType name="nodeType">
<xs:sequence>
<xs:choice>
<xs:element name="c0" type="c0type"/>
<xs:element name="c1" type="c1type"/>
<xs:element name="c2" type="c2type"/>
<xs:element name="c3" type="c3type"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element name="nodes">
<xs:complexType>
<xs:sequence>
<xs:element name="node" type="nodeType" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
now the problem I face is that I need the 'node' element to exist at least once within the 'root' element and with the selected element of type 'c0type'.
any number of combinations of <node><c0 /></node>...<node><c3 /></node> can occur but at least 1 <node><c0 /><node> must exist
Is it possible to achieve this validation through xsd?

It is not possible using XSD 1.0.

Related

Where is the schema of `child-resources` specified?

I'm trying to find where the schema of the result of a child-resources query is specified in the xsd. It's clearly not a primitiveContent (specified in responsePrimitive) because that doesn't contain the named child-resources arrays.
I think this is in the CDT-responsePrimitive-v.xsd file. In Resourcewrapper you have "m2m:sg_regularResource":
<xs:complexType name="resourceWrapper">
<xs:sequence>
<xs:choice minOccurs="1" maxOccurs="1">
...
<xs:element ref="m2m:sg_regularResource" />
...
</xs:choice>
<xs:element name="URI" type="xs:anyURI" />
</xs:sequence>
</xs:complexType>
In any of the resources that is a "m2m:sg_regularResource" you can find a section like this that allows for "included" child resources:
...
<!-- Child Resources -->
<xs:choice minOccurs="0" maxOccurs="1">
<xs:element name="childResource" type="m2m:childResourceRef" minOccurs="1" maxOccurs="unbounded" />
<xs:choice minOccurs="1" maxOccurs="unbounded">
<xs:element ref="m2m:aResourceType" />
<xs:element ref="m2m:anotherResourceType" />
</xs:choice>
</xs:choice>
...

What is the meaning of '/' in following TIBCO expression

I have following code in Tibco business works module
$ES_GetInfo/root/pfx4:GetInformationAndPropertyDetailsResponse/pfx4:LicenseInfo/pfx4:CoreEnt/pfx4:Ent
[pfx4:Ent/pfx4:EntOfferingCode = $Read_DB_Data/group/ROW/EOC]
/pfx4:EntState = "Disabled"
I can understand it is comparing "EntOfferingCode" with "EOC", but could not get the expression "/pfx4:EntState = 'Disabled'"?
As per the TIBCO, the whole expression returns a boolean value.
What is the meaning of "/pfx4:entState='Disabled'". Is logical or conditional or something else?
The whole expression is logical condition. The '/' is just xml schema elements separator in XPath (XML Path Language) syntax. You can start learning tibco xpath from here https://docs.tibco.com/pub/activematrix_businessworks/6.3.0/doc/html/GUID-D319018B-AA74-428D-A034-E477778AD2B6.html
The expression first filtering all the "Ent" nodes that have EntOfferingCode = $Read_DB_Data/group/ROW/EOC
then check if exists EntState = "Disabled" in filtered result
the expression can be replaced by
not (empty($Start/pfx:GetInformationAndPropertyDetailsResponse/pfx:LicenseInfo/pfx:CoreEnt/pfx:Ent[ pfx:EntOfferingCode= "EOC" and pfx:EntState = "Disabled"]))
For example
if the schema is like
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.tibco.com/schemas/TestProcess/Schema/Schema.xsd"
targetNamespace="http://www.tibco.com/schemas/TestProcess/Schema/Schema.xsd"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:element name="GetInformationAndPropertyDetailsResponse">
<xs:complexType>
<xs:sequence>
<xs:element ref="LicenseInfo" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="LicenseInfo">
<xs:complexType>
<xs:sequence>
<xs:element ref="CoreEnt" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="CoreEnt">
<xs:complexType>
<xs:sequence>
<xs:element ref="Ent" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Ent">
<xs:complexType>
<xs:sequence>
<xs:element name="EntOfferingCode" type="xs:string"/>
<xs:element name="EntState" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Expression return true for:
<?xml version = "1.0" encoding = "UTF-8"?>
<GetInformationAndPropertyDetailsResponse xmlns = "http://www.tibco.com/schemas/TestProcess/Schema/Schema.xsd">
<LicenseInfo>
<CoreEnt>
<Ent>
<EntOfferingCode>EOC</EntOfferingCode>
<EntState>Disabled</EntState>
</Ent>
</CoreEnt>
</LicenseInfo>
</GetInformationAndPropertyDetailsResponse>
Expression return false for:
<?xml version = "1.0" encoding = "UTF-8"?>
<GetInformationAndPropertyDetailsResponse xmlns = "http://www.tibco.com/schemas/TestProcess/Schema/Schema.xsd">
<LicenseInfo>
<CoreEnt>
<Ent>
<EntOfferingCode>EOC</EntOfferingCode>
<EntState>Enabled</EntState>
</Ent>
<Ent>
<EntOfferingCode>EOC1</EntOfferingCode>
<EntState>Disabled</EntState>
</Ent>
</CoreEnt>
</LicenseInfo>
</GetInformationAndPropertyDetailsResponse>
if you just use
$ES_GetInfo/root/pfx4:GetInformationAndPropertyDetailsResponse/pfx4:LicenseInfo/pfx4:CoreEnt/pfx4:Ent/pfx4:EntState = "Disabled"
it will return true for both examples
If your question is what does the xslt expression mean, it is basically checking the following:
For all LicenseInfo/CoreEnt/Ent,
where Ent/EntOfferingCode = EOC value from the DB
check if the corresponding Enstate is Disabled or not
if Disabled, output true, else output false.

XSD for auto closing tag in complexType

I have this in my XML file:
<rooms>
<room id="1" beds="1" windows="0"/>
<room id="2" beds="2" windows="0"/>
</rooms>
And this in my XSD file:
<xs:complexType name="Rooms">
<xs:sequence>
<xs:element name="room" type="Room"/>
</xs:sequence>
<xs:attribute name="count" type="xs:integer"/>
</xs:complexType>
<xs:complexType name="Room">
<xs:attribute name="id" type="xs:integer"/>
<xs:attribute name="beds" type="xs:integer"/>
<xs:attribute name="windows" type="xs:integer"/>
</xs:complexType>
But I got this error : Element 'room': This element is not expected.
When I put <room id="1" beds="1" windows="0"></room> I don't have the error anymore and if I have only one room I don't have the error, so it's basically because of the auto closing tag.
How can I fix this?
Try specifying values for minOccurs and maxOccurs to your room element inside the sequence. I think the default expected number of occurrences is 1. Something like:
<xs:sequence>
<xs:element name="room" type="Room" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>

Fully Qualified Xpath returns null

<Trial1Response xmlns="http://schemas.microsoft.com/Sql/2008/05/Procedures/dbo">
<Trial1Result>
<DataSet xmlns="http://schemas.datacontract.org/2004/07/System.Data">
<xs:schema id="NewDataSet" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element msdata:IsDataSet="true" name="NewDataSet">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="NewTable">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="cust_id" type="xs:int">
</xs:element>
<xs:element minOccurs="0" name="fname" type="xs:string">
</xs:element>
<xs:element minOccurs="0" name="lname" type="xs:string">
</xs:element>
<xs:element minOccurs="0" name="addr" type="xs:string">
</xs:element>
<xs:element minOccurs="0" name="city" type="xs:string">
</xs:element>
<xs:element minOccurs="0" name="order_id" type="xs:int">
</xs:element>
<xs:element minOccurs="0" name="amount" type="xs:int">
</xs:element>
<xs:element minOccurs="0" name="particulars" type="xs:string">
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<NewDataSet xmlns="">
<NewTable><cust_id>1</cust_id><fname>Akshay</fname><lname>Jain</lname><addr>Borivali</addr><city>Mumbai</city><order_id>221</order_id><amount>41</amount><particulars>Item B</particulars>
</NewTable>
<NewTable><id>223</id><Akshay1id>682</Akshay1id><amount>345</amount><particulars>Item A</particulars>
</NewTable>
</NewDataSet>
</diffgr:diffgram>
</DataSet>
</Trial1Result>
<ReturnValue>0</ReturnValue>
</Trial1Response>
I want to extract the data between the tags NewDataSet. For this, I am using the following Xpath:
/*[local-name="Trial1Response" and namespace-uri()="http://schemas.microsoft.com/Sql/2008/05/Procedures/dbo"]/*[local-name="Trial1Result" and namespace-uri()="http://schemas.microsoft.com/Sql/2008/05/Procedures/dbo"]/*[local-name="DataSet" and namespace-uri()="http://schemas.datacontract.org/2004/07/System.Data"]/*[local-name="diffgr:diffgram" and namespace-uri()="urn:schemas-microsoft-com:xml-diffgram-v1"]/*[local-name="NewDataSet" and namespace-uri()=""]
I get null as my result. What am I doing wrong?
I am expected to use the fully qualified Xpath because Logic apps do not work without it
Edit: I have edited the XML after comments
Correct your xml.
And change local-name to local-name()
like this
/*[local-name()="Trial1Response" and namespace-uri()="http://schemas.microsoft.com/Sql/2008/05/Procedures/dbo"]/*[local-name()="Trial1Result" and namespace-uri()="http://schemas.microsoft.com/Sql/2008/05/Procedures/dbo"]/*[local-name()="DataSet" and namespace-uri()="http://schemas.datacontract.org/2004/07/System.Data"]/*[local-name()="diffgram" and namespace-uri()="urn:schemas-microsoft-com:xml-diffgram-v1"]/*[local-name()="NewDataSet" and namespace-uri()=""]
note: no need of using namespace-uri() if you have single/unique elements in the xml.

XSD context-dependent types; wrapper types

I am writing a schema for XML documents like this:
<workbook>
<worksheet>
<column/>
</worksheet>
</workbook>
Where each node can be wrapped into the env element (e.g.)
<workbook>
<env>
<worksheet>
<column/>
</worksheet>
</env>
</workbook>
or
<workbook>
<worksheet>
<env>
<column/>
</env>
</worksheet>
</workbook>
So, depending on the location of the env element, it can have different children (env-child of workbook must have worksheet children and env-child of worksheet must have column children)
When I am declaring env elements as nested, I get multiply-defined element errors.
How could I write xsd for such document, or is it at all possible?
Thanks in advance!
Yes, it is possible, because you can have elements with the same name env but with different types (structure) in different places - something linke this:
<xs:element name="workbook">
<xs:complexType>
<xs:choice>
<xs:element name="env">
<xs:complexType>
<xs:sequence>
<xs:element ref="worksheet"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element ref="worksheet"/>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="worksheet">
<xs:complexType>
<xs:choice>
<xs:element name="env">
<xs:complexType>
<xs:sequence>
<xs:element ref="column"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element ref="column"/>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="column" type="xs:string">
</xs:element>

Resources