2010-11-22 12 views
0

私は、jQueryを使用してXMLを操作するのが初めてです。 jQueryを使用して複数のXMLノードの特定の属性を検索する方法

は、私は次のようになり、XML文書を持って言う:

<sitemap> 
    <products name="products" url="/products.html"> 
    <shirts name="women's shirts" url="/womens-shirts.html"> 
    <shoes name="women's shoe" url="/womens-shoes.html"> 
    <pants....> 
    </products> 
    <services> 
    <shopping> 
    <consultation> 
    </services> 
</sitemap> 

など、どこの各子ノード名とURL(私はwindow.locationのに基づいてブレッドクラムを投入しています両方を持っています.pathname)。私は特定のURLを検索したい(それはあなたのページ上のものと一致していなければならない)。これは親ノードか子ノードのいずれかのノードに置くことができる。私が探しているノードを指定せずにこれを行うにはどうすればよいですか?

ありがとうございます!

答えて

1

アスタリスクを使用して、任意の要素名を指定するには:あなたの応答のための

*[url='/products.html'] 
+0

感謝を! –

+0

これはどうでしょうか? –

+0

$(ドキュメント).ready(関数(){ \t $アヤックス({ タイプ: "GET"、 \t \t URL: "/_assets/xml/sitemap.xml"、 \t \tデータ型: "XML" 、 \t \tエラー:関数(){アラート( 'の読み込みエラーXML文書');}、 \t \t成功:parseXML }); 関数parseXML(XML){ \t \t VARパス名= window.locationの.pathname; $(xml).find(* [url =パス名])。それぞれ(function()) \t { \t \t alert(url); \t}); \t} }); –

関連する問題