0

そのため、XML ファイルを as3 にロードしたところ、正しくロードされ、トレースできるので正しいファイルであることがわかりますが、特定のノードをトレースしようとすると、出力ウィンドウが空のままになります。これが私のコードです:

var _textes:XML;
loader = new URLLoader();
requete = new URLRequest("texte_fr.xml");
loader.load(requete);
loader.addEventListener(Event.COMPLETE, finChargement);

function finChargement(pEvt:Event){
    _textes= new XML(pEvt.target.data);
}

_textes をトレースすると、すべての XML コードが表示されますが、XML ファイル内のノードをトレースしようとすると、何も表示されません。たとえば、_textes.instructions をトレースしようとすると、何も表示されません。私は何を間違っていますか?ここに私のXMLファイルがあります:

<?xml version="1.0" encoding="utf-8"?>
<textes version="1" xmlns="http://xspf.org/ns/0/">
<instructions>
    Some text
</instructions>
<niveau1>
    <reussi>
        Some other text
    </reussi>
    <fail>
        Some other text
    </fail>
</niveau1>
<niveau2>
    <reussi>
        Some other text
    </reussi>
    <fail>
        Some other text
    </fail>
</niveau2>
<niveau3>
    <reussi>
        Some other text
    </reussi>
    <fail>
        Some other text
    </fail>
</niveau3>
<perdu>
    Some other text
</perdu>
<general>
    Some other text
</general>
<boutons>
    Some other text
</boutons>
</textes>
4

2 に答える 2

0

編集: @fsbmainは、私が回答を編集しているときに、適切な解決策で私を打ち負かしました:)とにかく、これが私の改訂された回答です...

xmlを使用してノードを参照していないため、そのノードの内容を取得していませんドキュメントの名前空間。

これは、xml ノードにアクセスする方法です。

function finChargement(pEvt:Event){
    _textes= new XML(pEvt.target.data);
    // The namespace in your xml document:
    var ns:Namespace = new Namespace("http://xspf.org/ns/0/");
    default xml namespace = ns;
    trace(_textes.instructions);
}  

詳細については、このページを参照してください

名前空間は、データを分離または識別するために使用されます。XML では、1 つ以上のノードを特定の URI (Uniform Resource Identifier) に関連付けるために使用されます。名前空間を持つ要素は、他のタグと同じタグ名を持つことができますが、URI との関連付けによりそれらから分離されます。

次に例を示します。

次の xml データがあるとします。

<?xml version="1.0" encoding="utf-8"?>
<textes>
    <instructions  xmlns="http://xspf.org/ns/0/">
        Node 1
    </instructions>
    <instructions  xmlns="http://xspf.org/ns/1/">
        Node 2
    </instructions>
</textes>

最初のノードの名前空間を使用して「指示」ノードにアクセスすると、最初のノードの内容が取得されます。

function finChargement(pEvt:Event){
    _textes= new XML(pEvt.target.data);
    var ns:Namespace = new Namespace("http://xspf.org/ns/0/");
    default xml namespace = ns;
    trace(_textes.instructions);
    // Will output "Node 1"
}  

2 番目のノードの名前空間を使用すると、2 番目のノードのコンテンツが取得されます。

function finChargement(pEvt:Event){
    _textes= new XML(pEvt.target.data);
    var ns:Namespace = new Namespace("http://xspf.org/ns/1/");
    default xml namespace = ns;
    trace(_textes.instructions);
    // Will output "Node 2"
}
于 2013-01-13T19:24:23.083 に答える
0

次のコードで名前空間を指定せずに e4x を使用するために、デフォルトの名前空間を空に設定できます: var xml:XML = Some text

    var ns:Namespace = xml.namespace("");
    default xml namespace = ns;
    trace(xml.instructions.toString()); //output "Some text"
于 2013-01-13T19:50:33.690 に答える