0

私は現在 Jquery を使用しており、プロジェクト全体を sharepoint クライアント オブジェクト モデルのみを使用して実行する必要があります (そのため、サーバー側のコーディングを利用できません)。(いくつかの文字列を一緒に追加することによって) xml 構造を作成し、それを jquery var 変数に格納しました。今、私の変数の内容は次のようになります

<Collection xmlns="http://schemas.microsoft.com/collection/metadata/2009"
xmlns:ui="http://schemas.microsoft.com/livelabs/pivot/collection/2009"
SchemaVersion="1" Name="listname">
    <FacetCategories>
        <FacetCategory Name="Title" Type="String" />
        <FacetCategory Name="Created By" Type="String" />
        <FacetCategory Name="Modified By" Type="String" />
    </FacetCategories>
    <Items ImgBase="http://460d87.dzc">
        <Item Id="0" Img="#0" Name="Name1" Href="http://site/1_.000">
            <Facets>
                <Facet Name="Title">
                    <String Value="Name1" />
                </Facet>
            </Facets>
        </Item>
    </Items>
</collection>

この変数を、純粋に jquery に基づいて xml コンテンツに変換したいと考えています。ParseXml() メソッドを使用しましたが、alert() で出力を確認できません。これで私を助けてください。

4

2 に答える 2

0

ネイティブの組み込み XML パーサーを使用するだけです。

var parser, xml;
if (window.DOMParser) {
    parser = new DOMParser();
    xml = parser.parseFromString(str, "text/xml");
}
else { // IE
    xml = new ActiveXObject("Microsoft.XMLDOM");
    xml.async = "false";
    xml.loadXML(str);
}

var nodes = xml.getElementsByTagName('FacetCategory');

var i, l = nodes.length, items = [];
for (i = 0; i < l; i++) {
    console.log(nodes[i].getAttribute('Name'));
}

http://jsfiddle.net/QqtMa/

于 2013-03-18T11:27:33.863 に答える
0

xml が無効です。ルート要素はありますCollectionが、終了タグがcollectionsmallcであるため、パーサーが失敗しています

于 2013-03-18T11:33:54.790 に答える