我有一个 XML 文件,其中包含多张图片的数据,例如 GPS 坐标、日期/时间和一些我需要拆分成多个 XML 文件的图像数据。
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.1">
<Document>
<Placemark>
<name> //picture 1 info <name>
<Point>
<coordinates> //gps 1 cords <coordinates>
<Point>
<Placemark>
<Placemark>
<name> //picture 2 info <name>
<Point>
<coordinates> //gps 2 cords <coordinates>
<Point>
<Placemark>
<Document>
我希望它看起来像这样:
File 1:
<Placemark>
<Name> //picture 1 info <name>
<Point>
<coordinates> //gps 1 cords <coordinates>
<Point>
<Placemark>
File 2:
<Placemark>
<Name> //picture 2 info <name>
<Point>
<coordinates> //gps 2 cords <coordinates>
<Point>
<Placemark>
.....我读了这个问题: Split XML in Multiple XML files
并尝试在导入所有内容后为我的文件稍微修改代码。想知道是否有人对如何修改我的代码以像上面的问题那样吐口水有什么好主意。
最佳答案
在 XSLT 2.0 中非常简单:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="*">
<xsl:copy><xsl:apply-templates/></xsl:copy>
</xsl:template>
<xsl:template match="Placemark">
<xsl:result-document href="Placemark{position()}.xml">
<xsl:next-match/>
</xsl:result-document>
</xsl:template>
</xsl:stylesheet>
关于java - 将 XML 拆分为多个 xml 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6447296/