首页 > 解决方案 > 获取索引的 XML 节点

问题描述

我有textarea以下xml:

<root>
  <header>
    <title>This is the doc title</title>
  </header>
  <body attribute="[cursor]">
    Here we have some <?cursor [cursor]?> Text or [cursor]
    <![CDATA[
      Even more text in a CDATA and <notExisting>
        <p>
          [cursor]
        </p>
      </notExisting>
    ]]>
    <cursor  [cursor] />
    or with a comment <!-- This is the [cursor] position -->
  </body>
</root>

因为它是一个文本区域,所以我可以将光标放在我想要的任何地方。现在我想要光标位置的当前树。

例如,在第一个属性中,它可能类似于:/root/body/@attribute

或在处理指令中 /root/body/processing-instruction('cursor')

有什么方法可以始终获取当前光标位置?

标签: javascriptxmltypescriptxslt

解决方案


推荐阅读