0

我有这个 xml 文件,我想从中获取值:

  <test> 
        <item>
            <question audio='audio/AB2001Q.mp3' category='Alertness'>Before you make a U-turn in the road, you should</question>
            <description audio='audio/s1,1.mp3'>If you want to make a U-turn, slow down and ensure that the road is clear in both directions. Make sure that the road is wide enough to carry out the manoeuvre safely.</description>
            <image ></image>
            <answers>
                <answer title='a' audio='audio/AB2001A.mp3'>give an arm signal as well as using your indicators</answer>
                <answer title='b' audio='audio/AB2001B.mp3'>signal so that other drivers can slow down for you</answer>
                <answer title='c' audio='audio/AB2001C.mp3'>look over your shoulder for a final check</answer>
                <answer title='d' audio='audio/AB2001D.mp3'>select a higher gear than normal</answer>
            </answers>
            <correctAnswers>
                <answer>c</answer>
            </correctAnswers>
        </item>
 </test>

如何获取问题音频的文本内容和问题文本,例如

“audio/AB2001Q.mp3”是问题音频

“在你掉头之前,你应该”是问题文本

这是我到目前为止所拥有的:

var doc = Ti.XML.parseString(blob);
var branch = doc.getElementsByTagName('item').item(0);

我对 xml 很陌生!

4

2 回答 2

1

这与您在 HTML 中所做的类似,例如:

var branch = doc.getElementsByTagName('item')[0];
var question = branch.getElementsByTagName('question')[0];
var q1Text = question.childNodes[0].nodeValue;
var q1Audio = question.getAttribute['audio'];

(如果你使用 jQuery、Sencha 或任何其他库会更容易一些)

于 2013-01-08T17:05:13.393 回答
0

获得 Item 后,您可以使用getAttribute('audio')来获取该属性所代表的信息。但请记住,如果您有一个包含许多这些标签的大文件,您可能需要考虑一种不同的方法来获取数据。

于 2013-01-08T17:31:33.090 回答