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

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.

Related

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.

Complex XPaths using EclipseLink MOXy and JAXB

I am currently using EclipseLink MOXy 2.4.1 and trying to update an element's value via XPaths.
The input used is :
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<expenseReport>
<user>
<userName>Sanaulla</userName>
</user>
<items>
<item>
<itemName>Seagate External HDD</itemName>
<purchasedOn>August 24, 2010</purchasedOn>
<amount>6776.5</amount>
</item>
<item>
<itemName>External HDD</itemName>
<purchasedOn>August 24, 2010</purchasedOn>
<amount>677336.5</amount>
</item>
</items>
</expenseReport>
The XSD is
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="expenseReport" type="ExpenseT"/>
<xs:complexType name="ExpenseT">
<xs:sequence>
<xs:element name="user" type="UserT"/>
<xs:element name="items" type="ItemListT"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="UserT">
<xs:sequence>
<xs:element name="userName" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="ItemListT">
<xs:sequence>
<xs:element name="item" type="ItemT" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="ItemT">
<xs:sequence>
<xs:element name="itemName" type="xs:string"/>
<xs:element name="purchasedOn" type="xs:string"/>
<xs:element name="amount" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
And my Java code is :
JAXBContext context = JAXBContext.newInstance("sample.jaxb.xsd");
JAXBElement<ExpenseT> element = (JAXBElement<ExpenseT>)unmarshaller.unmarshal(new File("resources/sample_before.xml"));
ExpenseT expenseReport = element.getValue();
context.setValueByXPath(expenseReport, "items/item[1]/amount/text()", null, "100.11");
/** Marshalling code **/
I have my java classes created from the XSD using Moxy's tool "jaxb-compiler.cmd".
As you can see from the above code, I am trying to set the amount of 1st item to "100.11". But it doesn't set the value, nor does it throw any exception.
I tried setting the username above using XPath like this
context.setValueByXPath(expenseReport, "user/userName/text()", null, "ABC");
And, it does set/update the value properly.
Can you please advise on how can I set values for complex XPaths with Predicates? Something like this :
items/item[itemName='Seagate External HDD']/amount
We recently fixed a bug in our EclipseLink 2.4.2 and 2.5.0 streams related to setting values in which the XPath contains a postional indicator (ie "foo[1]/bar[2]/text()"). You can download a nightly build from the following link:
http://www.eclipse.org/eclipselink/downloads/nightly.php
You can use predicates in mappings with #XmlPath (see: http://blog.bdoughan.com/2011/03/map-to-element-based-on-attribute-value.html), but we currently don't supports this with our setValueByXPath call. Could you open an enhancement

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>

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

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.

BizTalk generated XSD fails to validate the XML its derived from

I've got an XML response from another system, but no XSD, so I used the Create Schema option to generate one.
I then added the XSD to my BizTalk 2006 R2 project and set its "Input Instance Filename" property to the original XML message.
Tried the "Validate Instance" option and it FAILS ???, with a couple of errors like so ...
error BEC2004: The xsi:type attribute value 'http://www.w3.org/2001/XMLSchema:int' is not valid for the element 'http://www.aniteps.com/xml/schemas/awm/images4:NumberOfErrors', either because it is not a type validly derived from the type in the schema, or because it has xsi:type derivation blocked.
How the heck can the XML fail that was used to generate the XSD ?
The XML example I have is ...
<?xml version="1.0" encoding="utf-8"?>
<ImportIndexDocumentResponse
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.aniteps.com/xml/schemas/awm/images4">
<HasErrors>false</HasErrors>
<NumberOfErrors xsi:type="xsd:int">0</NumberOfErrors>
<ErrorDescription xsi:type="xsd:string">No exception ocurred.</ErrorDescription>
<ErrorNumber xsi:type="xsd:int">0</ErrorNumber>
<FailedItems>
<Item>
<OriginalDataString xsi:type="xsd:string" />
<ErrorDescription xsi:type="xsd:string" />
</Item>
</FailedItems>
<UniqueDocumentReferences>
<UniqueDocumentReference>FA40FE</UniqueDocumentReference>
<UniqueDocumentReference>U55922</UniqueDocumentReference>
</UniqueDocumentReferences>
</ImportIndexDocumentResponse>
And BizTalk / Visual Studio 2005 generates ...
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
attributeFormDefault="unqualified"
elementFormDefault="qualified"
targetNamespace="http://www.aniteps.com/xml/schemas/awm/images4">
<xs:element name="ImportIndexDocumentResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="HasErrors" type="xs:boolean" />
<xs:element name="NumberOfErrors" type="xs:unsignedByte" />
<xs:element name="ErrorDescription" type="xs:string" />
<xs:element name="ErrorNumber" type="xs:unsignedByte" />
<xs:element name="FailedItems">
<xs:complexType>
<xs:sequence>
<xs:element name="Item">
<xs:complexType>
<xs:sequence>
<xs:element name="OriginalDataString" />
<xs:element name="ErrorDescription" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="UniqueDocumentReferences">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="UniqueDocumentReference" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xsd:schema>
The XSD generator is reasonably dumb, and didn't notice that the sample instance document contained type annotations (xsi:type attributes). So it decided that <ErrorDescription> should contain unsigned bytes and not signed integers, as the type annotation said.
What happens then is that the validator becomes confused because there are two distinct type definitions for the element, so who should it believe? You could try changing the schema so that the type definitions match the xsi:type overrides, that may help a bit.

Resources