我在使用 XML 并对其应用多个条件时遇到了一些问题。我有一个如下所示的输入 XML:
<?xml version="1.0" encoding="UTF-8"?>
<results xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ResultsType">
<result>
<resultSets>
<resultSet>
<row>
<column1>11111</column1>
<column2>0</column2>
<column3>imageId/111111</column3>
<column4>2012-04-03T10:11:22.187</column4>
</row>
<row>
<column1>11111</column1>
<column2>2</column2>
<column3>imageId/111112</column3>
<column4>2012-04-03T10:11:22.187</column4>
</row>
<row>
<column1>11111</column1>
<column2>2</column2>
<column3>imageId/111113</column3>
<column4>2012-04-03T10:11:22.187</column4>
</row>
<row>
<column1>22222</column1>
<column2>0</column2>
<column3>imageId/222222</column3>
<column4>2012-04-03T10:11:22.187</column4>
</row>
<row>
<column1>22222</column1>
<column2>2</column2>
<column3>imageId/222223</column3>
<column4>2012-04-03T10:11:22.187</column4>
</row>
</resultSet>
</resultSets>
</result>
</results>
但是我希望它看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<results xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ResultsType">
<result>
<row>
<id>11111</id>
<lagrgeImage>imageId/111111</lagrgeImage>
<smallImage>imageId/111112</smallImage>
<smallImage>imageId/111113</smallImage>
</row>
<row>
<id>22222</id>
<lagrgeImage>imageId/222222</lagrgeImage>
<smallImage>imageId/222223</smallImage>
</row>
</result>
</results>
如您所见,有两个过滤条件:
如果 column2 = 0 则输出中需要 largeImage 标记,但是 column2 = 2 则输出中需要 smallImage 标记。
更新
下面的两个示例都运行良好,但是它们都在根目录中包含了意想不到的命名空间。我得到的输出是:
<?xml version="1.0" encoding="utf-8"?>
<results xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ResultsType">
<result>
<row>
<id>11111</id>
<largeImage>imageId/111111</largeImage>
<smallImage>imageId/111112</smallImage>
<smallImage>imageId/111113</smallImage>
</row>
<row>
<id>22222</id>
<largeImage>imageId/222222</largeImage>
<smallImage>imageId/222223</smallImage>
</row>
</result>
</results>
如何xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ResultsType"
从上述输出中删除?