xml format problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • CindyH

    xml format problem

    Hi

    I'm using the following code to create xml string:

    Dim Doc As New System.Xml.XmlD ocument
    Dim newAtt As System.Xml.XmlA ttribute

    Dim dec As System.Xml.XmlD eclaration
    dec = Doc.CreateXmlDe claration("1.0" , Nothing, Nothing)
    dec.Encoding = "UTF-8"
    Doc.AppendChild (dec)

    Dim DocRoot As System.Xml.XmlE lement = Doc.CreateEleme nt("userlist")
    newAtt = Doc.CreateAttri bute("ACTION")
    newAtt.Value = vAction
    DocRoot.Attribu tes.Append(newA tt)

    newAtt = Doc.CreateAttri bute("VENDORNAM E")
    newAtt.Value = vVendorName
    DocRoot.Attribu tes.Append(newA tt)
    Doc.AppendChild (DocRoot)

    Dim amouser As System.Xml.XmlN ode = Doc.CreateEleme nt("amouser")
    newAtt = Doc.CreateAttri bute("AMOAID")
    newAtt.Value = vAMOAID
    amouser.Attribu tes.Append(newA tt)

    newAtt = Doc.CreateAttri bute("VENDORUSE RNAME")
    newAtt.Value = vH2UserName
    amouser.Attribu tes.Append(newA tt)

    newAtt = Doc.CreateAttri bute("AMOATOKEN ")
    newAtt.Value = vAMOAToken
    amouser.Attribu tes.Append(newA tt)

    DocRoot.AppendC hild(amouser)

    Dim xmlstring = Doc.OuterXml



    The result looks like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <userlist ACTION="redirec tuser" VENDORNAME="H2D igital">
    <amouser AMOAID="bb224c2 a-fe8a-4c3f-acf4-6c0986b8cf78"
    VENDORUSERNAME= "xrivera@hotmai l.com"
    AMOATOKEN="hx0g H6e8PvswEzaA8oX PoVIY/KvnbP2/" />
    </userlist>


    I need the result to look like this: with </amouserinstead of />

    <?xml version="1.0" encoding="UTF-8"?>
    <userlist ACTION="redirec tuser" VENDORNAME="H2D igital">
    <amouser AMOAID="bb224c2 a-fe8a-4c3f-acf4-6c0986b8cf78"
    VENDORUSERNAME= "xrivera@hotmai l.com"
    AMOATOKEN="hx0g H6e8PvswEzaA8oX PoVIY/KvnbP2/" </amouser>
    </userlist>

    Does anyone know what I'm doing wrong here?
    Thanks,
    Cindy


  • Martin Honnen

    #2
    Re: xml format problem

    CindyH wrote:
    Does anyone know what I'm doing wrong here?
    Whether an empty element is serialized as
    <foo/>
    or
    <foo />
    or
    <foo></foo>
    does not make a difference. If you want to enforce
    <foo></foo>
    nevertheless then with the .NET framework's DOM implementation set
    IsEmpty to false, see


    So in your original example you need
    amouser.IsEmpty = False



    --

    Martin Honnen --- MVP XML

    Comment

    • CindyH

      #3
      Re: xml format problem

      Ok - thanks

      "Martin Honnen" <mahotrash@yaho o.dewrote in message
      news:eIefbqmuIH A.5288@TK2MSFTN GP06.phx.gbl...
      CindyH wrote:
      >
      >Does anyone know what I'm doing wrong here?
      >
      Whether an empty element is serialized as
      <foo/>
      or
      <foo />
      or
      <foo></foo>
      does not make a difference. If you want to enforce
      <foo></foo>
      nevertheless then with the .NET framework's DOM implementation set IsEmpty
      to false, see

      >
      So in your original example you need
      amouser.IsEmpty = False
      >
      >
      >
      --
      >
      Martin Honnen --- MVP XML
      http://JavaScript.FAQTs.com/

      Comment

      Working...