2010-01-06 44 views
0

我已經得到了以下XML,並且想要在Safari瀏覽器中使用JQuery解析它。我只想打印出userName,並且需要一些關於如何寫入函數的幫助。在Safari中使用jQuery解析XML

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
<ns3:Account xmlns:ns2="http://oec.api.opsource.net/schemas/organization" .. > 
<ns3:userName>rdyer</ns3:userName> 
<ns3:fullName>Joe Public</ns3:fullName> 
<ns3:firstName>Joe</ns3:firstName> 
<ns3:lastName>Public</ns3:lastName> 
<ns3:emailAddress>[email protected]</ns3:emailAddress> 
<ns3:orgId>1831c1a9-9c03-44df-a5a4-f2a4662d6bde</ns3:orgId> 
<ns3:roles> 
<ns3:role> 
<ns3:name>primary administrator</ns3:name> 
</ns3:role> 
</ns3:roles> 
</ns3:Account> 
+0

類似:http://stackoverflow.com/questions/853740/jquery-xml-parsing-with-namespaces – gnarf 2010-01-06 06:49:51

回答

1

jQuery的1.3.2顯然下來$('ns3\\:userName',xml)休息下webkit的,但不要害怕,灒有力量了,就過濾的屬性 '節點名稱' 嘗試$('[nodeName=ns3:userName]',xml)

例子:

<div id='username'></div> 
<script> 
$(function() { 
    // When the DOM is ready - perform AJAX to get the XML: 
    $.get('/myxml.xml', {}, function(xml) { 
    var $username = $("[nodeName=ns3:userName]", xml); 
    // put the text from our node into the text of the empty div: 
    $("#username").text($username.text()); 
    }, "xml"); 
}); 
</script> 
+0

如果我沒有使用jQuery,該怎麼辦?任何其他選項? – Simon 2010-01-06 07:00:43

+0

該方法適用於jQuery就好(聲音是它的一部分)對不起,如果這是令人困惑......我不確定非jQuery解析它的方式。 – gnarf 2010-01-06 07:03:45