如何使用Smooks config设置xml字段命名空间?
我想转换csv ...
TSX:EMB,99,100
进入XML ...
<ser:placeOrder xmlns:ser="http://services.samples" xmlns:xsd="http://services.samples/xsd">
<ser:order>
<xsd:price>10</xsd:price>
<xsd:quantity>100</xsd:quantity>
<xsd:symbol>TSX:EMB</xsd:symbol>
</ser:order>
</ser:placeOrder>
这是我的smooks配置...
<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd" xmlns:xsd="http://services.samples/xsd" xmlns:core="http://www.milyn.org/xsd/smooks/smooks-core-1.4.xsd" xmlns:csv="http://www.milyn.org/xsd/smooks/csv-1.2.xsd" xmlns:ser="http://services.samples">
<resource-config selector="org.xml.sax.driver">
<resource>org.milyn.csv.CSVReader</resource>
<param name="fields">xsd:symbol,xsd:price,xsd:quantity</param>
<param name="rootElementName">ser:placeOrder</param>
<param name="recordElementName">ser:order</param>
</resource-config>
</smooks-resource-list>
答案 0 :(得分:1)
这可能,但不是你使用的方式...例如,这是我的博客文章的配置,我将很快发布:
<?xml version="1.0" encoding="UTF-8"?>
<localEntry xmlns="http://ws.apache.org/ns/synapse" key="orderIncommingTransformer">
<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd" xmlns:csv="http://www.milyn.org/xsd/smooks/csv-1.2.xsd" xmlns:edi="http://www.milyn.org/xsd/smooks/edi-1.2.xsd" xmlns:ftl="http://www.milyn.org/xsd/smooks/freemarker-1.1.xsd">
<params>
<param name="stream.filter.type">SAX</param>
<param name="inputType">input.csv</param>
<param name="input.csv" type="input.type.actived">Workspace://MyRegistryResources/models/incomming_csv.csv</param>
<param name="default.serialization.on">false</param>
</params>
<csv:reader fields="orderid,customerid,date,price" recordElementName="AddOrder" rootElementName="AddOrder_batch_req" separator=","/>
<ftl:freemarker applyOnElement="#document">
<ftl:template><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<#list .vars["AddOrder_batch_req"] as AddOrder_batch_req>
<ns1:AddOrder_batch_req xmlns:ns1="http://wso2.org/sample/shop/order">
<#list .vars["AddOrder_batch_req"]["AddOrder"] as AddOrder>
<ns1:AddOrder>
<ns1:orderID>${.vars["AddOrder"]["orderid"]}</ns1:orderID>
<ns1:customerID>${.vars["AddOrder"]["customerid"]}</ns1:customerID>
<ns1:date>${.vars["AddOrder"]["date"]}</ns1:date>
<ns1:price>${.vars["AddOrder"]["price"]}</ns1:price>
</ns1:AddOrder>
</#list>
</ns1:AddOrder_batch_req>
</#list>
</soapenv:Body>
</soapenv:Envelope>]]></ftl:template>
<param name="modelSrc">Workspace://MyRegistryResources/models/outgoing_xml_from_csv.xml</param>
<param name="modelSrcType">XML</param>
<param name="messageType">XML</param>
<param name="templateDataProvider">input</param>
</ftl:freemarker>
<resource-config selector="#document">
<resource>org.milyn.delivery.DomModelCreator</resource>
</resource-config>
</smooks-resource-list>
</localEntry>
输出它:
<soapenv:Body>
<ns1:AddOrder_batch_req xmlns:ns1="http://wso2.org/sample/shop/order">
<ns1:AddOrder>
<ns1:orderID>1</ns1:orderID>
<ns1:customerID>1</ns1:customerID>
<ns1:date>2011-12-26T18:28:48.214+05:30</ns1:date>
<ns1:price>456.76</ns1:price>
</ns1:AddOrder>
<ns1:AddOrder>
<ns1:orderID>2</ns1:orderID>
<ns1:customerID>3</ns1:customerID>
<ns1:date>2011-12-27T18:28:48.214+05:30</ns1:date>
<ns1:price>451.76</ns1:price>
</ns1:AddOrder>
<ns1:AddOrder>
<ns1:orderID>3</ns1:orderID>
<ns1:customerID>3</ns1:customerID>
<ns1:date>2011-12-27T18:28:48.214+05:30</ns1:date>
<ns1:price>451.76</ns1:price>
</ns1:AddOrder>
</ns1:AddOrder_batch_req>
</soapenv:Body>
使用命名空间。 我使用DVS 3.7.1进行此smooks配置并复制/粘贴到WSO2 ESB 4.8.1中的本地条目,它就像魅力一样。
问候。
答案 1 :(得分:0)
似乎smooks无法在转换期间添加命名空间。你可以做的是,在csv到xml转换完成后进行xslt转换。您可以在WSO2 ESB中使用xslt介体或有效负载工厂介体。