Results 1 to 4 of 4

Thread: Cannot close an element

  1. #1
    .NET Framework
    .NET 4.5
    Join Date
    Sep 2017
    Posts
    2
    Reputation
    0

    Exclamation Cannot close an element

    Dear Sir,
    I am reading from a databse to fill an xml file,here is the code and the results
    my problem is that i am not beeing able to close the element "address"
    what is missing in my code?any help? thanks in advance


    ' Loop over employees in array.
    For Each dataRow1 As DataRow In dt1.Rows
    writer.WriteStartElement("applications")
    writer.WriteStartElement("application")
    writer.WriteAttributeString("createdBy", "CTL Card Tech Services Ltd(Cyprus)")

    writer.WriteStartElement("customer")
    writer.WriteAttributeString("name", dataRow1("GNP27NAM"))
    writer.WriteAttributeString("templateCode", dataRow1("GNP27TCD"))
    writer.WriteAttributeString("number", dataRow1("GNP27CUI"))

    writer.WriteStartElement("addresses")
    writer.WriteStartElement("address")
    writer.WriteAttributeString("addressType", dataRow1("GNP27ATP"))
    writer.WriteAttributeString("location", dataRow1("GNP27LOC"))
    writer.WriteAttributeString("lastName", dataRow1("GNP27LNM"))
    writer.WriteAttributeString("firstName", dataRow1("GNP27FNM"))
    writer.WriteAttributeString("address1", dataRow1("GNP27AD1"))
    writer.WriteAttributeString("address2", dataRow1("GNP27AD2"))
    writer.WriteAttributeString("zip", dataRow1("GNP27ZIP"))
    writer.WriteAttributeString("state", dataRow1("GNP27STT"))
    writer.WriteAttributeString("city", dataRow1("GNP27CTY"))
    writer.WriteAttributeString("country", dataRow1("GNP27CNT"))
    writer.WriteAttributeString("title", dataRow1("GNP27TTL"))

    Next
    writer.WriteEndElement()
    writer.WriteEndDocument()


    xml result :


    <?xml version="1.0" encoding="UTF-8"?>
    <bridge xmlns="http://CTL.COM.SERVICES.BRIDGE.DataEntities">
    <applications>
    <application createdBy="CTL Card Tech Services Ltd(Cyprus)">
    <customer number="368266 " templateCode="CCU1 " name="Khoury">
    <addresses>
    <address title="MLE" country="" city="" state="" zip="" address2="AL BIARA " address1="GERANIUM " firstName="NADA " lastName="KHOURY " location="" addressType="TT "/></addresses>
    </customer>
    </application>


    <people id=""/></applications></bridge>

  2. #2
    .NET Framework
    .NET 4.5
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    15,214
    Reputation
    2861
    The address element is closed:
    Quote Originally Posted by nadakhou
    <address ... />
    XmlWriter.WriteEndDocument Method (System.Xml)
    closes any open elements or attributes
    [xcode=vb] code here [/xcode] - see bbcode list or use formatting buttons in posting editor.

    Visual Studio Community 2017

  3. #3
    .NET Framework
    .NET 4.5
    Join Date
    Sep 2017
    Posts
    2
    Reputation
    0
    Thanks jhonn
    Actually the element <addresses> is closed i want <address> to be closed also
    got me?

  4. #4
    .NET Framework
    .NET 4.5
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    15,214
    Reputation
    2861
    They are both closed, can't you see the forward slash before end bracket?
    [xcode=vb] code here [/xcode] - see bbcode list or use formatting buttons in posting editor.

    Visual Studio Community 2017

Similar Threads

  1. Question element innertext
    By TMTakas in forum VB.NET General Discussion
    Replies: 1
    Last Post: 04-02-2014, 8:10 PM
  2. Question HtmElement Get value of Element by ID
    By athacks in forum Windows Forms
    Replies: 0
    Last Post: 08-06-2010, 3:46 PM
  3. when me.close() doesn't close form.
    By tcl4p in forum Windows Forms
    Replies: 1
    Last Post: 03-02-2009, 1:54 PM
  4. How to get the root element?
    By Thierry in forum XML
    Replies: 8
    Last Post: 05-20-2008, 5:17 AM
  5. Adding a new Element
    By monuindia2002 in forum XML
    Replies: 1
    Last Post: 03-13-2006, 6:12 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •