2

I'm tring to write rows with multiple values using XmlWriter (vb - VS2013 .net 4.0). All I found googling, was examples of codes like this one:

    Dim settings As New XmlWriterSettings()
    settings.Indent = True

    Dim XmlWrt As XmlWriter = XmlWriter.Create("123.xml", settings)

    With XmlWrt
        .WriteStartDocument()
        .WriteComment("blablabla")
        .WriteStartElement("test1")
        .WriteStartElement("test2")
        .WriteString("text")
        .WriteEndElement()
        .WriteEndElement()
        .Close()
    End With

This is the output for the code above:

    <!-- blablabla -->
    <test1>
        <test2>text</test2>
    </test1>

But what a want is a line, that is a row with multiple values like this:

    <row Nome="value" Acessorio="value" CodigoNcm="99999999" EspecificacaoComplementar="value" Origem="value" Quantidade="0.01" UnidadeMedida="value" PesoUnitario="0.01" NomeFabricante="value" NumeroDocumentoNFouDI="0" CodigoTipoDocumento="2" OrigemItensFinanciaveis="value" CustoFOBUnitario="0.01" CustoCIFUnitarioDOLAR="0.01" ImpostoImportacaoUnitario="0.01" PisUnitario="0.01" CofinsUnitario="0.01" PaisOrigem="value" DireitosAntiDumpingUnitario="0.01" Seq-Componente="CMP-2" PaginaDI="1234"/>

I didn't find any method to write rows. How to i accomplish that?

Thanks everyone!

2
  • In XML, those key/value pairs on an element are called attributes. Commented Jul 25, 2017 at 21:32
  • Thaaaaanks Steven. That was i looking for! Commented Jul 25, 2017 at 21:38

1 Answer 1

2

In case anyone have the same question. This is the way:

    With XmlWrt
        .WriteStartElement("test1")
        .WriteAttributeString("key", "value")
        .WriteAttributeString("key", "value")
        .WriteEndElement()
        .Close()
    End With
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.