I'm using wso2 data-mapper to map input schema with output schema. problem here is we are unable to map with xml attributes(either it can be in input schema or output schema)
We are able to map with element based xml but unable to map with attribute values
Below link will show you the input schema and output schema
https://drive.google.com/file/d/1Dmupfl71Ww_mLQB0gRL1RnmaebrUnzwh/view?usp=sharing
I tried mapping xml elements to attributes on both Windows and Mac and both seem to work fine. I would advise to start with a small version of your xml tree and expand to see what the problem could be. One difference that stands out: I put sample data in my XML which does not seem to be the case in your example (since it says 'NULL' everywhere).
XML input:
<test>
<owner>theowner</owner>
<status>working</status>
</test>
XML output:
<test>
<Users owner="me" status="working" />
</test>
Related
I want to include last modification date in the output document. I want it to be last modification date of the input XML file. For this purposes I could use the construction below. Though, how could I extract the name of the input XML file to use it with Apache FOP in the construction instead of the manually specified input.xml?
<xsl:value-of select="java:format(java:java.text.SimpleDateFormat.new('yyyy−MM−dd',java:java.util.Locale.new('EN')), java:java.util.Date.new(java:lastModified(java:java.io.File.new('input.xml'))))"/>
I need to compare two xmls in a sequence and store the number of matches in a variable. can this be achieved through sequence.
for example first sequence will be:
<employees>
<employee><id>1</id><name>abc</name></employee>
<employee><id>2</id><name>def</name></employee>
<employee><id>3</id><name>ghi</name></employee>
</employees>
second xml
<employees>
<employee><id>1</id><name>abc</name></employee>
<employee><id>3</id><name>ghi</name></employee>
</employees>
when I compare these two xmls I need to get a count value of 2. How to achieve this.
You can achieve this class mediators. Write your logic in your java class and store the property in synapse context in your custom class.
Using XSLT how do we render CDATA tag?
In xslt I dont want to create CDATA tag using text or declaring in xml
output tag using cdata-section-elements,
it should read it dynamically from input, if element value is around CDATA than
then xslt should render the same, as shown below
Input:
<A><![CDATA[Hello World]]></A>
XSLT Output :
<A><![CDATA[Hello World]]></A>
The data model XSLT/XPath/XQuery operate on does not know any CDATA sections so you can't simply preserve them as the tree you operate on simply contains a text node in both cases (i.e. for <foo>a & b</foo> and <foo><![CDATA[a & b]]></foo> the tree is a foo element containing a single text child node with the string value a & b).
So there is no way in pure XSLT to achieve what you want, unless you pre-process the input to convert CDATA sections into some structure like elements the XSLT data model allows you to detect and distinguish. Andrew Welch has http://andrewjwelch.com/lexev/ to do that in a Java environment.
Thus if you use an XSLT 2.0 processor like Saxon 9 with Java you could use that approach.
i am using postages Db for my services.When Null defined for any fields DSS giving Some object so my front end also getting same object .But they are expecting "NULL" instead of this they are getting {#nil":"true"}
How can i get NULL value As NULL only and its creating its own name space also for this row
http://www.w3.org/2001/XMLSchema-instance"
username password
=========== ============
NULL NULL
kk a123
for above i am getting like this fro WSO2dss side
<Datalist>
<username xmlns="http:sps.in" xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<password xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</Datalist>
from my wso2esb side i am getting JSON like this
{"Body":{"Datalist":{"username":{"#nil":"true"},"password":{"#nil":"true"}}}}
But my front end service expecting in this below format where can modify for above this
{"Body":{"Datalist":{"username":"NULL","password":"NULL"}}}
In XML, the standard/recommended way to indicate that the value of a particular XML node is NULL, is via the notation [xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"]. If any standard XML parser comes across this particular notation, the element which contains the aforesaid notation is treated as an element with NULL as its value. This is particularly useful, when there are values such as "NULL" (not the actual NULL but a string containing the characters, "N","U","L","L") as there's no way to distinguish the real NULL values and "NULL" character streams.
Therefore, the best way to handle this scenario would be to check for #nil attribute at client side while parsing the JSON content that returns as the response of the web service invocation. Alternatively, you can add an XSLT transformation at the data service query level to transform the response (in XML format which gets processed internally within DSS before returning JSON content) the way you want so that you'll be able to add any custom rules and transform the response before it is returned to the client side. You can refer to the sample data service named "ExcelSampleService.dbs" located in "DSS_HOME/samples/dbs/excel/" directory in the product package for an example on how this is done.
Hope this helps!
Regards,
Prabath
It worked for me. I just put that two atributtes (xsi:nil, xmlns:xsi) into my XML by changing my AS (Application Server) like this:
public static OMElement addAttributeNull(OMElement parametro){
parametro.addAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance", null);
parametro.addAttribute("xsi:nil", "true", null);
return parametro;
}
I have an xml file in this format
<xml>
<entity>&acces;</entity>
</xml>
I am trying to retrieve the value of entity using <xsl:value-of select="xml/entity"> but it's returning empty string. Any hint how to achieve this?
Is that what your XML looks like?
It is missing the entity declaration or DTD reference that would define that entity. Your XML parser should throw an error, but may just be silently "skipping" it, so when you attempt to obtain the value, it is empty.