xml 在Visual Studio中查看xml文件时如何获取某个节点的xpath?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3148217/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get the xpath of a certain node when viewing an xml file in Visual Studio?
提问by Nam G VU
When I open an xml file in Visual Studio and browse it, I want to get the xpath of a certain node at the cursor like right click and choose "get xpath from this node" or something like that. How can we do that in Visual Studio 2010 or which tools/addons to use to do that?
当我在 Visual Studio 中打开一个 xml 文件并浏览它时,我想在光标处获取某个节点的 xpath,例如右键单击并选择“从该节点获取 xpath”或类似的东西。我们如何在 Visual Studio 2010 中做到这一点或使用哪些工具/插件来做到这一点?
Hope to hear from you all.
希望听到大家的意见。
回答by MindingData
I am unsure of a Visual Studio tool that does this (Although I am sure there is one). For me, I use Notepad++ (Is there anything it can't do!?).
我不确定执行此操作的 Visual Studio 工具(尽管我确定有一个)。对我来说,我使用 Notepad++(有什么它不能做的!?)。
- Inside Notepad++ go to Plugins -> Plugin Manager -> Show Plugin Manager
- Install XML Tools
- Restart Notepad
- Load your XML Doc
- Place your cursor onto the node you are looking to generate the xpath for
- Go Plugins -> XML Tools -> Current XML Path (Default Hotkey : Ctrl + Alt + Shift + P)
- 在 Notepad++ 中,转到插件 -> 插件管理器 -> 显示插件管理器
- 安装 XML 工具
- 重新启动记事本
- 加载您的 XML 文档
- 将光标放在要为其生成 xpath 的节点上
- Go Plugins -> XML Tools -> Current XML Path(默认热键:Ctrl + Alt + Shift + P)
This will only be able to give you the very basic XML tree traversal, but it's a start.
这只能为您提供非常基本的 XML 树遍历,但这只是一个开始。
No tool will be able to generate any sort of complicated xPath for attribute checking etc. For those things often it is trial and error. You can use an online xPath tester to test your expressions against your XML anytime. Something like http://www.freeformatter.com/xpath-tester.htmlshould be a great help.
没有任何工具能够为属性检查等生成任何类型的复杂 xPath。对于这些事情,通常是反复试验。您可以随时使用在线 xPath 测试器根据 XML 测试您的表达式。像http://www.freeformatter.com/xpath-tester.html这样的东西应该会有很大帮助。
回答by Ogglas
The extension you want is called "XPath Information". In Visual Studio go to Tools -> Extensions and Updates -> Online -> Search for "XPath Information".
您想要的扩展名为“XPath 信息”。在 Visual Studio 中,转到工具 -> 扩展和更新 -> 在线 -> 搜索“XPath 信息”。

