1

次のようなノードを持つドキュメントを解析しようとしています。

<doc>
<results>
        <result xmlns="http://www.inktomi.com/">
            <title>Senate Panel to Review Election Unit Sale</title>
        </result>
</result>
</doc>

ただし、結果の名前空間とノード名は異なる場合があります。そうでない場合、これは機能します:

results..*::title //>Senate Panel to ...

しかし、これを行うことはできません:

var myvar = "title"
results..*::[myvar] 

手がかりはありますか?

4

3 に答える 3

0

どうやら、子にアクセスする角括弧の方法と、名前空間を選択するための*の使用は一緒に機能しません

var doc:XML = 
<doc> 
    <results> 
        <result xmlns="http://www.inktomi.com/">  
            <title>Senate Panel to Review Election Unit Sale</title> 
        </result>
    </results>
</doc>;
var ns:Namespace = new Namespace("http://www.inktomi.com/");
trace(doc..*::title.toXMLString()); //These three 
trace(doc.results.*::result);       //lines compile
trace(doc.results.ns::["result"]);  //and run as expected
//This commented out line compiles but throws 2 verify errors in the run time
//trace(doc.results.*::["result"]); 

VerificationError:エラー#1080:名前空間の値が無効です。
ReferenceError:エラー#1065:変数テストが定義されていません。

VerificationErrorクラスは、不正な形式または破損したSWFファイルが検出されたときに発生するエラーを表します。

于 2009-10-10T09:47:57.203 に答える
0

E4X ソリューションではありませんが、xml.namespaceDeclarations() によって返されるすべての使用可能な名前空間を反復処理してから、最初の子を取得するか、角かっこを使用してそれにアクセスできます。

xml を事前に解析し、すべての名前空間を簡単な修正と同じにすることもできます。

于 2009-10-12T01:48:20.160 に答える