Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将xml标记加载到javascript数组中_Javascript_Xml - Fatal编程技术网

将xml标记加载到javascript数组中

将xml标记加载到javascript数组中,javascript,xml,Javascript,Xml,我有一个javascript测试,我正试图使用xml文件从外部加载它。有24个问题。我想将问题加载到“myQuestions”数组中,并将每个答案加载到a、b、c和d数组中。xml文件名为MYFile.xml,如有任何帮助,将不胜感激。谢谢你 <question> <text><![CDATA[<b>Question 1 Text</b>]]> </text> <answers> <text correct

我有一个javascript测试,我正试图使用xml文件从外部加载它。有24个问题。我想将问题加载到“myQuestions”数组中,并将每个答案加载到a、b、c和d数组中。xml文件名为MYFile.xml,如有任何帮助,将不胜感激。谢谢你

<question>
<text><![CDATA[<b>Question 1 Text</b>]]> </text>
<answers>
<text correct="1">1Answer 1 Text</text>
<text correct="0">1Answer 2 Text</text>
<text correct="0">1Answer 3 Text</text>
<text correct="0">1Answer 4 Text</text>
</answers>
</question>
<question>
<text><![CDATA[<b>Question 2 Text</b>]]> </text>
<answers>
<text correct="1">2Answer 1 Text</text>
<text correct="0">2Answer 2 Text</text>
<text correct="0">2Answer 3 Text</text>
<text correct="0">2Answer 4 Text</text>
</answers>
</question>

问题1文本]]>
1回答1文本
1答案2文本
1答案3文本
1答案4文本
问题2文本]]>
2答案1文本
2答案2文本
2答案3文本
2答案4文本
使用javascript中最快的xml解析器怎么样

var xml=require(“txml”);
常数fs=要求('fs');
const data=fs.readFileSync('MYFile.xml').toString();
const dom=xml(数据);
log(JSON.stringify(
SimplifiedLossless(dom),未定义''
));
这将打印:

{
  "question": [
    {
      "text": "<b>Question 1 Text</b>",
      "answers": {
        "text": [
          {
            "_attributes": {
              "correct": "1"
            },
            "value": "1Answer 1 Text"
          },
          {
            "_attributes": {
              "correct": "0"
            },
            "value": "1Answer 2 Text"
          },
          {
            "_attributes": {
              "correct": "0"
            },
            "value": "1Answer 3 Text"
          },
          {
            "_attributes": {
              "correct": "0"
            },
            "value": "1Answer 4 Text"
          }
        ]
      }
    },
    {
      "text": "<b>Question 2 Text</b>",
      "answers": {
        "text": [
          {
            "_attributes": {
              "correct": "1"
            },
            "value": "2Answer 1 Text"
          },
          {
            "_attributes": {
              "correct": "0"
            },
            "value": "2Answer 2 Text"
          },
          {
            "_attributes": {
              "correct": "0"
            },
            "value": "2Answer 3 Text"
          },
          {
            "_attributes": {
              "correct": "0"
            },
            "value": "2Answer 4 Text"
          }
        ]
      }
    }
  ]
}
{
“问题”:[
{
“文本”:“问题1文本”,
“答案”:{
“文本”:[
{
“_属性”:{
“正确”:“1”
},
“值”:“1回答1文本”
},
{
“_属性”:{
“正确”:“0”
},
“值”:“1回答2文本”
},
{
“_属性”:{
“正确”:“0”
},
“值”:“1回答3文本”
},
{
“_属性”:{
“正确”:“0”
},
“值”:“1回答4文本”
}
]
}
},
{
“文本”:“问题2文本”,
“答案”:{
“文本”:[
{
“_属性”:{
“正确”:“1”
},
“值”:“2回答1文本”
},
{
“_属性”:{
“正确”:“0”
},
“值”:“2回答2文本”
},
{
“_属性”:{
“正确”:“0”
},
“值”:“2回答3文本”
},
{
“_属性”:{
“正确”:“0”
},
“值”:“2回答4文本”
}
]
}
}
]
}

我正在使用基本上是javascript的Animate CC canvas。我希望将所有问题标签添加到myquestions数组中,然后将其他问题标签添加到另一个数组中。我觉得你写这篇文章的方式有点让我难以理解。