XML parsing using SQL - sql

How i can parse the following XML to get output like below name = Business, Value = XYZ name = Product, Value = STANDARD name = Trend, Value = Active,Active New,Sparse etc Business,Product,Trend data can be dynamic,some xml do contain, some do not,if it exists then only value should be shown.
Can you please help me with this.
<Filter>
<Expression>
<Expression Name="Business">
<Path>
<RolePathItem>
<RoleID>Gcea34afc</RoleID>
</RolePathItem>
</Path>
<AttributeRef>
<AttributeID>3d0534a20d19</AttributeID>
</AttributeRef>
</Expression>
<Expression>
<Literal>
<DataType>String</DataType>
<Value>XYZ</Value>
</Literal>
</Expression>
</Expression>
<Expression>
<Function>
<FunctionName>Equals</FunctionName>
<Arguments>
<Expression Name="Product">
<Path>
<RolePathItem>
<RoleID>6a99c8cd92fc</RoleID>
</RolePathItem>
<RolePathItem>
<RoleID>011e01b51ba0</RoleID>
</RolePathItem>
</Path>
</Expression>
<Expression>
<Literal>
<DataType>String</DataType>
<Value>STANDARD</Value>
</Literal>
</Expression>
</Arguments>
</Function>
</Expression>
<Expression>
<Function>
<FunctionName>In</FunctionName>
<Arguments>
<Expression Name="Trend">
<Path>
<RolePathItem>
<RoleID>6a99c8cd92fc</RoleID>
</RolePathItem>
<RolePathItem>
<RoleID>dad362a5a954</RoleID>
</RolePathItem>
</Path>
</Expression>
<Expression>
<Literal>
<DataType>String</DataType>
<Values>
<Value>Active</Value>
<Value>Active New</Value>
<Value>New</Value>
<Value>Sparse</Value>
</Values>
</Literal>
</Expression>
</Arguments>
</Function>
</Expression>
</Filter>

Because of dynamic content, I had to use some string functions, but it looks working.
DECLARE #xmlData XML = '
<Filter>
<Expression>
<Expression Name="Business">
<Path>
<RolePathItem>
<RoleID>Gcea34afc</RoleID>
</RolePathItem>
</Path>
<AttributeRef>
<AttributeID>3d0534a20d19</AttributeID>
</AttributeRef>
</Expression>
<Expression>
<Literal>
<DataType>String</DataType>
<Value>XYZ</Value>
</Literal>
</Expression>
</Expression>
<Expression>
<Function>
<FunctionName>Equals</FunctionName>
<Arguments>
<Expression Name="Product">
<Path>
<RolePathItem>
<RoleID>6a99c8cd92fc</RoleID>
</RolePathItem>
<RolePathItem>
<RoleID>011e01b51ba0</RoleID>
</RolePathItem>
</Path>
</Expression>
<Expression>
<Literal>
<DataType>String</DataType>
<Value>STANDARD</Value>
</Literal>
</Expression>
</Arguments>
</Function>
</Expression>
<Expression>
<Function>
<FunctionName>In</FunctionName>
<Arguments>
<Expression Name="Trend">
<Path>
<RolePathItem>
<RoleID>6a99c8cd92fc</RoleID>
</RolePathItem>
<RolePathItem>
<RoleID>dad362a5a954</RoleID>
</RolePathItem>
</Path>
</Expression>
<Expression>
<Literal>
<DataType>String</DataType>
<Values>
<Value>Active</Value>
<Value>Active New</Value>
<Value>New</Value>
<Value>Sparse</Value>
</Values>
</Literal>
</Expression>
</Arguments>
</Function>
</Expression>
</Filter>'
;WITH XmlRows AS (
SELECT
CONVERT(VARCHAR(MAX),ref.query('*')) XMLString
FROM #xmlData.nodes('/Filter/Expression') x ( ref )
)
,NameAndValueXml AS
( SELECT CONVERT(XML,
SUBSTRING(XMLString,
CHARINDEX('<Expression Name=',XMLString),
( CHARINDEX('</Expression>',XMLString) - CHARINDEX('<Expression Name=',XMLString) + LEN('</Expression>') ) )
) AS NameXml
,CONVERT(XML,
SUBSTRING(XMLString,
CHARINDEX('<Literal>',XMLString),
( CHARINDEX('</Literal>',XMLString) - CHARINDEX('<Literal>',XMLString) + LEN('</Literal>') ) )
)
AS ValueXml
FROM XmlRows
)
SELECT
NameXml.value('(./Expression/#Name)[1]', 'nvarchar(255)') Name,
CASE
WHEN ValueXml.exist('(/Literal/Values/*)') = 1 THEN
REPLACE(REPLACE(REPLACE(CONVERT(VARCHAR(max),ValueXml.query('(/Literal/Values/*)')),'</Value><Value>' , ','),'</Value>',''),'<Value>','')
ELSE
ValueXml.value('(./Literal/Value)[1]', 'nvarchar(max)')
END AS Value
FROM NameAndValueXml
result:
Name Value
-------- ----------------------------
Business XYZ
Product STANDARD
Trend Active,Active New,New,Sparse

Related

Assertions on XML response in Karate

How to apply assertions in such kind of a response in XML.
I have tried to convert this in json first by using
* json response = response
But this returns an invalid json when checked via json validator. As I thought converting in JSON and then matching the response will be easier.
** Assertions**
Check if first tag is Resource.
Check type is type1
Check valueTotal is 7
Check /Resource/entry/url value is https://myurl1
Check /Resource/entry/resource/user/identifier/type/coding/code
value is CC
<Resource xmlns="http://myurl">
<type xmlns="" value="type1"/>
<valueTotal xmlns="" value="7"/>
<entry xmlns="">
<url value="https://myurl1"/>
<resource>
<user>
<id value="123"/>
<identifier>
<type>
<coding>
<system value="http://myurl2"/>
<code value="CC"/>
<display value="abcedflk"/>
</coding>
<text value="test"/>
</type>
<system value="http://myurl3"/>
<value value="90204343"/>
</identifier>
<patient>
<reference value="value/new"/>
</patient>
<relationship>
<extension url="http://myurl4">
<valueCodeableConcept>
<coding>
<system value="http://myurl5"/>
<code value="xyz"/>
<display value="value11111"/>
</coding>
<text value="value11111"/>
</valueCodeableConcept>
</extension>
</relationship>
<name>
<family value="ABC"/>
<given value="TEST"/>
<given value="JON"/>
</name>
<gender value="male"/>
<birthDate value="1990-02-17"/>
</user>
</resource>
<search>
<mode value="123zbc"/>
</search>
</entry>
<entry xmlns="">
<url value="https://myurl1"/>
<resource>
<user>
<id value="123"/>
<identifier>
<type>
<coding>
<system value="http://myurl2"/>
<code value="CC"/>
<display value="abcedflk"/>
</coding>
<text value="test"/>
</type>
<system value="http://myurl3"/>
<value value="90204343"/>
</identifier>
<patient>
<reference value="value/new"/>
</patient>
<relationship>
<extension url="http://myurl4">
<valueCodeableConcept>
<coding>
<system value="http://myurl5"/>
<code value="abc"/>
<display value="value22222"/>
</coding>
<text value="value22222"/>
</valueCodeableConcept>
</extension>
</relationship>
<name>
<family value="ABC"/>
<given value="TEST"/>
<given value="JON"/>
</name>
<gender value="male"/>
<birthDate value="1990-02-17"/>
</user>
</resource>
<search>
<mode value="123yyy"/>
</search>
</entry>
</Resource>
Assuming the XML is in the variable response:
# the first 2 lines are un-necessary, as all the
# XPath assertions start with /Resource
* json asJson = response
* match asJson contains { Resource: '#present' }
* match /Resource/type/#value == 'type1'
* match /Resource/valueTotal/#value == '7'
* match /Resource/entry[1]/url/#value == 'https://myurl1'
* match /Resource/entry[1]/resource/user/identifier/type/coding/code/#value == 'CC'
Please brush up on XML and XPath if needed: https://github.com/karatelabs/karate#advanced-xpath

Constructing a XML in SQL with a table column name as XML tag

I have a requirement to get the schema of a table in XML format.
Consider a table Person with columns:
ID varchar(10) Identity, Name varchar(20), Designation varchar(10)
I need the XML to be of the format
<Persons>
<Person LocalizationSetting = {today's date}>
<ID type=varchar length =10 required=true/>
<Nametype=varchar length =20 required=true/>
<Designation type=varchar length =10 required=true/>
</Person>
</Persons>
I have the following script
DECLARE #TableSchema XML
SELECT #TableSchema = (
select column_name,
data_type as [type],
CHARACTER_MAXIMUM_LENGTH AS maxLength,
case(is_nullable)
when 'YES' then 'false'
else 'true'
end as [required]
from information_schema.columns [column]
where table_name = 'Person'
for xml auto,root('Persons')
)
SELECT #TableSchema
I get the following result:
<Patients>
<column column_name="ID" type="varchar" maxLength="10" required="true" />
<column column_name="Name" type="varchar" maxLength="20" required="true" />
<column column_name="Designation" type="varchar" maxLength="10" required="true" />
</Patients>
Is it possible to have the column_name as a tag as shown in the expected result?
You should solve this ...
I have a requirement to get the schema of a table in XML format.
... with standard built-in features. The schema you provide as expected output is some self-defined structure probably... Check this out:
CREATE TABLE Person (ID VARCHAR(10) NOT NULL
,NameType VARCHAR(20) NOT NULL
,Designation VARCHAR(10) NOT NULL);
INSERT INTO Person VALUES('SomeID','SomeType','SomeDes');
SELECT * FROM Person FOR XML AUTO,XMLDATA;
--XMLDATA returns this schema
<Schema name="Schema1" xmlns="urn:schemas-microsoft-com:xml-data" xmlns:dt="urn:schemas-microsoft-com:datatypes">
<ElementType name="Person" content="empty" model="closed">
<AttributeType name="ID" dt:type="string" />
<AttributeType name="NameType" dt:type="string" />
<AttributeType name="Designation" dt:type="string" />
<attribute type="ID" />
<attribute type="NameType" />
<attribute type="Designation" />
</ElementType>
</Schema>
--The next possibility
SELECT * FROM Person FOR XML AUTO,XMLSCHEMA;
--XMLSCHEMA returns this schema
<xsd:schema targetNamespace="urn:schemas-microsoft-com:sql:SqlRowSet1" xmlns:schema="urn:schemas-microsoft-com:sql:SqlRowSet1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sqltypes="http://schemas.microsoft.com/sqlserver/2004/sqltypes" elementFormDefault="qualified">
<xsd:import namespace="http://schemas.microsoft.com/sqlserver/2004/sqltypes" schemaLocation="http://schemas.microsoft.com/sqlserver/2004/sqltypes/sqltypes.xsd" />
<xsd:element name="Person">
<xsd:complexType>
<xsd:attribute name="ID" use="required">
<xsd:simpleType>
<xsd:restriction base="sqltypes:varchar" sqltypes:localeId="1033" sqltypes:sqlCompareOptions="IgnoreCase IgnoreKanaType IgnoreWidth">
<xsd:maxLength value="10" />
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="NameType" use="required">
<xsd:simpleType>
<xsd:restriction base="sqltypes:varchar" sqltypes:localeId="1033" sqltypes:sqlCompareOptions="IgnoreCase IgnoreKanaType IgnoreWidth">
<xsd:maxLength value="20" />
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="Designation" use="required">
<xsd:simpleType>
<xsd:restriction base="sqltypes:varchar" sqltypes:localeId="1033" sqltypes:sqlCompareOptions="IgnoreCase IgnoreKanaType IgnoreWidth">
<xsd:maxLength value="10" />
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
</xsd:complexType>
</xsd:element>
</xsd:schema>
If you really have to fullfill the expected format you are having the problem, that native queries do not support dynamic column names. As a workaround you might use dynamically created SQL to be run with EXEC or this approach, which is using a very ugly hack on string level (something one rather should avoid with XML!) at the end:
WITH AlmostCorrect AS
(
SELECT
(
SELECT GETDATE() AS [#LocalizationSetting]
,(
SELECT COLUMN_NAME AS [#name]
,DATA_TYPE AS [#type]
,CHARACTER_MAXIMUM_LENGTH AS [#length]
,CASE IS_NULLABLE
WHEN 'YES' THEN 'false'
ELSE 'true'
END AS [#required]
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'Person'
FOR XML PATH('row'),TYPE
) AS [*]
FOR XML PATH('Person'),ROOT('Persons'),TYPE
) AS TheXML
)
SELECT CAST(REPLACE(REPLACE(CAST(TheXML AS NVARCHAR(MAX)),'<row name="','<'),'" type',' type') AS XML)
FROM AlmostCorrect
The result
<Persons>
<Person LocalizationSetting="2017-04-18T11:05:30.047">
<ID type="varchar" length="10" required="true" />
<NameType type="varchar" length="20" required="true" />
<Designation type="varchar" length="10" required="true" />
</Person>
</Persons>

Mule - CSV Lookup Table

I have a mule flow with DataMapper configuration to map XML to JSON, in that I have a requirement to Lookup a CSV file which contains, for example, two columns and four rows to map to one of the JSON output field.
Below are my sample CSV file contents:
Name,Contact
Ram,111-222
Kumar,222-333
John,333-444
I got below exception while running DataMapper:
Element [CSV:CSV]-Pre-Execution of lookup table [CSV:CSV]failed
Error when parsing record #2 field Name
Caused by: java.lang.RuntimeException: Parsing error: Unexpected record delimiter, probably record has too few fields.
When the CSV file contains only one row there is no exception.
Could any one provide me a way to solve the issue? Thanks in advance.
EDIT: Please find the DataMapper configuration
<mule>
<data-mapper:config name="XML_To_JSON_1" transformationGraphPath="xml_to_json_1.grf" doc:name="XML_To_JSON" />
<flow name="mule-csv-lookupFlow1" doc:name="mule-csv-lookupFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="9090" doc:name="HTTP" />
<data-mapper:transform config-ref="XML_To_JSON_1" doc:name="XML To JSON" />
</flow>
</mule>
Below is the .grf file
<?xml version="1.0" encoding="UTF-8"?><Graph __version="3.5.0" author="pradeep" created="Wed Dec 03 13:06:48 IST 2014" description="XML To JSON" guiVersion="3.4.4.P" id="1417593604462" licenseCode="Unlicensed" licenseType="Unknown" modified="Wed Dec 03 13:06:48 IST 2014" modifiedBy="pradeep" name="XML_To_JSON" preview-file="${Project_Home}/src/main/resources/employee.xml" revision="1.0" showComponentDetails="false">
<Global>
<Metadata __index="0" __referenceCounter="1" __sourcePath="{}/object/contact" _dataStructure="SINGLE_DIMENSIONAL_COLLECTION" _id="__id" _metadataParentId="4430d2fe-5b06-4e39-b259-492c325fe164" _parent_id="__parent_id" _type="Output" id="f11ab87d-ec49-4034-a277-1e96a57b7925">
<Record fieldDelimiter="," name="contact" recordDelimiter="\n\\|\r\n\\|\r" type="delimited">
<Field __artificialType="_parent_id" __systemManaged="true" name="__parent_id" type="string"/>
<Field __artificialType="_id" __systemManaged="true" name="__id" type="string"/>
<Field __index="0" __sourcePath="{}/object/contact/name" containerType="SINGLE" label="name" name="name" type="string"/>
<Field __index="1" __sourcePath="{}/object/contact/phone" containerType="SINGLE" label="phone" name="phone" type="string"/>
</Record>
</Metadata>
<Metadata _type="Lookup" id="963db4af-a7a1-428c-be6b-39af261e93d4">
<Record fieldDelimiter="," name="CSV" recordDelimiter="\n\\|\r\n\\|\r" type="delimited">
<Field containerType="SINGLE" label="firstname" name="firstname" size="10" type="string"/>
<Field containerType="SINGLE" eofAsDelimiter="true" label="phone" name="phone" size="10" type="string"/>
</Record>
</Metadata>
<Metadata __index="0" __referenceCounter="1" __schemaType="employeeType" __sourcePath="{}/employees/employee" _dataStructure="SINGLE_DIMENSIONAL_COLLECTION" _id="__id" _metadataParentId="80f1c157-e81d-439d-afa8-e475de2dfe36" _parent_id="__parent_id" _type="Input" id="019cda9c-1078-4d00-bdcc-f81a59df5292">
<Record fieldDelimiter="," name="employee" recordDelimiter="\n\\|\r\n\\|\r" type="delimited">
<Field __artificialType="_parent_id" __systemManaged="true" name="__parent_id" type="string"/>
<Field __artificialType="_id" __systemManaged="true" name="__id" type="string"/>
<Field __index="0" __schemaType="employeeType" __sourcePath="{}/employees/employee/#firstname" containerType="SINGLE" label="firstname" name="firstname" type="string"/>
<Field __index="1" __schemaType="employeeType" __sourcePath="{}/employees/employee/#lastname" containerType="SINGLE" label="lastname" name="lastname" type="string"/>
<Field __index="2" __schemaType="employeeType" __sourcePath="{}/employees/employee/#gender" containerType="SINGLE" label="gender" name="gender" type="string"/>
<Field __index="3" __schemaType="employeeType" __sourcePath="{}/employees/employee/#phone" containerType="SINGLE" label="phone" name="phone" type="string"/>
<Field __index="4" __schemaType="employeeType" __sourcePath="{}/employees/employee/#text()" containerType="SINGLE" label="text()" name="text" type="string"/>
</Record>
</Metadata>
<Metadata __filteredMetadata="false" __index="0" __referenceCounter="1" __schemaType="employeesType" __sourcePath="{}/employees" _dataStructure="OBJECT" _id="__id" _type="Input" id="80f1c157-e81d-439d-afa8-e475de2dfe36">
<Record fieldDelimiter="," name="employees" recordDelimiter="\n\\|\r\n\\|\r" type="delimited">
<Field __artificialType="_id" __systemManaged="true" name="__id" type="string"/>
</Record>
</Metadata>
<Metadata __index="0" __referenceCounter="1" __sourcePath="{}/object" _dataStructure="OBJECT" _id="__id" _type="Output" id="4430d2fe-5b06-4e39-b259-492c325fe164">
<Record fieldDelimiter="," name="object" recordDelimiter="\n\\|\r\n\\|\r" type="delimited">
<Field __artificialType="_id" __systemManaged="true" name="__id" type="string"/>
</Record>
</Metadata>
<LookupTable fileURL="D:/1_Ram/DEV/Workspace/mule-workspace/mule-datamapper-lookup/src/main/resources/staff.txt" id="CSV" key="phone" metadata="963db4af-a7a1-428c-be6b-39af261e93d4" name="CSV" type="simpleLookup">
<attr name="lookupType"><![CDATA[CSV]]></attr>
</LookupTable>
<Dictionary>
<Entry id="DictionaryEntry0" input="true" name="inputPayload" output="false" type="object"/>
<Entry id="DictionaryEntry1" input="false" name="outputPayload" output="true" type="object"/>
</Dictionary>
</Global>
<Phase number="0">
<Node enabled="enabled" guiName="Foreach 'employees' -> 'object'" guiX="460" guiY="20" id="FOREACH_EMPLOYEES_OBJECT" transformClass="com.mulesoft.datamapper.transform.MelRecordTransform" type="REFORMAT">
<attr name="melScript"><![CDATA[//MEL
//START -> DO NOT REMOVE
output.__id = input.__id;
//END -> DO NOT REMOVE
]]></attr>
</Node>
<Node enabled="enabled" guiName="Foreach 'employee' -> 'contact'" guiX="460" guiY="120" id="FOREACH_EMPLOYEE_CONTACT" transformClass="com.mulesoft.datamapper.transform.MelRecordTransform" type="REFORMAT">
<attr name="melScript"><![CDATA[//MEL
//START -> DO NOT REMOVE
output.__id = input.__id;
output.__parent_id = input.__parent_id;
//END -> DO NOT REMOVE
output.phone = input.phone + (isnull(lookup("CSV").get([input.firstname])) ? null : lookup("CSV").get([input.firstname]).phone);
output.name = input.lastname + ' ' + input.firstname;]]></attr>
</Node>
<Node cacheInMemory="true" charset="UTF-8" enabled="enabled" fileURL="dict:outputPayload" guiName="JSON WRITER" guiX="900" guiY="20" id="JSON_WRITER0" type="JSON_WRITER">
<attr name="mapping"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<object xmlns:clover="http://www.cloveretl.com/ns/xmlmapping" clover:inPort="0">
<clover:collection clover:name="contact">
<item clover:inPort="1" clover:key="__parent_id" clover:parentKey="__id">
<name>$1.name</name>
<phone>$1.phone</phone>
</item>
</clover:collection>
</object>]]></attr>
<attr name="__isJsonSchema"><![CDATA[false]]></attr>
<attr name="_data_format"><![CDATA[JSON]]></attr>
<attr name="jsonSchemaURL"><![CDATA[./src/main/resources/contacts.json]]></attr>
</Node>
<Node charset="UTF-8" dataPolicy="strict" enabled="enabled" fileURL="dict:inputPayload" guiName="XML READER" guiX="20" guiY="20" id="XML_READER0" type="XML_READER">
<attr name="xmlSchemaURL"><![CDATA[./src/main/resources/employees.xsd]]></attr>
<attr name="mapping"><![CDATA[<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Context outPort="0" sequenceField="__id" xpath="/employees">
<Context generatedKey="__parent_id" outPort="1" parentKey="__id" sequenceField="__id" xpath="employee">
<Mapping cloverField="firstname" trim="true" xpath="#firstname"/>
<Mapping cloverField="lastname" trim="true" xpath="#lastname"/>
<Mapping cloverField="gender" trim="true" xpath="#gender"/>
<Mapping cloverField="phone" trim="true" xpath="#phone"/>
<Mapping cloverField="text" trim="true" xpath="text()"/>
</Context>
</Context>
]]></attr>
<attr name="_data_format"><![CDATA[XML]]></attr>
<attr name="__rootGlobalElementName"><![CDATA[employees]]></attr>
</Node>
<Edge debugMode="true" fromNode="FOREACH_EMPLOYEES_OBJECT:0" guiBendpoints="" id="Edge1" inPort="Port 0 (in)" metadata="4430d2fe-5b06-4e39-b259-492c325fe164" outPort="Port 0 (out)" toNode="JSON_WRITER0:0"/>
<Edge debugMode="true" fromNode="FOREACH_EMPLOYEE_CONTACT:0" guiBendpoints="" id="Edge3" inPort="Port 1 (in)" metadata="f11ab87d-ec49-4034-a277-1e96a57b7925" outPort="Port 0 (out)" toNode="JSON_WRITER0:1"/>
<Edge debugMode="true" fromNode="XML_READER0:0" guiBendpoints="" id="Edge0" inPort="Port 0 (in)" metadata="80f1c157-e81d-439d-afa8-e475de2dfe36" outPort="Port 0 (out)" toNode="FOREACH_EMPLOYEES_OBJECT:0"/>
<Edge debugMode="true" fromNode="XML_READER0:1" guiBendpoints="" id="Edge2" inPort="Port 0 (in)" metadata="019cda9c-1078-4d00-bdcc-f81a59df5292" outPort="Port 1 (out)" toNode="FOREACH_EMPLOYEE_CONTACT:0"/>
</Phase>
</Graph>
I noticed the following issues in your .grf file:
1. CSV Record fields are firstname and phone while in your actual csv file they are Name and Contact (I assume the CSV sample in your original post matches what in staff.txt file).
2. LookupTable key is phone while you lookup based on name in your phone mapping lookup("CSV").get([input.firstname]).phone

not able to delete records using endeca partial update

I developed a partial pipeline and executed . There is no error that is generated.But record add and delete is not working, though record update is working fine.
Following is my record manipulator code (jobId is record spec) :
<EXPRESSION LABEL="" NAME="IF" TYPE="VOID" URL="">
<EXPRESSION LABEL="" NAME="MATH" TYPE="INTEGER" URL="">
<EXPRNODE NAME="TYPE" VALUE="STRING"/>
<EXPRNODE NAME="OPERATOR" VALUE="EQUAL"/>
<EXPRESSION LABEL="" NAME="IDENTITY" TYPE="PROPERTY" URL="">
<EXPRNODE NAME="PROP_NAME" VALUE="Endeca.Action"/>
</EXPRESSION>
<EXPRESSION LABEL="" NAME="CONST" TYPE="STRING" URL="">
<EXPRNODE NAME="VALUE" VALUE="UPSERT"/>
</EXPRESSION>
</EXPRESSION>
<EXPRESSION LABEL="" NAME="UPDATE_RECORD" TYPE="VOID" URL="">
<EXPRNODE NAME="ACTION" VALUE="ADD_OR_REPLACE"/>
</EXPRESSION>
<EXPRNODE NAME="ELSE_IF" VALUE=""/>
<EXPRESSION LABEL="" NAME="MATH" TYPE="INTEGER" URL="">
<EXPRNODE NAME="TYPE" VALUE="STRING"/>
<EXPRNODE NAME="OPERATOR" VALUE="EQUAL"/>
<EXPRESSION LABEL="" NAME="IDENTITY" TYPE="PROPERTY" URL="">
<EXPRNODE NAME="PROP_NAME" VALUE="Endeca.Action"/>
</EXPRESSION>
<EXPRESSION LABEL="" NAME="CONST" TYPE="STRING" URL="">
<EXPRNODE NAME="VALUE" VALUE="DELETE"/>
</EXPRESSION>
</EXPRESSION>
<EXPRESSION LABEL="" NAME="UPDATE_RECORD" TYPE="VOID" URL="">
<EXPRNODE NAME="ACTION" VALUE="DELETE_OR_IGNORE"/>
</EXPRESSION>
</EXPRESSION>
After I run partial udpate after deleting a record , get following at /data/partials/forge_output/TestAppen-sgmt0.records.xml_2014.03.26.09.33.53
<UPDATE>
<UPD_UNIT>
<RECORD_DELETE_OR_IGNORE/>
</UPD_UNIT>
</UPDATE>
But record doesnt get deleted.
Thanks,
Mayank Batra

How to make a dynamic xPath and execute it?

I collect string to xpath
<property xmlns:t="https://services" name="xPathElemet" expression="fn:concat(//t:SNILS/, $func:element)"/>
and I want to run this xpath and write the value of a Property
<property name="KEY" expression="get-property('xPathElemet')"/>
but receive only collected a string
how to xpath of the Property?
example code sequence :
<iterate continueParent="true" expression="//t:Employee">
<target>
<sequence>
<call-template target="save_element">
<with-param name="key_element" value="Name"/>
</call-template>
</sequence>
</target>
</iterate>
example code template :
<template xmlns="http://ws.apache.org/ns/synapse" name="save_element">
<parameter name="key_element"/> <!--example: "Name"-->
<sequence>
<property name="KEY" expression="fn:concat(//t:Employee/t:SNILS, ':' ,$func:key_element)" scope="default"
type="STRING"/> <!--example: "111-111-111-1:Name"-->
<property name="xPathElemet" expression="fn:concat('//t:Employee/t:', $func:element)"/> <!--example: "//t:Employee/t:Name"-->
<property name="VALUE" expression="get-property('xPathElemet')" scope="default" type="STRING"/> <!--example: Den (Now it does not work)-->
<dbreport>
<connection>
<pool>
<seetings/>
</pool>
</connection>
<statement>
<sql>
<![CDATA[insert into cache( key , value ) values (?, ?);]]></sql> <!--insert new line where key = "111-111-111-1:Name" and value = "Den"-->
<parameter expression="get-property('KEY')" type="VARCHAR"/>
<parameter expression="get-property('VALUE')" type="VARCHAR"/>
</statement>
</dbreport>
</sequence>
</template>
example xml:
<Employees xmlns="https://services">
<Employee>
<SNILS>111-111-111-1</SNILS>
<Name>Den</Name>
</Employee>
<Employee>
<SNILS>111-111-111-2</SNILS>
<Name>Elena</Name>
</Employee>
</Employees>
Use evaluate
In your case:
<property xmlns:t="https://services" name="xPathElemet" expression="fn:concat(//t:SNILS/, $func:element)"/>
<property name="KEY" expression="evaluate(get-property('xPathElemet'))"/>
You can find more infomation in this blog.
Please try the following and see if it works
<property xmlns:t="https://services" name="xPathElemet" expression="fn:concat(//t:SNILS/, $func:element)"/>
<property xmlns:t="https://services" name="xPathfull" expression="fn:concat(get-property('xPathElemet'),'/text()')"/>
<property name="KEY" expression="get-property('xPathfull')"/>
What was missing from your code was the /text() which refer to the parameters of the given xpath. Please try this