以格式方式拆分xml节点 [英] Split xml node formatwise
问题描述
<?xml version="1.0"?>
-<DocumentElement>
-<test>
<c0>manas</c0>
<c1>100</c1>
<c2>20</c2>
<c3>33</c3>
<c4>54</c4>
<c5>65</c5>
<c6>78</c6>
</test>
-<test>
<c0>manasi</c0>
<c1>101</c1>
<c2>25</c2>
<c3>76</c3>
<c4>90</c4>
<c5>12</c5>
<c6>74</c6>
</test>
-<test>
<c0>mani</c0>
<c1>115</c1>
<c2>29</c2>
<c3>56</c3>
<c4>11</c4>
<c5>95</c5>
<c6>78</c6>
</test>
</DocumentElement>
控制台应用
对于第一次节点测试:
manas 100 20 33
manas 54 65 78 >
第二节点测试:
manasi 101 25 76
manasi 90 12 74
对于第三节点测试:
mani 115 29 56
mani 11 95 78
先生,
目标是拆分多个列数。
实际上第一节点测试的7列值如manas 100 20 33 54 65 78
我的要求是显示第一列(manas)和另外3行,再次创建一个中断并写下第一列(manas),后面有3列。
然后它将创建相同的类型对于第二个节点测试。
然后它将为第三个节点测试创建相同类型。
Console Application
For first Node Test:
manas 100 20 33
manas 54 65 78
For Second Node Test:
manasi 101 25 76
manasi 90 12 74
For Third Node Test:
mani 115 29 56
mani 11 95 78
Sir,
Aim is to split multiple number of columns .
Actually 7 columns values for First node Test like manas 100 20 33 54 65 78
My requirement is to display first column(manas) with 3 other row, again it will create a break and write like first column(manas) with next 3 columns.
Then same type it will create for second Node Test.
Then same type it will create for Third Node Test.
推荐答案
听起来你想写一个C#控制台应用程序并使用xsl转换数据。这很简单;只需创建一个控制台应用使用System.Xml和System.Xml.Xsl库名称空间。
It sounds like you want to write a C# console app and transform your data using xsl. This is straightforward; just create a console app. Use the System.Xml and System.Xml.Xsl library namespaces.
XslTransform xslt = new XslTransform();
xslt.Load("mytransform.xsl");
XPathDocument mydata = new XPathDocument("inputdata.xml");
XmlWriter writer = new XmlTextWriter(Console.Out);
xslt.Transform(mydata,null,writer, null);
将格式详细信息放在.xsl文件中。
Put the formatting details in the .xsl file.
希望它能按照我的理解解决您的问题。
Hope it will solve your problem as per my understanding.
DECLARE @XML XML='<documentelement>
<test><c0>manas</c0><c1>100</c1><c2>20</c2><c3>33</c3><c4>54</c4><c5>65</c5><c6>78</c6></test>
<test><c0>manasi</c0><c1>101</c1><c2>25</c2><c3>76</c3><c4>90</c4><c5>12</c5><c6>74</c6></test>
<test><c0>mani</c0><c1>115</c1><c2>29</c2><c3>56</c3><c4>11</c4><c5>95</c5><c6>78</c6></test>
</documentelement>'
Select Column1= x.value('c0[1]','varchar(100)') + ' '+ x.value('c1[1]','varchar(100)')+' ' +x.value('c2[1]','varchar(100)') +' '+x.value('c3[1]','varchar(100)'),
Column2= x.value('c0[1]','varchar(100)') + ' '+ x.value('c4[1]','varchar(100)')+' ' +x.value('c5[1]','varchar(100)') +' '+x.value('c6[1]','varchar(100)')
from @XML.nodes('/DocumentElement/test') e(x)
这篇关于以格式方式拆分xml节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!