Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
按子标签对XML文件排序?_Xml_Sorting - Fatal编程技术网

按子标签对XML文件排序?

按子标签对XML文件排序?,xml,sorting,Xml,Sorting,我不再是程序员了。 我正在使用我的windows media center PC,并试图减少mcechannelinfo.xml中的垃圾 很容易删除其他提供商(我不使用的有线电视运营商),但现在我在我的提供商中尝试排序/删除我没有得到的频道 数据按如下方式排序: <channel> <id>Atlanta, DISH Atlanta::ZBUSN::mcepg</id> <name>ZBUSN</name>

我不再是程序员了。 我正在使用我的windows media center PC,并试图减少mcechannelinfo.xml中的垃圾

很容易删除其他提供商(我不使用的有线电视运营商),但现在我在我的提供商中尝试排序/删除我没有得到的频道

数据按如下方式排序:

    <channel>
      <id>Atlanta, DISH Atlanta::ZBUSN::mcepg</id>
      <name>ZBUSN</name>
      <num>708</num>
      <subnum>0</subnum>
    </channel>
    <channel>
      <id>Atlanta, DISH Atlanta::KIDTV::mcepg</id>
      <name>KIDTV</name>
      <num>9394</num>
      <subnum>0</subnum>
    </channel>
    <channel>
      <id>Atlanta, DISH Atlanta::WSBK::mcepg</id>
      <name>WSBK</name>
      <num>8775</num>
      <subnum>0</subnum>
    </channel>
    <channel>
      <id>Atlanta, DISH Atlanta::BLOCK::mcepg</id>
      <name>BLOCK</name>
      <num>349</num>
      <subnum>0</subnum>
    </channel>
<?xml-stylesheet type="text/xsl" href="order-channels.xsl"?>
<channels>
      <channel>
        <id>Atlanta, DISH Atlanta::ZBUSN::mcepg</id>
        <name>ZBUSN</name>
        <num>708</num>
        <subnum>0</subnum>
      </channel>
  ...
</channels>

亚特兰大,亚特兰大::ZBUSN::mcepg
ZBUSN
708
0
亚特兰大,亚特兰大::基德电视台::mcepg
儿童电视
9394
0
亚特兰大,亚特兰大::WSBK::mcepg
WSBK
8775
0
亚特兰大,亚特兰大::街区::mcepg
块
349
0
正如你所看到的,那真是一团糟。它既不是按频道名称的字母顺序排列,也不是按数字排列

如何按名称或更好的方式,按数字对数据进行排序? 我可以使用一些工具——Excel、记事本++,还有另一个我抓到的叫做XMLMIND的程序

请帮忙

嗯。我尝试了你的回复,但似乎不起作用,所以我从XML顶部粘贴了一个更大的剪辑,这样你就可以看到所有内容

?xml version="1.0" encoding="utf-8"?>
<Channels> 
 <category name="Atlanta, DISH Atlanta">
    <channel>
      <id>Atlanta, DISH Atlanta::ESPNA::mcepg</id>
      <name>ESPNA</name>
      <num>148</num>
      <subnum>0</subnum>
    </channel>
    <channel>
      <id>Atlanta, DISH Atlanta::FSP::mcepg</id>
      <name>FSP</name>
      <num>391</num>
      <subnum>0</subnum>
    </channel>
    <channel>
      <id>Atlanta, DISH Atlanta::ACMAX::mcepg</id>
      <name>ACMAX</name>
      <num>313</num>
      <subnum>0</subnum>
    </channel>
    <channel>
      <id>Atlanta, DISH Atlanta::TBSHD::mcepg</id>
      <name>TBSHD</name>
      <num>139</num>
      <subnum>0</subnum>
    </channel>
?xml version=“1.0”encoding=“utf-8”>
亚特兰大,亚特兰大::ESPNA::mcepg
埃斯普纳
148
0
亚特兰大,亚特兰大::FSP::mcepg
FSP
391
0
亚特兰大,亚特兰大::ACMAX::mcepg
ACMAX
313
0
亚特兰大,亚特兰大::TBSHD::mcepg
TBSHD
139
0

非常感谢您的帮助。

您可以使用XSLT 1.0样式表。不难找到解析器,您甚至可以使用在线服务来处理它

您没有发布格式良好的XML,因此我假设您在
上方有一个父节点,我将称之为
。所以我假设你的文件是这样的:

    <channel>
      <id>Atlanta, DISH Atlanta::ZBUSN::mcepg</id>
      <name>ZBUSN</name>
      <num>708</num>
      <subnum>0</subnum>
    </channel>
    <channel>
      <id>Atlanta, DISH Atlanta::KIDTV::mcepg</id>
      <name>KIDTV</name>
      <num>9394</num>
      <subnum>0</subnum>
    </channel>
    <channel>
      <id>Atlanta, DISH Atlanta::WSBK::mcepg</id>
      <name>WSBK</name>
      <num>8775</num>
      <subnum>0</subnum>
    </channel>
    <channel>
      <id>Atlanta, DISH Atlanta::BLOCK::mcepg</id>
      <name>BLOCK</name>
      <num>349</num>
      <subnum>0</subnum>
    </channel>
<?xml-stylesheet type="text/xsl" href="order-channels.xsl"?>
<channels>
      <channel>
        <id>Atlanta, DISH Atlanta::ZBUSN::mcepg</id>
        <name>ZBUSN</name>
        <num>708</num>
        <subnum>0</subnum>
      </channel>
  ...
</channels>

亚特兰大,亚特兰大::ZBUSN::mcepg
ZBUSN
708
0
...
创建包含此XSL样式表的文件:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

    <xsl:output indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="channels">
        <xsl:copy>
            <xsl:apply-templates select="channel">
                <xsl:sort select="num"/>
            </xsl:apply-templates>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
    </xsl:template>

</xsl:stylesheet>

现在,您可以使用XSLT处理器或服务,并使用样式表转换XML。生成的XML将具有按编号排序的
通道
节点

您也可以使用。只需将源XML复制到XML文本框中,将XSL复制到XSL框中,然后按“转换XML”

您可以根据不同的条件进行订购,将
中的
选择属性替换为
频道
上下文中的其他字段

(别忘了我对您的XML源代码做了一些假设;如果您发布的内容只是一个简化,那么您可能需要将其调整为源XML)