【问题标题】:Import XML from Web Service into XML?将 XML 从 Web 服务导入 XML?
【发布时间】:2013-10-16 18:35:01
【问题描述】:

我正在使用 joomla 3.1 站点,php 5.3.27。我将数据存储在一个 ms sql server 2008 r2 数据库中,该数据库是通过 wsdl soap Web 服务移植出来的。

在来自 Web 服务的 xml 中,有一个“服务”列表,每个都有我需要提取的“serviceid”和“servicename”节点。

<services count="9">
   <service>
      <serviceid>1</serviceid>
      <servicename>Training</servicename>
      ... and some other nodes ...
   </service>
   <service>
      <serviceid>2</serviceid>
      <servicename>Faculty/Staff Email</servicename>
      ... and some other nodes ...
   </service>
</services>

这些 serviceid 和 servicenames 需要进入我的 mvc 结构中视图的 default.xml 文件。现在这些值是硬编码的。

<metadata>
<layout title="Service" option="service">
    <help
        key = "Display a service from the catalog"
    />
    <message>
        Display a service from the catalog
    </message>
</layout>

<!-- Add fields to the request variables for the layout. -->
<fields name="request">
    <fieldset name="request"
        addfieldpath="/administrator/components/com_content/models/fields">

        <field name="id" type="modal_article"
            label="COM_CONTENT_FIELD_SELECT_ARTICLE_LABEL"
            required="true"
            edit="true"
            clear="false"
            description="COM_CONTENT_FIELD_SELECT_ARTICLE_DESC"
            default="36"
        />
        <field name="serviceID" type="list"
            label="Service ID"
            required="true"
            edit="true"
            clear="false"
            description="The service to display"
        >
            <option value="1">Training</option>
            <option value="2">Faculty/Staff Email</option>
            <option value="3">Email List Services</option>
            <option value="4">Mass Email Services</option>
            <option value="5">Email Encryption</option>
        </field>
    </fieldset>
</fields>

等等……

我遇到问题的部分是将它从肥皂响应中获取到另一个 xml 文件中。我可以创建一个可以循环遍历数组并创建选项标签的 php 文档,但是从 xml 到 php 再到 xml 似乎很愚蠢,而且我仍然会遇到同样的问题,即尝试将此外部数据导入右侧放在这个文件里。

长期潜伏者,第一次发帖,所以如果我违反了协议,请原谅,我将承担我鞭打的位置。如果我不清楚或者您需要更多信息,请告诉我。提前致谢!

【问题讨论】:

    标签: php xml web-services soap


    【解决方案1】:

    使用 XSLT 在目标 XML 中注入源 XML 值。这正是 XSL 语言的用途。

    这样,您可以将模板(在您的情况下为 default.xml)与源值分开,并且无需任何 PHP 代码即可更改它。

    PHP 有很多库来处理 XSLT 文件,每个库都有自己的优点和问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-04-05
      • 2011-09-11
      • 1970-01-01
      • 1970-01-01
      • 2023-03-12
      • 1970-01-01
      • 2014-03-23
      相关资源
      最近更新 更多