Is it possible to concatenate two nodes variables using Bash ?
i'm trying to contacted this 4 variables
To have something like "5216997, Yes, Mark, Request"
IncidentId="$(echo "cat /incidents/incident/id/text()" | xmllint --nocdata --shell ~/Desktop/Chicago.csv | sed '1d;$d')"
is_customer_satisfied="$(echo "cat /incidents/incident/is_customer_satisfied/text()" | xmllint --nocdata --shell ~/Desktop/Chicago.csv | sed '1d;$d')"
requester="$(echo "cat /incidents/incident/requester/name/text()" | xmllint --nocdata --shell ~/Desktop/Chicago.csv | sed '1d;$d')"
category="$(echo "cat /incidents/incident/category/name/text()" | xmllint --nocdata --shell ~/Desktop/Chicago.csv | sed '1d;$d')"
BUT i do have this :
5216172 ------- 5215298 | ------- Yes ------- Yes | ------- Mark ------- Luc | ------- Request ------- Request
OR is this a better way to do, what i'm looking for ?
And the csv file content xml values :
> <?xml version="1.0" encoding="UTF-8"?>
<incidents>
<incident>
<id>5237425</id>
<number>5101</number>
<name>Google Mail Password Reset</name>
<description></description>
<description_no_html></description_no_html>
<state>Closed</state>
<priority>Low</priority>
<category>
<id>371032</id>
<name>Software</name>
<default_tags>Software</default_tags>
<children>
<child>
<id>505786</id>
<name>Accounts</name>
<default_tags>Google, google, gmail, AppleId, appleid, Uniflow, </default_tags>
<children nil="true"/>
<parent_id>371032</parent_id>
<default_assignee_id>-1</default_assignee_id>
</child>
<child>
<id>371040</id>
<name>Email/Outlook</name>
<default_tags>Mail/Outlook, Email, Outlook</default_tags>
<children nil="true"/>
<parent_id>371032</parent_id>
<default_assignee_id>-1</default_assignee_id>
</child>
<child>
<id>423866</id>
<name>iOS</name>
<default_tags>iOS</default_tags>
<children nil="true"/>
<parent_id>371032</parent_id>
<default_assignee_id>-1</default_assignee_id>
</child>
<child>
<id>371044</id>
<name>macOS</name>
<default_tags>macOS</default_tags>
<children nil="true"/>
<parent_id>371032</parent_id>
<default_assignee_id>-1</default_assignee_id>
</child>
<child>
<id>371043</id>
<name>MS office (Word, Excel,...)</name>
<default_tags>MS office, Word, Excel, Access</default_tags>
<children nil="true"/>
<parent_id>371032</parent_id>
<default_assignee_id>-1</default_assignee_id>
</child>
<child>
<id>371047</id>
<name>Other Software</name>
<default_tags>Other Software</default_tags>
<children nil="true"/>
<parent_id>371032</parent_id>
<default_assignee_id>-1</default_assignee_id>
</child>
<child>
<id>371046</id>
<name>Windows</name>
<default_tags>Windows</default_tags>
<children nil="true"/>
<parent_id>371032</parent_id>
<default_assignee_id>-1</default_assignee_id>
</child>
</children>
<parent_id nil="true"/>
<default_assignee_id>-1</default_assignee_id>
</category>
<subcategory>
<id>371040</id>
<name>Email/Outlook</name>
<default_tags>Mail/Outlook, Email, Outlook</default_tags>
<children nil="true"/>
<parent_id>371032</parent_id>
<default_assignee_id>-1</default_assignee_id>
</subcategory>
<assignee>
<group_id>1518184</group_id>
<is_user>true</is_user>
<id>1323154</id>
<name>Mark</name>
<disabled>false</disabled>
<title>IT Support Administrator</title>
<created_at>2017-01-30T16:06:46+01:00</created_at>
<last_login>2018-03-01T09:23:45+01:00</last_login>
<phone> 22</phone>
<mobile_phone> 36</mobile_phone>
<department>
<id>20501</id>
<name>IT</name>
<description>IT Team</description>
<default_assignee_id>-1</default_assignee_id>
</department>
<role>
<id>233084</id>
<name>IT support</name>
<description></description>
<portal>false</portal>
<show_my_tasks>false</show_my_tasks>
</role>
<salt>0ec80dd90d499c4e80307fd8128f6e267717ae9b</salt>
<group_ids>
<group_id>1518184</group_id>
<group_id>1499663</group_id>
<group_id>1539645</group_id>
</group_ids>
<custom_fields_values/>
<avatar>
<type>initials</type>
<color>#0bc46f</color>
<initials>ML</initials>
</avatar>
<mfa_enabled>false</mfa_enabled>
<reports_to>
<group_id>1500982</group_id>
<is_user>true</is_user>
<id>1308247</id>
<name>Stéphane</name>
<disabled>false</disabled>
<title>IT Support</title>
<email>user#test.com</email>
<created_at>2016-10-21T09:55:42+02:00</created_at>
<last_login>2018-05-28T08:04:33+02:00</last_login>
<phone> 47 95</phone>
<mobile_phone>+41 14 24</mobile_phone>
<department>
<id>20501</id>
<name>IT</name>
<description>IT Team</description>
<default_assignee_id>-1</default_assignee_id>
</department>
<role>
<id>225674</id>
<name>Administrator</name>
<description>This is the all powerful administrator user!</description>
<portal>false</portal>
<show_my_tasks>false</show_my_tasks>
</role>
<salt>bde321c1b90d43d1af1b12140ad2528cadc69672</salt>
<group_ids>
<group_id>1500982</group_id>
</group_ids>
<custom_fields_values/>
<avatar>
<type>image</type>
<image_class>avatar_image</image_class>
<sso_image_class></sso_image_class>
<avatar_url></avatar_url>
</avatar>
<mfa_enabled>false</mfa_enabled>
<site>
<id>23927</id>
<name>IT</name>
<location>London</location>
<description>London</description>
<time_zone>Bern</time_zone>
<language>-1</language>
<business_record>
<id>28860</id>
<name>Default Business Hours</name>
<description>This is your initial business hours record</description>
</business_record>
</site>
</reports_to>
<site>
<id>23926</id>
<name>London</name>
<location>london</location>
<description>London</description>
<time_zone>Bern</time_zone>
<language>-1</language>
<business_record>
<id>28860</id>
<name>Default Business Hours</name>
<description>This is your initial business hours record</description>
</business_record>
</site>
</assignee>
<requester>
<id>1157306</id>
<account_id>34933</account_id>
<user_id>1393446</user_id>
<email>user#london.com</email>
<name>Student - Leysin</name>
<disabled>false</disabled>
<has_gravatar>false</has_gravatar>
<customer_satisfaction_survey_time>2018-06-08T15:01:57+02:00</customer_satisfaction_survey_time>
<avatar>
<type>initials</type>
<color>#bb5bac</color>
<initials>SL</initials>
</avatar>
</requester>
<created_at>2018-06-26T11:12:32+02:00</created_at>
<updated_at>2018-06-26T11:12:32+02:00</updated_at>
<due_at nil="true"/>
<sla_violations/>
<number_of_comments>0</number_of_comments>
<user_saw_all_comments>true</user_saw_all_comments>
<is_service_request>false</is_service_request>
<created_by>
<id>1089626</id>
<account_id>34933</account_id>
<user_id>1323154</user_id>
<email>user#test.com</email>
<name>Mark</name>
<disabled>false</disabled>
<has_gravatar>false</has_gravatar>
<customer_satisfaction_survey_time>2018-06-27T11:10:20+02:00</customer_satisfaction_survey_time>
<avatar>
<type>initials</type>
<color>#0bc46f</color>
<initials>ML</initials>
</avatar>
</created_by>
<custom nil="true"/>
<href>https://website.com/incidents/5237425-reset.xml</href>
<site>
<id>23926</id>
<name>London</name>
<location>London</location>
<description>London</description>
<time_zone>Bern</time_zone>
<language>-1</language>
<business_record>
<id>28860</id>
<name>Default Business Hours</name>
<description>This is your initial business hours record</description>
</business_record>
</site>
<department>
<id>26020</id>
<name>Students</name>
<description>Students</description>
<default_assignee_id>-1</default_assignee_id>
</department>
<cc/>
<custom_fields_values/>
<comments/>
<attachments/>
<statistics>
<statistic>
<statistic_type>State Changed</statistic_type>
<time>00:01</time>
<time_elapsed>00:01</time_elapsed>
<business_time_elapsed>00:01</business_time_elapsed>
<value>2018-06-26 09:12:32 UTC</value>
</statistic>
<statistic>
<statistic_type>first_touch_resolution</statistic_type>
<time nil="true"/>
<time_elapsed nil="true"/>
<business_time_elapsed nil="true"/>
<value>t</value>
</statistic>
</statistics>
<tags>
<tag>
<id>299260</id>
<name>software</name>
<taggings_count>9349</taggings_count>
</tag>
</incident>
</incidents>
I used xmlstarlet and it works better
Related
*
This API used to insert DB.
When I request for this ESB API response 202 accepted,but I need 200
I didn't set asynchronous request.Please excuse my poor English.Do I make myself clear?Thanks.
*
<api xmlns="http://ws.apache.org/ns/synapse" name="xxxxxx" context="/xxxxxxx">
<resource methods="POST" url-mapping="/xxxxxx">
<inSequence>
<property name="requestMsg" expression="json-eval($)"/>
<property name="children" expression="json-eval($.children)"/>
<property name="messageType" value="application/json" scope="axis2" type="STRING"></property>
<dbreport>
<connection>
<pool>
<driver>oracle.jdbc.OracleDriver</driver>
<url>jdbc:oracle:thin:#xxxxxxxxxx:1521/xxxxxx</url>
<user>xxxxxx</user>
<password>xxxxxx</password>
</pool>
</connection>
<statement>
<sql>INSERT INTO TABLE (CARDID )VALUES(?)</sql>
<parameter expression="//CARDID/text()" type="CHAR"/>
</statement>
</dbreport>
<foreach id="foreach_1" expression="//children">
<sequence>
<property name="PKID" expression="json-eval($.children.PKID)"/>
<dbreport>
<connection>
<pool>
<driver>oracle.jdbc.OracleDriver</driver>
<url>jdbc:oracle:thin:#xxxxxxxxxxxxxx/xxxxxx</url>
<user>xxxxxx</user>
<password>xxxxxx</password>
</pool>
</connection>
<statement>
<sql>INSERT INTO TABLE_1 ( PKID )VALUES ( ? )</sql>
<parameter expression="//PKID/text()" type="VARCHAR"/>
</statement>
</dbreport>
</sequence>
</foreach>
<respond/>
</inSequence>
</resource>
</api>
I've been trying to figure out how to get WSO2's ESB to make calls to two different APIs and combine their results into a single response, and running into nothing but trouble. At its most basic, I've got two backends I'm making requests to that respond something like this:
http://example.com/items:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<response xmlns="http://example.com/response">
<query name="items" xmlns="http://example.com/query">
<row>
<id>1</id>
<name>Item 1</name>
</row>
<row>
<id>2</id>
<name>Item 2</name>
</row>
</query>
</response>
</soapenv:Body>
</soapenv:Envelope>
http://example.com/parts:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<response xmlns="http://example.com/response">
<query name="parts" xmlns="http://example.com/query">
<row>
<id>1</id>
<part>Part 1.1</part>
</row>
<row>
<id>1</id>
<part>Part 1.2</part>
</row>
<row>
<id>1</id>
<part>Part 1.3</part>
</row>
<row>
<id>2</id>
<part>Part 2.1</part>
</row>
<row>
<id>2</id>
<part>Part 2.2</part>
</row>
</query>
</response>
</soapenv:Body>
</soapenv:Envelope>
I'd like to request both of those, then combine their results to look something like this:
<items>
<item>
<id>1</id>
<name>Item 1</name>
<parts>
<part>
<id>1</id>
<name>Part 1.1</name>
</part>
<part>
<id>1</id>
<name>Part 1.2</name>
</part>
<part>
<id>1</id>
<name>Part 1.3</name>
</part>
</parts>
</item>
<item>
<id>2</id>
<name>Item 2</name>
<parts>
<part>
<id>2</id>
<name>Part 2.1</name>
</part>
<part>
<id>2</id>
<name>Part 2.2</name>
</part>
</parts>
</item>
</items>
Basically, every response from both APIs has a list of rows, each of which contains an id element. The ids in the call to /items are unique within that response, and each row in the response from parts has an id that ties it to a row from /items.
I've got the following API definition in the ESB:
<?xml version="1.0" encoding="UTF-8"?>
<api context="/item_list" name="ItemList" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST" uri-template="/">
<inSequence>
<header name="Content-Type" scope="transport" value="text/xml; charset=utf-8"/>
<clone>
<target>
<sequence>
<send>
<endpoint>
<address format="soap11" uri="http://example.com/items"/>
</endpoint>
</send>
</sequence>
</target>
<target>
<sequence>
<send>
<endpoint>
<address format="soap11" uri="http://example.com/parts"/>
</endpoint>
</send>
</sequence>
</target>
</clone>
</inSequence>
<outSequence>
<aggregate>
<correlateOn expression="//*[name()='response']/*[name()='query']/*[name()='row']/*[name()='id']" />
<completeCondition>
<messageCount max="2" min="2"/>
</completeCondition>
<onComplete expression="//*[name()='response']/*[name()='query']/*[name()='row']">
<send/>
</onComplete>
</aggregate>
</outSequence>
<faultSequence/>
</resource>
</api>
The inSequence here is heavily simplified, but it does send two valid queries and gets back the expected responses. The outSequence as it's written here never sends a response to the client or logs an error on the server. If I remove the correlateOn element from aggregate, I get back a single row, seemingly at random, from one of the two API calls. I think correlateOn is something I want to be using here, but I can't find any useful documentation on it from either WSO2 or Apache, so I'm sure I'm using it incorrectly. My XPath background is pretty weak, so I'm sure that expression could also use some work.
Am I at least on the right track here with the clone/aggregate pattern? How would I go about combining the results from these two queries into something similar to my example? If I can get something even sort of close, I should be able to do the rest with XSLT.
take a look at this demo:
Backend 1 with the items response:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="items"
transports="https http"
startOnLoad="true">
<target>
<inSequence>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<response xmlns="http://example.com/response">
<query xmlns="http://example.com/query" name="items">
<row>
<id>1</id>
<name>Item 1</name>
</row>
<row>
<id>2</id>
<name>Item 2</name>
</row>
</query>
</response>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args/>
</payloadFactory>
<log level="full"/>
<loopback/>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
</target>
</proxy>
Backend 2 with the parts response:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="parts"
transports="https http"
startOnLoad="true">
<target>
<inSequence>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<response xmlns="http://example.com/response">
<query xmlns="http://example.com/query" name="parts">
<row>
<id>1</id>
<part>Part 1.1</part>
</row>
<row>
<id>1</id>
<part>Part 1.2</part>
</row>
<row>
<id>1</id>
<part>Part 1.3</part>
</row>
<row>
<id>2</id>
<part>Part 2.1</part>
</row>
<row>
<id>2</id>
<part>Part 2.2</part>
</row>
</query>
</response>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args/>
</payloadFactory>
<log level="full"/>
<loopback/>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
</target>
</proxy>
My API calling backend 1 and backend 2 and transforming with xslt:
<?xml version="1.0" encoding="UTF-8"?>
<api xmlns="http://ws.apache.org/ns/synapse"
name="ItemList"
context="/item_list">
<resource methods="POST" uri-template="/">
<inSequence>
<header name="Action" scope="default" value="urn:mediate"/>
<call>
<endpoint>
<address uri="http://localhost:8283/services/items.itemsHttpSoap11Endpoint"
format="soap11"/>
</endpoint>
</call>
<enrich>
<source type="inline" clone="true">
<Payloads/>
</source>
<target type="property" property="Items"/>
</enrich>
<enrich>
<source clone="true" xpath="$body/*"/>
<target action="child" xpath="$ctx:Items"/>
</enrich>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body/>
</soapenv:Envelope>
</format>
<args/>
</payloadFactory>
<call>
<endpoint>
<address uri="http://localhost:8283/services/parts.partsHttpSoap11Endpoint"
format="soap11"/>
</endpoint>
</call>
<enrich>
<source clone="true" xpath="$body/*[name()='response']/*[name()='query']"/>
<target type="property" property="Parts"/>
</enrich>
<enrich>
<source type="property" clone="true" property="Parts"/>
<target action="child" xpath="$ctx:Items"/>
</enrich>
<enrich>
<source type="property" property="Items"/>
<target type="body"/>
</enrich>
<xslt key="transformTwoSourcesToOneResult"/>
<loopback/>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
</resource>
</api>
And my xslt transformation:
<?xml version="1.0" encoding="UTF-8"?>
<localEntry key="transformTwoSourcesToOneResult" xmlns="http://ws.apache.org/ns/synapse">
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns0="http://example.com/query"
xmlns:ns1="http://example.com/response"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:exslt="http://exslt.org/common"
xmlns:saxon="http://saxon.sf.net/"
xmlns:syn="http://ws.apache.org/ns/synapse"
exclude-result-prefixes="ns0 ns1 xs">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:variable name="var1_instance_Payloads" select="."/>
<items>
<xsl:for-each select="$var1_instance_Payloads/syn:Payloads">
<xsl:variable name="var2_Payloads" select="."/>
<xsl:for-each select="$var2_Payloads/ns1:response/ns0:query/ns0:row">
<xsl:variable name="var2_row" select="."/>
<item>
<id>
<xsl:value-of select="number(string($var2_row/ns0:id))"/>
</id>
<name>
<xsl:value-of select="string($var2_row/ns0:name)"/>
</name>
<parts>
<xsl:for-each select="$var2_Payloads/ns0:query/ns0:row">
<xsl:variable name="var4_row" select="."/>
<xsl:if test="string((number(string($var2_row/ns0:id)) = number(string($var4_row/ns0:id)))) != 'false'">
<part>
<id>
<xsl:value-of select="number(string($var4_row/ns0:id))"/>
</id>
<name>
<xsl:value-of select="string($var4_row/ns0:part)"/>
</name>
</part>
</xsl:if>
</xsl:for-each>
</parts>
</item>
</xsl:for-each>
</xsl:for-each>
</items>
</xsl:template>
</xsl:stylesheet>
</localEntry>
The API response:
<items xmlns="http://ws.apache.org/ns/synapse" xmlns:syn="http://ws.apache.org/ns/synapse" xmlns:saxon="http://saxon.sf.net/" xmlns:exslt="http://exslt.org/common">
<item>
<id>1</id>
<name>Item 1</name>
<parts>
<part>
<id>1</id>
<name>Part 1.1</name>
</part>
<part>
<id>1</id>
<name>Part 1.2</name>
</part>
<part>
<id>1</id>
<name>Part 1.3</name>
</part>
</parts>
</item>
<item>
<id>2</id>
<name>Item 2</name>
<parts>
<part>
<id>2</id>
<name>Part 2.1</name>
</part>
<part>
<id>2</id>
<name>Part 2.2</name>
</part>
</parts>
</item>
</items>
In the (last) FHIR specification (v1.8.0), it's mentioned that a contained resource can be embedded in a Reference (documentation), when no reference exists.
But, by looking at the XSD, I can't figure out how to validate the XML against the patient.xsd with such a mechanism.
Here is my attempt
<?xml version="1.0" encoding="UTF-8"?>
<Patient xmlns="http://hl7.org/fhir">
<identifier>
<system value="urn:oid:1.2.250.1.311.1.1"/>
<value value="2000100439"/>
<assigner>
<display value="ap-hm"/>
</assigner>
</identifier>
<name>
<use value="official"/>
<family value="COPTER"/>
<given value="ELI"/>
</name>
<gender value="male"/>
<birthDate value="1954-08-14"/>
<deceasedBoolean value="false"/>
<address>
<use value="home"/>
<line value="45 boulevard des cigales"/>
<city value="MARSEILLE 10"/>
<postalCode value="13010"/>
</address>
<maritalStatus>
<coding>
<system value="http://hl7.org/fhir/v3/MaritalStatus"/>
<code value="U"/>
</coding>
</maritalStatus>
<generalPractitioner>
<contained>
<Practitioner>
<id value="p1"/>
<name>
<family value="PASTEUR"/>
<given value="LOUIS"/>
</name>
<address>
<city>MARSEILLE</city>
<postalCode>13005</postalCode>
</address>
<gender value="male"/>
</Practitioner>
</contained>
</generalPractitioner>
</Patient>
What is the correct way to have a contained reference ?
All contained resources are sent near the top using the "contained" element. They are then referenced as a local reference. So your example would look as follows:
<?xml version="1.0" encoding="UTF-8"?>
<Patient xmlns="http://hl7.org/fhir">
<contained>
<Practitioner>
<id value="p1"/>
<name>
<family value="PASTEUR"/>
<given value="LOUIS"/>
</name>
<address>
<city>MARSEILLE</city>
<postalCode>13005</postalCode>
</address>
<gender value="male"/>
</Practitioner>
</contained>
<identifier>
<system value="urn:oid:1.2.250.1.311.1.1"/>
<value value="2000100439"/>
<assigner>
<display value="ap-hm"/>
</assigner>
</identifier>
<name>
<use value="official"/>
<family value="COPTER"/>
<given value="ELI"/>
</name>
<gender value="male"/>
<birthDate value="1954-08-14"/>
<deceasedBoolean value="false"/>
<address>
<use value="home"/>
<line value="45 boulevard des cigales"/>
<city value="MARSEILLE 10"/>
<postalCode value="13010"/>
</address>
<maritalStatus>
<coding>
<system value="http://hl7.org/fhir/v3/MaritalStatus"/>
<code value="U"/>
</coding>
</maritalStatus>
<generalPractitioner>
<reference value="#p1"/>
</generalPractitioner>
</Patient>
Im am trying to get the xml tag to be a part of the file name but im not getting any value. Am I doing something wrong? Im getting an error or a null value when I change the transformer
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:email="http://www.mulesoft.org/schema/mule/email" xmlns:pop3="http://www.mulesoft.org/schema/mule/pop3" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/pop3 http://www.mulesoft.org/schema/mule/pop3/current/mule-pop3.xsd
http://www.mulesoft.org/schema/mule/email http://www.mulesoft.org/schema/mule/email/current/mule-email.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd">
<flow name="email_notificationFlow">
<file:inbound-endpoint path="C:\Users\pd00h\Desktop\Knauf\testxML" responseTimeout="10000" doc:name="File"/>
<file:file-to-byte-array-transformer doc:name="File to Byte Array"/>
<set-variable variableName="order" value="#[xpath3('//ns0:Payload/WhsDockets/WhsDocket/Reference')]" doc:name="Variable"/>
<logger message="#[flowVars.order]" level="INFO" doc:name="Logger"/>
<file:outbound-endpoint path="C:\Users\pd00h\Desktop\Knauf" outputPattern="Knauf-#[message.id].xml" responseTimeout="10000" doc:name="File"/>
</flow>
</mule>
Sample Input File
<?xml version="1.0" encoding="utf-8"?><XmlInterchange xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Version="1" xmlns="http://www.edi.com.au/EnterpriseService/">
<InterchangeInfo>
<Date>2016-02-19T09:31:34.969+09:00</Date>
<XmlType>LightWeight</XmlType>
<Source>
<EnterpriseCode>AWH</EnterpriseCode>
<CompanyCode>ADL</CompanyCode>
<OriginServer>ADL</OriginServer>
</Source>
<Target />
<EDIOrganisation EDICode="AWHLOG_AU" OwnerCode="AWHLOG_AU">
<OrganisationDetails>
<Name>AWH LOGISTICS</Name>
<Location Country="Australia" City="Adelaide">AUADL</Location>
<Addresses>
<Address AddressType="MAIN">
<AddressLine1>Gillman Wool Complex</AddressLine1>
<AddressLine2>GRAND TRUNKWAY,</AddressLine2>
<AddressCode>Gillman Wool Complex</AddressCode>
<CityOrSuburb>GILLMAN</CityOrSuburb>
<StateOrProvince>SA</StateOrProvince>
<PostCode>5013</PostCode>
<TelephoneNumbers>
<TelephoneNumber NumberType="Business">+618 8240 8400</TelephoneNumber>
<TelephoneNumber NumberType="Fax">+618 8240 0080</TelephoneNumber>
</TelephoneNumbers>
<Email>containers#awh.com.au</Email>
<Language>ENG</Language>
<Location>AUADL</Location>
<Sequence>1</Sequence>
<AddressCapabilities>
<AddressCapability AddressType="MAIN" />
<AddressCapability IsMainAddress="true" AddressType="OFC" />
<AddressCapability IsMainAddress="true" AddressType="PAD" />
</AddressCapabilities>
</Address>
</Addresses>
</OrganisationDetails>
</EDIOrganisation>
</InterchangeInfo>
<Payload>
<WhsDockets>
<WhsDocket>
<Identifier>
<Client EDICode="KNAINSBNE" OwnerCode="KNAINSBNE">
<OrganisationDetails>
<Name>Knauf Insulation Pty Ltd</Name>
<Location Country="Australia" City="Brisbane">AUBNE</Location>
<Addresses>
<Address AddressType="MAIN">
<AddressLine1>2/44 BorthwickAve</AddressLine1>
<AddressCode>2/44 BorthwickAve</AddressCode>
<CityOrSuburb>MURARRIE</CityOrSuburb>
<StateOrProvince>QLD</StateOrProvince>
<PostCode>4172</PostCode>
<TelephoneNumbers>
<TelephoneNumber NumberType="Business">+61 (7) 3393-7300</TelephoneNumber>
<TelephoneNumber NumberType="Mobile">+61 (438) 488-000</TelephoneNumber>
<TelephoneNumber NumberType="Fax">+61 (7) 3343-1898</TelephoneNumber>
</TelephoneNumbers>
<Email>orders.au#knaufinsulation.com</Email>
<Language>ENG</Language>
<Location>AUBNE</Location>
<Sequence>1</Sequence>
<AddressCapabilities>
<AddressCapability AddressType="MAIN" />
<AddressCapability IsMainAddress="true" AddressType="OFC" />
</AddressCapabilities>
</Address>
</Addresses>
</OrganisationDetails>
</Client>
<Reference>2363867</Reference>
<DocketType>WOH</DocketType>
<ActionType>CON</ActionType>
</Identifier>
<DocketDetail>
<WarehouseCode>ROC</WarehouseCode>
<CustomerReference>3330826</CustomerReference>
<Units>80</Units>
<Packages>0</Packages>
<Pallets>0</Pallets>
<Weight DimensionType="KG">673</Weight>
<Cubic DimensionType="M3">7.624</Cubic>
<TransportInsurance>0.0000</TransportInsurance>
<ShipperCODAmount>0.0000</ShipperCODAmount>
<CustomerOrderDetail>
<OrderType>ORD</OrderType>
<DateRequired>2015-08-25T00:00:00</DateRequired>
<Consignee AddressType="CEA">
<AddressLine1>71-83 Kenny Street</AddressLine1>
<CityOrSuburb>PORTSMITH</CityOrSuburb>
<StateOrProvince>QLD</StateOrProvince>
<PostCode>4870</PostCode>
<CompanyName>Bunnings Cairns Central Warehouse</CompanyName>
<CountryCode>AU</CountryCode>
<ContactName>The Import Manager</ContactName>
</Consignee>
</CustomerOrderDetail>
<CustomAttributes />
</DocketDetail>
<DocketLines>
<DocketLine>
<Product>E2271</Product>
<Description>R 3 0 145mm x 580mm x 1160mm</Description>
<QuantityFromClientOrder>4</QuantityFromClientOrder>
<QuantityActuallyOrdered>4</QuantityActuallyOrdered>
<ProductUQ>MST</ProductUQ>
<LineAttributes />
<LineNumber>1</LineNumber>
<Confirmation>
<Lines>
<Line>
<Quantity>16</Quantity>
<QuantityUQ>PAC</QuantityUQ>
</Line>
</Lines>
<Quantity>16</Quantity>
</Confirmation>
</DocketLine>
<DocketLine>
<Product>E4386</Product>
<Description>R 2 0 90mm x 580mm x 19000mm</Description>
<QuantityFromClientOrder>4</QuantityFromClientOrder>
<QuantityActuallyOrdered>4</QuantityActuallyOrdered>
<ProductUQ>MST</ProductUQ>
<LineAttributes />
<LineNumber>2</LineNumber>
<Confirmation>
<Lines>
<Line>
<Quantity>32</Quantity>
<QuantityUQ>PAC</QuantityUQ>
</Line>
</Lines>
<Quantity>32</Quantity>
</Confirmation>
</DocketLine>
<DocketLine>
<Product>450521</Product>
<Description>XPS300 30 x 600 x 1200 B1 / On / SE</Description>
<QuantityFromClientOrder>20</QuantityFromClientOrder>
<QuantityActuallyOrdered>20</QuantityActuallyOrdered>
<ProductUQ>PC</ProductUQ>
<LineAttributes />
<LineNumber>3</LineNumber>
<Confirmation>
<Lines>
<Line>
<Quantity>20</Quantity>
<QuantityUQ>PC</QuantityUQ>
</Line>
</Lines>
<Quantity>20</Quantity>
</Confirmation>
</DocketLine>
<DocketLine>
<Product>450523</Product>
<Description>XPS300 50 x 600 x 1200 B1 / On / SE</Description>
<QuantityFromClientOrder>12</QuantityFromClientOrder>
<QuantityActuallyOrdered>12</QuantityActuallyOrdered>
<ProductUQ>PC</ProductUQ>
<LineAttributes />
<LineNumber>4</LineNumber>
<Confirmation>
<Lines>
<Line>
<Quantity>12</Quantity>
<QuantityUQ>PC</QuantityUQ>
</Line>
</Lines>
<Quantity>12</Quantity>
</Confirmation>
</DocketLine>
</DocketLines>
</WhsDocket>
</WhsDockets>
</Payload>
Can you use this to complex XML structures?
Add namespace-manager
replace file:file-to-byte-array-transformer
with byte-array-to-string-transformer
fix xpath usage
updated code:
<mule xmlns:file="http://www.mulesoft.org/schema/mule/file"
xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:email="http://www.mulesoft.org/schema/mule/email"
xmlns:pop3="http://www.mulesoft.org/schema/mule/pop3" xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/pop3 http://www.mulesoft.org/schema/mule/pop3/current/mule-pop3.xsd
http://www.mulesoft.org/schema/mule/email http://www.mulesoft.org/schema/mule/email/current/mule-email.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd">
<mulexml:namespace-manager
includeConfigNamespaces="true">
<mulexml:namespace prefix="ns0"
uri="http://www.example.com/something.xsd" />
</mulexml:namespace-manager>
<flow name="email_notificationFlow">
<file:inbound-endpoint path="C:\Users\pd00h\Desktop\Knauf\testxML"
responseTimeout="10000" doc:name="File" />
<byte-array-to-string-transformer
doc:name="Byte Array to String" />
<set-variable variableName="order"
value="#[xpath3('//ns0:WhsDockets/ns0:WhsDocket/ns0:Reference')]"
doc:name="Variable" />
<logger message="#[flowVars.order]" level="INFO" doc:name="Logger" />
<file:outbound-endpoint path="C:\Users\pd00h\Desktop\Knauf"
outputPattern="Knauf-#[message.id].xml" responseTimeout="10000"
doc:name="File" />
</flow>
</mule>
Sample xml file:
<?xml version='1.0' encoding='UTF-8'?>
<ns0:WhsDockets xmlns:ns0="http://www.example.com/something.xsd">
<ns0:WhsDocket>
<ns0:Reference>GotIt!</ns0:Reference>
</ns0:WhsDocket>
</ns0:WhsDockets>
Cheers
I have complex soap XML like below.
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<MessageHeader>
<From>
<Type>string</Type>
</d3p1:From>
<d3p1:To>
<Role>string</Role>
</d3p1:To>
</MessageHeader>
<Security xmlns="http://schemas.xmlsoap.org/ws/2002/12/sxvt">
<StrongToken>string</StrongToken>
</Security>
</soap:Header>
<soap:Body>
<FunctionResponse xmlns="http://www.yyy.com/webservices">
<FunctionRS TimeStamp="dateTime">
<Message>string<Message>
<Success>
<SuccessMessage>string</SuccessMessage>
</Success>
<Warnings>
<Warning Type="string" Text="string" />
<Warning Type="string" Text="string" />
</Warnings>
<Errors>
<Error Type="string" Text="string" />
<Error Type="string" Text="string" />
</Errors>
<Items>
<Item SequenceNo="Int" ">
<SamplePrice>
<Prices>
<Price>
<ToatlPrice>
<ItemNo>Int </ItemNo>
<ItemPrice>Int </ItemPrice>
</ToatlPrice>
</Price>
</Prices>
</SamplePrice >
</Item>
<Item SequenceNo="Int" ">
<SamplePrice>
<Prices>
<Price>
<ToatlPrice>
<ItemNo>Int </ItemNo>
<ItemPrice>Int </ItemPrice>
</ToatlPrice>
</Price>
</Prices>
</SamplePrice >
</Item>
</Items>
<Info>
<CurrencyCode>
<string>string</string>
<string>string</string>
</CurrencyCode>
</Infor>
</FunctionRS>
</FunctionResponse>
</soap:Body>
</soap:Envelope>
here i want the results of FunctionRS tag. I have created the class for the FunctionRS tag.
I have created FunctionRS class.
var result = resultNewDataSet.Descendants("FunctionRS").Select(t => new FunctionRS
{
Message = t.Descendants("Message").First().Value,
//Success = t.Descendants("Success").First().Value
});
using the above code i am able to get Message tag, but i am not able get the array lists (like Success, warnings,Items,etc) and class (like Info).
How can i Serialize the above xml using LINQ to XML.
Thanks in advance.
Elements you are looking for are in http://www.yyy.com/webservices namespace however in your query you are not using namespaces. I am not sure how FunctionRS or Message could be found as you are looking for them in the empty namespace. Try the following:
var resultNewDataSet = XDocument.Parse(
#"<?xml version=""1.0"" encoding=""utf-8""?>
<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""
xmlns:xsd=""http://www.w3.org/2001/XMLSchema""
xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:d3p1=""unknownnamespace"">
<soap:Header>
<MessageHeader>
<d3p1:From>
<Type>string</Type>
</d3p1:From>
<d3p1:To>
<Role>string</Role>
</d3p1:To>
</MessageHeader>
<Security xmlns=""http://schemas.xmlsoap.org/ws/2002/12/sxvt"">
<StrongToken>string</StrongToken>
</Security>
</soap:Header>
<soap:Body>
<FunctionResponse xmlns=""http://www.yyy.com/webservices"">
<FunctionRS TimeStamp=""dateTime"">
<Message>string</Message>
<Success>
<SuccessMessage>string</SuccessMessage>
</Success>
<Warnings>
<Warning Type=""string"" Text=""string"" />
<Warning Type=""string"" Text=""string"" />
</Warnings>
<Errors>
<Error Type=""string"" Text=""string"" />
<Error Type=""string"" Text=""string"" />
</Errors>
<Items>
<Item SequenceNo=""Int"">
<SamplePrice>
<Prices>
<Price>
<ToatlPrice>
<ItemNo>Int </ItemNo>
<ItemPrice>Int </ItemPrice>
</ToatlPrice>
</Price>
</Prices>
</SamplePrice >
</Item>
<Item SequenceNo=""Int"">
<SamplePrice>
<Prices>
<Price>
<ToatlPrice>
<ItemNo>Int </ItemNo>
<ItemPrice>Int </ItemPrice>
</ToatlPrice>
</Price>
</Prices>
</SamplePrice >
</Item>
</Items>
<Info>
<CurrencyCode>
<string>string</string>
<string>string</string>
</CurrencyCode>
</Info>
</FunctionRS>
</FunctionResponse>
</soap:Body>
</soap:Envelope>");
XNamespace webServicesNs = "http://www.yyy.com/webservices";
var result = resultNewDataSet
.Descendants(webServicesNs + "FunctionRS")
.Select(t => new
{
Message = (string)t.Descendants(webServicesNs + "Message").First(),
Success = (string)t.Descendants(webServicesNs + "Success").First(),
Warnings = t
.Element(webServicesNs + "Warnings")
.Elements(webServicesNs + "Warning")
.Select(w => new
{
#Type = (string)w.Attribute("Type"),
#Text = (string)w.Attribute("Text")
})
});
foreach (var r in result)
{
Console.WriteLine(r);
foreach (var w in r.Warnings)
{
Console.WriteLine(w);
}
}
(I included the Xml since the one you provided was broken and I had to fix it to make it possible to load to XDocument).
Here is the result I got:
{ Message = string, Success = string, Warnings = System.Linq.Enumerable+WhereSel
ectEnumerableIterator`2[System.Xml.Linq.XElement,<>f__AnonymousType0`2[System.St
ring,System.String]] }
{ Type = string, Text = string }
{ Type = string, Text = string }