Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.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
是否可以在Javascript xpath中获取父节点属性的值_Javascript_Xml_Xpath - Fatal编程技术网

是否可以在Javascript xpath中获取父节点属性的值

是否可以在Javascript xpath中获取父节点属性的值,javascript,xml,xpath,Javascript,Xml,Xpath,我有下面的代码工作得很好。它在我的xml文件中搜索特定分支(“str”分支)的所有“output_text”节点,然后将文本写入表中。问题是,我真的想得到父节点属性的值(总id值)。这样,我的表行将是两列:总体ID和结果。 我可以在VB/asp xpath中实现这一点,但我正在尝试为移动设备制作客户端版本。 以下是xml的一个片段: <curriculum> <strand id="Dance"> <strand_text>Dance</stran

我有下面的代码工作得很好。它在我的xml文件中搜索特定分支(“str”分支)的所有“output_text”节点,然后将文本写入表中。问题是,我真的想得到父节点属性的值(总id值)。这样,我的表行将是两列:总体ID和结果。 我可以在VB/asp xpath中实现这一点,但我正在尝试为移动设备制作客户端版本。 以下是xml的一个片段:

 <curriculum>
 <strand id="Dance">
 <strand_text>Dance</strand_text>
<overalls>
  <overall id="A1">
    <overall_text>Creating and Presenting: apply the creative process (see pages 19-22) to the composition of simple dance phrases, using the elements of dance to communicate feelings and ideas</overall_text>
    <specifics>
      <specific></specific>
    </specifics>
  </overall>
  <overall id="A2">
    <overall_text>Reflecting, Responding, and Analysing: apply the critical analysis process (see pages 23-28) to communicate their feelings, ideas, and understandings in response to a variety of dance pieces and experiences</overall_text>
    <specifics>
      <specific></specific>
    </specifics>
  </overall>
 </overalls>
</strand>
<strand id="visual"> . . . </strand>
</curriculum>

跳舞
创作和呈现:将创作过程(见第19-22页)应用于简单舞蹈短语的创作,利用舞蹈元素传达情感和想法
反思、回应和分析:运用批判性分析过程(见第23-28页)传达他们对各种舞蹈片段和经历的感受、想法和理解
. . . 
下面是代码:(忽略IE位——它将只在Android和IOS上)


函数popout(){
var gr=gradedd.options[gradedd.selectedIndex].value
var sb=subdd.options[subdd.selectedIndex].value
var str=stranddd.options[stranddd.selectedIndex].value
xml=loadXMLDoc(“resources/ont/grade_“+gr+”“+sb+”.xml”);
path=“/currency/strand[@id=”+str+“]/workalls/overall/overall_text”
//IE代码
if(window.ActiveXObject){
var nodes=xml.selectNodes(路径);
对于(i=0;i

在我看来:

ind = result.parentNode.getAttribute("id")

应该可以工作。

请注意,IE10+没有本机XPath支持。您可能希望使用post.OMG中提到的库来简化您的整个方法,这当然有效!(就像vb代码一样)。这是我尝试的第一件事,但最后我得到了“result.parentNode[0].getAttribute(“id”)和.value”。我尝试了各种变体(.nodesValue等)。出于某种原因,我认为js xpath中的所有内容都需要[0]。我现在要去尝试一下。
ind = result.parentNode.getAttribute("id")