如何使用 jQuery 和 AJAX 从 axis2 服务转换 xml?

发布于 2024-07-15 01:15:32 字数 1817 浏览 4 评论 0原文

我遇到了 axis2 和 ajax 的问题。 我使用 jQuery 的 ajax 函数从我的一项 Web 服务获取 xml,并使用 this jquery将结果 xml 转换为 html 的插件。

以下是服务返回的相关 xml 的示例。

<ns:getPatientsByDoctorResponse>
    <ns:return type="com.emolst.jdbc.PatientBean">
        <ax23:firstName>Bryce</ax23:firstName>
        <ax23:lastName>Thompson</ax23:lastName>
    </ns:return>
</ns:getPatientsByDoctorResponse>

我查看了从 jQuery ajax 调用获得的 xml Document 对象,它似乎从标签中剥离了名称空间,并使标签全部小写。 但是,我似乎无法让我的 xsl 模板识别任何标签。

这是我现在在 xsl 中的内容。

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" indent="yes"/>

    <xsl:template match="/">
        <option>success1</option>
        <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="//return">
        <option>success2</option>
        <option>
            <xsl:value-of select="firstname"/> <xsl:value-of select="lastname"/>
        </option>
    </xsl:template>
</xsl:transform>

我能得到的最好的就是 success1 选项。 我在这里找到了一些关于让axis2更好地使用ajax的信息,但这看起来可能把我的java服务客户端搞砸了。

这是有问题的 JavaScript。

$("select[name=patientlist]").transform({
    xml:{
        url:"/axis2/services/PatientService/getPatientsByDoctor",
        data {
            docKey: "6"
        },
        type:"GET",
        dataType:"xml"
    },
    xsl:"xsl/patients-option.xsl"
});

那么我是在做一些愚蠢的事情还是有更好的方法来做到这一点? 谢谢你的帮助。

I'm running into a problem with axis2 and ajax. I'm getting xml from one of my web services with jQuery's ajax functions, and using this jquery plugin to transform the result xml to html.

Here's an example of the relevant xml that the service returns.

<ns:getPatientsByDoctorResponse>
    <ns:return type="com.emolst.jdbc.PatientBean">
        <ax23:firstName>Bryce</ax23:firstName>
        <ax23:lastName>Thompson</ax23:lastName>
    </ns:return>
</ns:getPatientsByDoctorResponse>

I looked through the xml Document object that I get from the jQuery ajax call, and it seems to have stripped the namespaces from the tags and made the tags all lowercase. However, I can't seem to get my xsl templates to recognize any of the tags.

Here's what I have now in the xsl.

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" indent="yes"/>

    <xsl:template match="/">
        <option>success1</option>
        <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="//return">
        <option>success2</option>
        <option>
            <xsl:value-of select="firstname"/> <xsl:value-of select="lastname"/>
        </option>
    </xsl:template>
</xsl:transform>

The best I can get is the success1 option. I found some info here about making axis2 play nicer with ajax, but that looks like it might screw up the java service clients I have.

Here's the javascript in question.

$("select[name=patientlist]").transform({
    xml:{
        url:"/axis2/services/PatientService/getPatientsByDoctor",
        data {
            docKey: "6"
        },
        type:"GET",
        dataType:"xml"
    },
    xsl:"xsl/patients-option.xsl"
});

So am I doing something stupid or is there a better way to do this? Thanks for any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

茶色山野 2024-07-22 01:15:32

你说你认为命名空间已经消失了,但我认为它们没有。 他们为什么要这么做?

尝试忽略名称空间的转换,如下所示:

<xsl:transform 
  version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output method="html" indent="yes"/>

    <xsl:template match="/">
        <option>success1</option>
        <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="//*[local-name()='return']">
        <option>success2</option>
        <option>
            <xsl:value-of select="*[local-name()='firstname']"/>
            <xsl:text> </xsl:text>
            <xsl:value-of select="*[local-name()='lastname']"/>
        </option>
    </xsl:template>

</xsl:transform>

或正确使用它们的模板,如下所示:

<xsl:transform 
  version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:ax23="........ax23 namespace here........"
  xmlns:ns="........ns namespace here........"
>

    <xsl:output method="html" indent="yes"/>

    <xsl:template match="/">
        <option>success1</option>
        <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="ns:return">
        <option>success2</option>
        <option>
            <xsl:value-of select="ax23:firstname"/>
            <xsl:text> </xsl:text>
            <xsl:value-of select="ax23:lastname"/>
        </option>
    </xsl:template>

</xsl:transform>

You say that you think namespaces are gone, but I think they are not. Why should they?

Try a transformation that ignores namespaces, like this:

<xsl:transform 
  version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output method="html" indent="yes"/>

    <xsl:template match="/">
        <option>success1</option>
        <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="//*[local-name()='return']">
        <option>success2</option>
        <option>
            <xsl:value-of select="*[local-name()='firstname']"/>
            <xsl:text> </xsl:text>
            <xsl:value-of select="*[local-name()='lastname']"/>
        </option>
    </xsl:template>

</xsl:transform>

or a template that uses them correctly, like this:

<xsl:transform 
  version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:ax23="........ax23 namespace here........"
  xmlns:ns="........ns namespace here........"
>

    <xsl:output method="html" indent="yes"/>

    <xsl:template match="/">
        <option>success1</option>
        <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="ns:return">
        <option>success2</option>
        <option>
            <xsl:value-of select="ax23:firstname"/>
            <xsl:text> </xsl:text>
            <xsl:value-of select="ax23:lastname"/>
        </option>
    </xsl:template>

</xsl:transform>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文