输入XML文件和例外XML文件
答案 0 :(得分:0)
使用xml linq
Imports System.Xml
Imports System.Xml.Linq
Module Module1
Sub Main()
Dim input(,) As String = {{"1322274520008570", "AB"}, _
{"1322274520008571", "GHI"}, _
{"1322274520008572", "K"}
}
Dim header As String = "<?xml version=""1.0"" encoding=""utf-8""?><FileFormatBoc></FileFormatBoc>"
Dim doc As XDocument = XDocument.Parse(header)
Dim fileFormatBoc As XElement = doc.Descendants("FileFormatBoc").FirstOrDefault()
Dim len = input.Length / 2
For row = 0 To (len - 1)
fileFormatBoc.Add(New XElement("F", New Object() { _
New XAttribute("F1", input(row, 0)), _
New XElement("P1", New XAttribute("P", input(row, 1))) _
}))
Next row
End Sub
End Module
答案 1 :(得分:0)
VB.net的XML文字可以使用类似于WebForms的语法来嵌入表达式,并使用Dim xml =
<?xml version="1.0"?>
<FileFormatBoC>
<F F1="1">
<P1 P="A"/>
<P1 P="B"/>
</F>
<F F1="2">
<P1 P="C"/>
<P1 P="D"/>
<P1 P="E"/>
</F>
<F F1="3"/>
</FileFormatBoC>
Dim newXml =
<?xml version="1.0"?>
<FileFormatBoC>
<%=
From f In xml.<FileFormatBoC>.<F>
Select If(
f.<P1>.Any(),
<F F1=<%= f.@F1 %>>
<P1 P=<%= String.Join("", From p In f.<P1> Select p.@P) %>/>
</F>,
f
)
%>
</FileFormatBoC>
来引用属性。使用它和一些LINQ to XML查询:
<FileFormatBoC>
<F F1="1">
<P1 P="AB" />
</F>
<F F1="2">
<P1 P="CDE" />
</F>
<F F1="3" />
</FileFormatBoC>
newXml:
<div style="width:100%; height:auto;" >
<img style="width:100%; height:auto;" src="image.png">
</div>