I want to address an xml value in the Xpath field within the enrich mediator in order to customize an API response. My xml input is as follow:
<member>
<name>ABC</name>
</value>1</value>
</member>
I tried to access the 'ABC' value by using this code:
$body//member[#name='ABC']
but it does not work for me.
First of all your XML input is not valid. There is no opening value tag but two closing.
Can you try //member/name/text(),this worked für me.If its not working,then maybe you need to add the namespaces.
Hope that helps.
I have two xml config files that has same elements. I want to compare if the uri is same for them. If they are different I need to print the element name.
Doc1 :
<config>
<google>
<url>google.com/api/getcoordinates</url>
</google>
<ranst>
<url>http://ranst.com/getranst</url>
<ranst>
</config>
doc2:
<config>
<google>
<url>google.com/api/getlocationcordinates</url>
</google>
<akamai>
<url>http://akamai.com/redirectlocation/eastregion</url>
<akamai>
</config>
Document1 and document2 has google in common , but the uri's are different. So I want to call this out. How can I do this using XSLT ?
Thanks.
I have a requirement to parse JSON response which contain array of products(P1,P2,P3,etc.). Each product contains multiple information like name, type, cost, etc.
I need to read each product one by one and append additional data got from the another service into an new JSON output. I am thinking of using ForEach component of WSO2 ESB to iterate each product one by one.
Problem is that ForEach component uses ForEachExpression which expects XML expression in the configuration.
Please suggest on the method to parse array of JSON response one by one in WSO2 ESB.
/Abhishek
Can use both Iterate or ForEach mediator for iterating the JSON array, since both are content aware mediators and support JSON.
Which one to use depends upon the specific usecase as Iterate provides the capability to use call / callout / send mediators in the sequence whereas ForEach doesn´t allow it.
For the below given sample JSON request, the following iteration works and the JSON array and objects can be referred like the same.
{
"products":[
{
"product":{
"id":"1234",
"size":"20",
"quantity":"1",
"price":"990",
"type":"Electronics",
"store":{
"id":"001"
}
}
}
]
}
<iterate expression="//products" id="PRD_ITR">
<target>
<sequence>
<sequence key="Product_Enrich_Sequence_s"/>
<!-- For example, Switching sequence based on the product type -->
<switch source="//products/product/type">
<case regex="Computer">
<sequence key="Computer_Product_Enrich_Sequence_s"/>
</case>
<case regex="Mobile">
<sequence key="Mobile_Product_Enrich_Sequence_s"/>
</case>
<case regex="Grocery">
<sequence key="GR_Product_Enrich_Sequence_s"/>
</case>
<default>
<!-- default stuff --!>
</default>
</switch>
</sequence>
</target>
</iterate>
FYR
https://docs.wso2.com/display/ESB490/Iterate+Mediator
https://docs.wso2.com/display/ESB490/ForEach+Mediator
Note: tested in WSO2 ESB 4.9.0
I haven't found any approach to parse string with whole XML doc into separate tuples, pls suggest me how can I do this?
Suppose we have avro file:
{fieldname: id, fieldname: xml}
Xml structure:
<?xml version='1.0' encoding='UTF-8'?>
<response>
<name>Ghty</name>
<main>
<data>
<id>1</id>
<text>ABC mask</text>
<title>Some text</title>
</data>
<data>
<id>2</id>
<text>Second value</text>
<title>To</title>
</data>
<data>
<id>3</id>
<text>Evolving to</text>
<title>Hint 567</title>
</data>
</main>
</response>
When we do a load from xml file, its clear that input xml splits
into parts, according to the tag we put into statement:
DEFINE XMLLoader org.apache.pig.piggybank.storage.XMLLoader('data');
DEFINE XPath org.apache.pig.piggybank.evaluation.xml.XPath();
xml = LOAD '$XPATH' using XMLLoader as (x:chararray);
DUMP xml;
(<data><id>1</id><text>ABC mask</text><title>Some text</title></data>)
(<data><id>2</id><text>Second value</text><title>To</title></data>)
(<data><id>3</id><text>Evolving to</text><title>Hint 567</title></data>)
xml_parse = FOREACH xml GENERATE
XPath(x, 'data/id') as (id:chararray),
XPath(x, 'data/text') as (text:chararray),
XPath(x, 'data/title') as (title:chararray);
DUMP xml_parse;
(1,ABC mask,Some text)
(2,Second value,To)
(3,Evolving to,Hint 567)
I want to do the same with the xml in the string, without LOAD
operation. But how can we do the same if we have such xmls in a
string and they are not splited for further XPath action?
(<?xml version='1.0' encoding='UTF-8'?><response><name>Ghty</name><main><data><id>1</id><text>ABC mask</text><title>Some text</title></data><data><id>2</id><text>Second value</text><title>To</title></data><data><id>3</id><text>Evolving to</text><title>Hint 567</title></data></main></response>)
1. I tried to apply this approach, but haven't got any success, because I'm getting only the first element from xml string:
xml = LOAD 'xml_set.avro' using
org.apache.pig.piggybank.storage.avro.AvroStorage();
xml_parse = foreach xml generate
XPath($0, 'data');
DUMP xml_parse ;
(1,ABC mask,Some text)
2. I tried to use XPathAll, but haven't got success as well, all values was put in one tuple:
xml = LOAD 'xml_set.avro' using
org.apache.pig.piggybank.storage.avro.AvroStorage();
xml_parse = foreach xml generate
XPathAll($0, 'data'),
XPathAll($0, 'data'),
XPathAll($0, 'data'),
DUMP xml_parse ;
((1,ABC mask,Some text,2,Second value,To,3,Evolving to,Hint 567))
3. Then I tried to use XPathAll with full tag paths, but result was a tuple of tuples. I need somehow to split them in a right order,
but don't know how.
xml = LOAD 'xml_set.avro' using
org.apache.pig.piggybank.storage.avro.AvroStorage();
xml_parse = foreach xml generate
XPathAll($0, 'data/id'),
XPathAll($0, 'data/text'),
XPathAll($0, 'data/title'),
DUMP xml_parse ;
((1,2,3),(ABC mask,Second value, Evolving to),(Some text,To,Hint 567))
Seems need some kind of pivot to be done here. The goal is to get:
(1,ABC mask,Some text)
(2,Second value,To)
(3,Evolving to,Hint 567)
Ofc I can store all xmls from avro to 1 big xml file and then load it with XMLLoader, but its redundunt step I assume.
Appreciate any help and suggestions. Stuck with it for a long time (((
[WSO2 ESB V4.5.0]
What is wrong with how I'm configuring the enrich mediator to accumulate XML? I have a sequence of n PojoMediators that retrieve XML from a database with each setting a context property with the XML represented as a string. For example, after the first PojoMediator executes, its' context property is set to:
customerInformation = <cust><id>1</id><oc></oc><ca>0</ca></cust>
and I'm trying to enrich the body with that XML content but end up with:
[snip]
</header>
<cust><id>1</id><oc></oc><ca>0</ca></cust></root></soapenv:Body></soapenv:Envelope> {org.apache.synapse.mediators.builtin.LogMediator}
..where the enrich mediator is escaping the referenced "custInfo" XML. My enrich configuration is:
<enrich>
<source type="property" property="custInfo"/>
<target type="body"/>
</enrich>
Is there a means to coerce the enrich mediator to treat the property ("custInfo") as an XML fragment rather than as straight text? I'm assuming that this is why the XML is getting escaped as the mediator believes it is setting the content of a node rather than specifying an XML fragment.
How you defined property ? Can you try after adding
type="OM"
to the property definition and try again?