2

如何使用 Smooks 配置设置 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>
4

2 回答 2

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 内的本地条目,它就像一个魅力。

问候。

于 2015-01-26T19:02:57.490 回答
0

似乎 smooks 没有能力在转换过程中添加命名空间。您可以做的是,在 csv 到 xml 转换完成后进行 xslt 转换。您可以在 WSO2 ESB 中使用 xslt 中介或负载工厂中介。

于 2014-04-05T15:22:16.860 回答