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++?
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 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.
I need to remove the attribute tags without any value in an xml file using ant script
Below is the XML I have:
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>DoNothingTest</members>
<name>ApexClass</name>
</types>
<types>
</types>
<types>
</types>
<types>
</types>
<types>
</types>
<version>42.0</version>
</Package>
All the tags that does not have a nesting tag or value should be removed from this xml . The output should look like below:
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>DoNothingTest</members>
<name>ApexClass</name>
</types>
<version>42.0</version>
</Package>
How can I achieve this using ANT script?
I am using the below ant script to perform the job, however, it trims only one occurence of 'types' tag.
<!--Format the generated XML file -->
<target name="formatXML" depends="generatePackage.xml">
<property name="final-xml.file" value="temp/src/package.xml"/>
<for param="src-xml.absolute-path" list="${final-xml.file}">
<fileset dir="temp/src/" includes="*.xml"/>
<sequential>
<replaceregexp file="${final-xml.file}"
flags="s"
match="\s*(?:<\/([a-z]+)>)(\s*<\1>)"
replace=""/>
</sequential>
</for>
</target>
How to iterate over the xml file and replace all occurences of 'types' tags?
You can invoke an XSLT transformation from Ant using the XSLT ant task. A stylesheet to remove empty <types> elements in namespace http://soap.sforce.com/2006/04/metadata consists of a boilerplate identity rule to copy all elements unchanged, plus the rule
<xsl:template match="x:types[not(*) and not(text()[normalize-space()])]"
xmlns:x="http://soap.sforce.com/2006/04/metadata"/>
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'm having some trouble creating some custom web services in Magento. I'm trying to get the module configured properly and I can't seem to make the web services I've defined in the api.xml file show up under the user role setup in the admin area.
I've defined a custom module in app/etc shown here
ctp_GiftCards.xml:
<?xml version="1.0"?>
<config>
<modules>
<ctp_GiftCards>
<active>true</active>
<codePool>local</codePool>
</ctp_GiftCards>
</modules>
</config>
The module code is located in app/local/ctp/GiftCards/
Here is an example of the etc/api.xml:
<?xml version="1.0"?>
<config>
<api>
<resources>
<GiftCards translate="title" module="ctp_GiftCards">
<title>GiftCard webservices</title>
<acl>GiftCards/GiftCard</acl>
<methods>
<update translate="title" module="ctp_GiftCards">
<title>updates a giftcard account</title>
</update>
</methods>
<faults module="ctp_GiftCards">
<invalid_data>
<code>100</code>
<message>giftcard data invalid</message>
</invalid_data>
<card_pool_error>
<code>101</code>
<message>card pool for entry not updated</message>
</card_pool_error>
<cache_error>
<code>102</code>
<message>cache not reset</message>
</cache_error>
</faults>
</GiftCards>
</resources>
<acl>
<resources>
<GiftCards translate="title" module="ctp_GiftCards">
<title>GiftCards</title>
<sort_order>6</sort_order>
<GiftCard translate="title" module="ctp_GiftCards">
<title>GiftCard</title>
<update translate="title" module="ctp_GiftCards">
<title>Update</title>
</update>
</GiftCard>
</GiftCards>
</resources>
</acl>
</api>
</config>
and the etc/config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<ctp_GiftCards>
<version>0.1.0</version>
</ctp_GiftCards>
</modules>
<global>
<models>
<GiftCard>
<class>CTP_GiftCards_Model</class>
</GiftCard>
</models>
</global>
</config>
Any help would be much appreciated.
--edit--
I'm using mangeto pro 1.10
Don't use capital letter (GiftCards) in the name of xml tag inside the node. Moreover, your module's name contains both underscope (_) and capital letter (ctp_GiftCards) which will lead Magento to misunderstand.