2009-07-13 24 views
3

カスタムスキーマデータをAJAX呼び出しから取得しています。jQueryを使用して解析する必要があります。どのようにこれを行うにはどのようなアイデア?ここでjQueryを使用してカスタムXMLスキーマを解析します。

はXMLです:

<xsd:get_customer_summary_response xmlns:xsd="http://com/acmeco/ovm/cas/xsd"> 
    <xsd:customer_details> 
    <typ:phone_number xmlns:typ="http://com/acmeco/ovm/cas/types">1.555.5553002</typ:phone_number> 
    <typ:timezone xsi:nil="true" xmlns:typ="http://com/acmeco/ovm/cas/types" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/> 
    <typ:zipcode xmlns:typ="http://com/acmeco/ovm/cas/types">3002</typ:zipcode> 
... 
    </xsd:customer_details> 
</xsd:get_customer_summary_response> 

そしてここでは、AJAX呼び出しがあります。私は通常のXMLを以下のように解析できますが、XSDのものは解析できません。

$.ajax({ 
     type: "GET", 
     url: "so.xml", 

     dataType: "html", 

     success: function(returnhtml){ 
    $("customer_details", returnhtml).find("zipcode").each(function() { 
     alert($(this).text()); 
    }); 
    }, etc. 

答えて

0

私はこれをテストしていませんが、あなたは試してみました:

$.ajax({ 
    type: "GET", 
    url: "so.xml", 

    dataType: "html", 

    success: function(returnhtml){ 
    $(returnhtml).find("customer_details zipcode").each(function() { 
     alert($(this).text()); 
    }); 
}, etc. 

のjQueryのcontext引数には、DOM要素を期待しています。

returnhtmlは、dataTypeをHTMLとして設定すると、jQuery's ajax() documentationに従うHTML文字列になります。 XML文字列の場合は、jQueryをコンテキストとして使用する前に、最初に作業できる要素にjQueryを変換する必要があります。

0

$.parseXMLを使用できます。

success: function (returnhtml) { 
    var parsedXML = $.parseXML(returnhtml); 
    $(parsedXML).find("zipcode").each(function() { 
     alert($(this).text()); 
    }); 
} 

https://jsfiddle.net/chukanov/jjt894dc/

関連する問題