我试图写下面的xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<ns2:IntraConsignment IntraListingsNbr="1" xmlns:ns2="http://www.minfin.fgov.be/IntraConsignment" xmlns="http://www.minfin.fgov.be/InputCommon">
是否可以使用xmlwriter在Visual Basic中实现此目的?
我只与两条第一线挣扎。完整的示例如下所示:
<?xml version="1.0" encoding="ISO-8859-1"?>
<ns2:IntraConsignment xmlns="http://www.minfin.fgov.be/InputCommon" xmlns:ns2="http://www.minfin.fgov.be/IntraConsignment" IntraListingsNbr="1">
<ns2:Representative>
<RepresentativeID identificationType="NVAT" issuedBy="BE">0000000097</RepresentativeID>
<Name>TEST Gevolmachtigde Manadataire NV SA</Name>
<Street>AV Test-laan 8</Street>
<PostCode>9999</PostCode>
<City>TESTCITY</City>
<CountryCode>BE</CountryCode>
<EmailAddress>scsdferfzefc@dsfsdf.be</EmailAddress>
<Phone>0212487645648</Phone>
</ns2:Representative>
<ns2:RepresentativeReference>CCFFLot2 LK</ns2:RepresentativeReference>
<ns2:IntraListing AmountSum="1000.00" DeclarantReference="" ClientsNbr="1" SequenceNumber="1">
<ns2:Declarant>
<VATNumber>0000000097</VATNumber>
<Name>BELGIUM nv sa</Name>
<Street>AV. testLAAN 20</Street>
<PostCode>9999</PostCode>
<City>TESTCITY</City>
<CountryCode>BE</CountryCode>
<EmailAddress>scsdferfzefc@dsfsdf.be</EmailAddress>
<Phone>0212487645648</Phone>
</ns2:Declarant>
<ns2:Period>
<ns2:Month>11</ns2:Month>
<ns2:Year>2011</ns2:Year>
</ns2:Period>
<ns2:IntraClient SequenceNumber="1">
<ns2:CompanyVATNumber issuedBy="IT">00399999991</ns2:CompanyVATNumber>
<ns2:Code>L</ns2:Code>
<ns2:Amount>1000.00</ns2:Amount>
<ns2:CorrectingPeriod>
<ns2:Month>11</ns2:Month>
<ns2:Year>2010</ns2:Year>
</ns2:CorrectingPeriod>
</ns2:IntraClient>
<ns2:Comment>free text max 2000 characters</ns2:Comment>
</ns2:IntraListing>
</ns2:IntraConsignment>
答案 0 :(得分:0)
是的,您可以使用XmlWriter
生成包含这些顶级节点的XML文档。这是一个例子:
Dim settings As New XmlWriterSettings()
settings.Indent = True
settings.IndentChars = vbTab
settings.Encoding = Encoding.GetEncoding("ISO-8859-1")
Using writer As XmlWriter = XmlWriter.Create("test.xml", settings)
writer.WriteStartDocument()
writer.WriteStartElement("ns2", "IntraConsignment", "http://www.minfin.fgov.be/IntraConsignment")
writer.WriteAttributeString("IntraListingsNbr", "1")
writer.WriteAttributeString("xmlns", "http://www.w3.org/2000/xmlns/", "http://www.minfin.fgov.be/InputCommon")
' ...
writer.WriteEndElement()
writer.WriteEndDocument()
End Using
由于您没有指定您遇到问题的任务的哪个特定部分,我无法详细说明让您感到困惑的部分,但如果您想特别询问它的任何部分,我很乐意添加更多解释。