如何更好地理解和导航大型XML文件的结构

时间:2023-01-15 09:36:42

I'm slogging through a somewhat large XML file. Say I'm looking for a particular value within the tree. I find it manually, but then to find it programmatically I need to know the path. Right now, I'm usingtidy and vim to pretty-print the file so that can I inspect it manually. It's getting old real fast though, 'cause the file is over 30,000 lines. So when I found the aforementioned value, it's quite a challenge to determine the full path. Ideally, I'd like a tool that'll let me do a full search on the contents of the xml file, and then display the full tree path to the root. This question has some awesome suggestions, but all of them are Windows only. Is there anything for Macs out there?

我正在浏览一个有点大的XML文件。假设我在树中寻找特定值。我手动找到它,但然后以编程方式找到它我需要知道路径。现在,我正在使用和vim来打印文件,以便我可以手动检查它。它虽然变得很快,但是因为文件超过30,000行。因此,当我找到上述值时,确定完整路径是一个相当大的挑战。理想情况下,我想要一个工具,让我可以对xml文件的内容进行全面搜索,然后显示到根目录的完整树路径。这个问题有一些很棒的建议,但它们都只是Windows。 Mac上有什么东西吗?

3 个解决方案

#1


1  

There are some strong XML tools for the Mac as well. Specifically, if you are interested in the path, I like using the XML editor of Eclipse. If you download the Helios version (go for the "Eclipse IDE for JavaScript Web Developers"), you can set it as your default XML editor (in the Finder, set the Open With) and it has very solid tools for outlining an XML and shows the path in the status bar.

Mac也有一些强大的XML工具。具体来说,如果您对路径感兴趣,我喜欢使用Eclipse的XML编辑器。如果您下载Helios版本(转到“Eclipse IDE for JavaScript Web Developers”),您可以将其设置为默认的XML编辑器(在Finder中,设置Open With),它具有非常可靠的工具来概述XML和显示状态栏中的路径。

There are other tools, GIYF.

还有其他工具,GIYF。

#2


1  

I use a combination of vim, xmllint, xpath, and a tool called cgrep, which you can find at http://plg1.cs.uwaterloo.ca/~ftp/mt/cgrep/ .

我使用了vim,xmllint,xpath和一个名为cgrep的工具的组合,您可以在http://plg1.cs.uwaterloo.ca/~ftp/mt/cgrep/找到它。

vim is my standard editor.

vim是我的标准编辑。

xmllint is essential if you are doing xml development.

如果你正在进行xml开发,xmllint是必不可少的。

xpath comes with xmllint iirc, and is a clumsy but workable command-line xpath evaluator.

xpath附带xmllint iirc,是一个笨拙但可行的命令行xpath评估程序。

cgrep is an experimental grep that uses cascading shortest-match regexes which can be very useful for quickly parsing record oriented files (xml, ini, properties, yaml, etc). I often find this much more useful than xpath.

cgrep是一个实验性的grep,它使用级联最短匹配正则表达式,这对于快速解析面向记录的文件(xml,ini,properties,yaml等)非常有用。我经常发现这比xpath更有用。

Note that if you are using gcc to build it, it does require some simple bug fixes as it is written in archaic C - I'm happy to send you a copy of the patched up code if you are interested.

请注意,如果您使用gcc构建它,它确实需要一些简单的错误修复,因为它是用古老的C编写的 - 如果您感兴趣,我很乐意向您发送修补代码的副本。

#3


1  

If the end goal is to have a Mac program to read and deal with the XML then I'd recommend you take a look at the tool and the code from this Apple-provided sample: http://developer.apple.com/mac/library/samplecode/XMLBrowser/Introduction/Intro.html

如果最终目标是让Mac程序读取和处理XML,那么我建议您查看Apple提供的示例中的工具和代码:http://developer.apple.com/mac /library/samplecode/XMLBrowser/Introduction/Intro.html

You can browse the XML and also test out various XQuery strings to see what is returned.

您可以浏览XML并测试各种XQuery字符串以查看返回的内容。

#1


1  

There are some strong XML tools for the Mac as well. Specifically, if you are interested in the path, I like using the XML editor of Eclipse. If you download the Helios version (go for the "Eclipse IDE for JavaScript Web Developers"), you can set it as your default XML editor (in the Finder, set the Open With) and it has very solid tools for outlining an XML and shows the path in the status bar.

Mac也有一些强大的XML工具。具体来说,如果您对路径感兴趣,我喜欢使用Eclipse的XML编辑器。如果您下载Helios版本(转到“Eclipse IDE for JavaScript Web Developers”),您可以将其设置为默认的XML编辑器(在Finder中,设置Open With),它具有非常可靠的工具来概述XML和显示状态栏中的路径。

There are other tools, GIYF.

还有其他工具,GIYF。

#2


1  

I use a combination of vim, xmllint, xpath, and a tool called cgrep, which you can find at http://plg1.cs.uwaterloo.ca/~ftp/mt/cgrep/ .

我使用了vim,xmllint,xpath和一个名为cgrep的工具的组合,您可以在http://plg1.cs.uwaterloo.ca/~ftp/mt/cgrep/找到它。

vim is my standard editor.

vim是我的标准编辑。

xmllint is essential if you are doing xml development.

如果你正在进行xml开发,xmllint是必不可少的。

xpath comes with xmllint iirc, and is a clumsy but workable command-line xpath evaluator.

xpath附带xmllint iirc,是一个笨拙但可行的命令行xpath评估程序。

cgrep is an experimental grep that uses cascading shortest-match regexes which can be very useful for quickly parsing record oriented files (xml, ini, properties, yaml, etc). I often find this much more useful than xpath.

cgrep是一个实验性的grep,它使用级联最短匹配正则表达式,这对于快速解析面向记录的文件(xml,ini,properties,yaml等)非常有用。我经常发现这比xpath更有用。

Note that if you are using gcc to build it, it does require some simple bug fixes as it is written in archaic C - I'm happy to send you a copy of the patched up code if you are interested.

请注意,如果您使用gcc构建它,它确实需要一些简单的错误修复,因为它是用古老的C编写的 - 如果您感兴趣,我很乐意向您发送修补代码的副本。

#3


1  

If the end goal is to have a Mac program to read and deal with the XML then I'd recommend you take a look at the tool and the code from this Apple-provided sample: http://developer.apple.com/mac/library/samplecode/XMLBrowser/Introduction/Intro.html

如果最终目标是让Mac程序读取和处理XML,那么我建议您查看Apple提供的示例中的工具和代码:http://developer.apple.com/mac /library/samplecode/XMLBrowser/Introduction/Intro.html

You can browse the XML and also test out various XQuery strings to see what is returned.

您可以浏览XML并测试各种XQuery字符串以查看返回的内容。