0

我有一些 xml 数据,我想在其中找到最长的节点。例如...

<data>
    <name>Miranda</name>
    <type>Horse</type>
</data>
<data>
    <name>Corny</name>
    <type>Unicorn</type>
</data>

因此,如果我在上面搜索最长的名称节点,它应该返回“Miranda”,如果我搜索最长的类型节点,它应该返回“Unicorn”。我怎样才能做到这一点?

4

1 回答 1

0

This is not all automatic but if you have the XML Tools plugin (can be downloaded via Plugin Manager)...

... select Tools->XML Tools->Evaluate XPath Expression and enter this in your expression:

/some/data/name

... then click [Evaluate]

I know it will show all name tags but you can just scroll through it and manually look for the longest string.

PS: the extra tag above was added because your XML by itself is not a valid XML file. I have to format it like below to make it traversable:

<?xml version="1.0"?>
<some>
    <data>
        <name>Miranda</name>
        <type>Horse</type>
    </data>
    <data>
        <name>Corny</name>
        <type>Unicorn</type>
    </data>
</some>
于 2013-05-10T02:39:09.243 回答