javascript - 获取索引的 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')
有什么方法可以始终获取当前光标位置?
解决方案
推荐阅读
- java - 在没有左右参考的情况下查找树的高度
- java - 如果有任何带有空格的文件名,如何正确地将 git ls-files 输出传递给 Java?
- javascript - 如何编写下拉选项以加载 JSON 文件?
- linux - save_stack_trace_tsk 和 struct stack_trace 在 Linux 5.2+ 中不再可用
- css - 以角度更改代码镜像的高度和宽度
- ruby-on-rails - 未捕获的错误:rails-ujs 已加载
- javascript - React Hooks useEffect 从 useCallback 调用道具回调
- html - 输入所需的 HTML 不会消失并且表单已禁用
- github - 如何在 Github 上将提交拆分为单个 PR
- html - 将 inline-svg 设置为 div 的背景