Visual Basic .net写入xml

时间:2021-06-24 00:01:08

I'm trying to write following xml:

我正在尝试编写以下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">

Is it possible to achieve this in visual basic using xmlwriter?

是否有可能使用xmlwriter在visual basic中实现这一点?

I'm only struggling with the two first lines. The complete example looks like this:

我只是在与两个第一线挣扎。完整的示例如下所示:

<?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>    

1 个解决方案

#1


0  

Yes, you can use an XmlWriter to generate an XML document which has those top-level nodes. Here's an example:

是的,您可以使用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

Since you didn't specify which particular part of the task you were having trouble with, I can't adequately elaborate on the part that confuses you, but if you want to ask about any part of it specifically, I'd be happy to add more explanation.

既然你没有说明你遇到麻烦的任务的哪个特定部分,我就无法详细说明让你感到困惑的部分,但如果你想特别询问它的任何部分,我会很乐意添加更多解释。

#1


0  

Yes, you can use an XmlWriter to generate an XML document which has those top-level nodes. Here's an example:

是的,您可以使用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

Since you didn't specify which particular part of the task you were having trouble with, I can't adequately elaborate on the part that confuses you, but if you want to ask about any part of it specifically, I'd be happy to add more explanation.

既然你没有说明你遇到麻烦的任务的哪个特定部分,我就无法详细说明让你感到困惑的部分,但如果你想特别询问它的任何部分,我会很乐意添加更多解释。