I have an XML file as shown below.
<?xml version="1.0" encoding="UTF-8"?>
<body xmlns:bons0="http://DistinctAppSample" xmlns:httpsca="http://www.ibm.com/xmlns/prod/websphere/http/sca/6.1.0" xmlns:mq="http://www.ibm.com/xmlns/prod/websphere/mq/sca/6.0.0" xmlns:smo="http://www.ibm.com/websphere/sibx/smo/v6.0.1" xmlns:tns="http://DistinctAppSample/TestInf" xmlns:tns1="http://www.w3.org/2005/08/addressing" xmlns:tns2="http://www.w3.org/2003/05/soap-envelope" xmlns:tns_1="wsdl.http://DistinctAppSample/TestInf" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="foo.xsd">
<tns:testOperation>
<input>
<request>
<salary>100</salary>
<newSalary>101</newSalary>
</request>
<request>
<salary>123</salary>
<newSalary>101</newSalary>
</request>
<request>
<salary>101</salary>
<newSalary>123</newSalary>
</request>
<request>
<salary>100</salary>
<newSalary>101</newSalary>
</request>
</input>
</tns:testOperation>
</body>
I am trying to remove the duplicate "request" node where we have same salary and newSalary value (node1 and node4 has same values. So I need to consider only one node). Sample output is follows.
<?xml version="1.0" encoding="UTF-8"?>
<body xmlns:bons0="http://DistinctAppSample" xmlns:httpsca="http://www.ibm.com/xmlns/prod/websphere/http/sca/6.1.0" xmlns:mq="http://www.ibm.com/xmlns/prod/websphere/mq/sca/6.0.0" xmlns:smo="http://www.ibm.com/websphere/sibx/smo/v6.0.1" xmlns:tns="http://DistinctAppSample/TestInf" xmlns:tns1="http://www.w3.org/2005/08/addressing" xmlns:tns2="http://www.w3.org/2003/05/soap-envelope" xmlns:tns_1="wsdl.http://DistinctAppSample/TestInf" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="foo.xsd">
<tns:testOperation>
<input>
<request>
<salary>100</salary>
<newSalary>101</newSalary>
</request>
<request>
<salary>123</salary>
<newSalary>101</newSalary>
</request>
<request>
<salary>101</salary>
<newSalary>123</newSalary>
</request>
</input>
</tns:testOperation>
</body>
I would need to write a XPATH to achieve this Scenario.
I have tried //request[not(salary = preceding::salary and newSalary = preceding::newSalary)] but it is not working as expected. Any suggesition would be much appriciated.
Thanks.
Related
I'm newbie about validation on programming. Like Checking string and checking field input empty or not. Maybe anyone in here can share me about simple sample validation rule about string and checking field to me with XSLT. Thanks
First of all, XSLT is for XML transformations and if you want to do schema validations you should be looking at XSD validations. Having said that below is how you can use XSLT to validate a message and generate a payload.
Let's say you have a Payload like the below.
<Request>
<messages>
<message>
<id>123</id>
<name>Not Empty</name>
</message>
<message>
<id>234</id>
<name></name>
</message>
</messages>
</Request>
In the above payload, you want to check each message and check whether the name is empty or not. Inorder to validate this you can use XSLT. First create a XSLT as a LocalEntry in the local-entries directory. You can use the following content. (You can create your XSLT in the registry as well)
<?xml version="1.0" encoding="UTF-8"?>
<localEntry key="LOCAL_XSLT_NullCheck" xmlns="http://ws.apache.org/ns/synapse">
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output encoding="UTF-8" indent="yes" method="xml" omit-xml-declaration="yes"/>
<xsl:template match="/">
<Response>
<!-- Iterating through message elements -->
<xsl:for-each select="//messages/message">
<message>
<messageID><xsl:value-of select="id/text()"/></messageID>
<xsl:choose>
<!-- Check if name is empty -->
<xsl:when test="boolean(name/text())">
<isEmpty>false</isEmpty>
</xsl:when>
<xsl:otherwise>
<isEmpty>true</isEmpty>
</xsl:otherwise>
</xsl:choose>
</message>
</xsl:for-each>
</Response>
</xsl:template>
</xsl:stylesheet>
</localEntry>
Next create a API to consume your request and to validate the payload and then to generate the response.
<?xml version="1.0" encoding="UTF-8"?>
<api context="/xslt" name="TestAPI" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST">
<inSequence>
<log level="full">
<property name="Message" value="Incoming Message"/>
</log>
<xslt key="LOCAL_XSLT_NullCheck"/>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
Now once you invoke the API with the aforementioned message. You should see the following response.
<Response xmlns="http://ws.apache.org/ns/synapse">
<message>
<messageID>123</messageID>
<isEmpty>false</isEmpty>
</message>
<message>
<messageID>234</messageID>
<isEmpty>true</isEmpty>
</message>
</Response>
You ca read more on XSLT mediator from here. You can also consider using FastXSLT Mediator as well based on your requirement. Read more on XSLT from here.
i am sending purchase request in xml with createcustomer profile.
customerProfileId is returning good but customerpayment profile id is returning in field customerPaymentProfileIdList > numericString.
here is full response.
<?xml version="1.0" encoding="utf-8"?>
<createTransactionResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
<messages>
<resultCode>Ok</resultCode>
<message>
<code>I00001</code>
<text>Successful.</text>
</message>
</messages>
<transactionResponse>
<responseCode>1</responseCode>
<authCode>R7BVRZ</authCode>
<avsResultCode>Y</avsResultCode>
<cvvResultCode>P</cvvResultCode>
<cavvResultCode>2</cavvResultCode>
<transId>60032752664</transId>
<refTransID />
<transHash>C1F3242645F7F118D709452E5758AF35</transHash>
<testRequest>0</testRequest>
<accountNumber>XXXX0015</accountNumber>
<accountType>MasterCard</accountType>
<messages>
<message>
<code>1</code>
<description>This transaction has been approved.</description>
</message>
</messages>
<transHashSha2 />
</transactionResponse>
<profileResponse>
<messages>
<resultCode>Ok</resultCode>
<message>
<code>I00001</code>
<text>Successful.</text>
</message>
</messages>
<customerProfileId>1813409569</customerProfileId>
<customerPaymentProfileIdList>
<numericString>1808086931</numericString>
</customerPaymentProfileIdList>
<customerShippingAddressIdList />
</profileResponse>
</createTransactionResponse>
Currently I use Doctrine2 with value object, it's working great. The problem when I use value object with only one field, for example:
$this->repository->findBy(array('email' => 'name#domain.com')); //This is not working
$this->repository->findBy(array('email.email' => 'name#domain.com')); //This is work great
The question is, how to make $this->repository->findBy(array('email' => 'name#domain.com')); working?
This is my doctrine mapping
User.orm.xml
<!-- User.orm.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"
xmlns:gedmo="http://gediminasm.org/schemas/orm/doctrine-extensions-mapping">
<entity name="Domain\User\Entity\User" table="users" repository-class="Infrastructure\User\Repository\UserRepository">
<id name="id" type="guid">
<generator strategy="UUID"/>
</id>
<embedded name="email" class="Shared\ValueObject\Email" use-column-prefix="false" />
</entity>
</doctrine-mapping>
Email.orm.xml
<!-- Email.orm.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<embeddable name="Shared\ValueObject\Email">
<field name="email" type="string" length="80" />
</embeddable>
</doctrine-mapping>
Thank you for your help, and sorry for my bad english.
Unfortunately according to code this is not possible. Field name always be
$property . "." . $fieldMapping['fieldName'];
I want to have following xml file:
<?xml version="1.0" encoding="UTF8" ?>
<!DOCTYPE people SYSTEM "XMLSpyDTD.dtd">
<report>
<Start>
<date format="ddMMyy" val="Tue Jun 09 2015
" />
<time format="hhmm" val="11:43:06 " />
</Start>
<test name="Testadd" executed="Yes">
<discription>
<![CDATA[Add two numbers]]>
</discription>
<targets>
<target threaded="false">C++</target>
</targets>
</test>
</report>
So, kindly suggest me how may i generate it using libxml2 in c++?
I have such a problem here: service with which I integrating, has a strange format.
takes the value:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" >
<soapenv:Header/>
<soapenv:Body>
<Operation>
<XmlStream>
<Name>GetPolicys</Name>
<XML><![CDATA[
<Arra>
<Ul>
<LastName>---</LastName>
<FirstName>---</FirstName>
<FatherName>---</FatherName>
<Birthday>---</Birthday>
</Ul>
</Array>]]>
</XML>
</XmlStream>
</Operation>
</soapenv:Body>
</soapenv:Envelope>
and returns
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<OperationResponse>
<OperationResult>
<ResultName>GetPolicys</ResultName>
<XML><![CDATA[<?xml version="1.0" encoding="utf-8"?>
<Array>
<Ul>
<LastName>----</LastName>
<FirstName>----</FirstName>
<FatherName>---</FatherName>
<Birthday>--</Birthday>
<PolicyList>
----
</PolicyList>
</Ul>
</Array>]]>
</XML>
</OperationResult>
</OperationResponse>
</s:Body>
</s:Envelope>
create a nested message I got. As it wrapped in a CDATA? How to get it from CDATA in the preparation?
You can use XSLT to pick out from CDATA..