locked
Help with creating XML file RRS feed

  • Question

  • User-284642143 posted

    Really struggling to get this right....Does anyone have an example i can follow to create an XML file which would look like

    For each c in myCustomerData

    <Customers>

    <Customer id=c.id>
    <Name><Name>
    <Address></Address>
    </Customer>

    <Customer id=c.id>
    <Name><Name>
    <Address></Address>
    </Customer>

    </Customers>

    Next

    The end output file would look like

    <?xml version="1.0" encoding="UTF-16" standalone="yes"?>
    <Customers>

    <Customer id="1">
    <Name><Name>
    <Address></Address>
    </Customer>

    <Customer id="2">
    <Name><Name>
    <Address></Address>
    </Customer>

    </Customers>

    Thanks

    Thursday, May 1, 2014 5:23 AM

Answers

  • User832087614 posted

    XElement Customers=new XElement("Customers")

    For each c in myCustomerData

    {

    XElement  Customer=new Xelement("Customer");

    Customer.SetAttributeValue("id",c.id);

    XElement  Name=new Xelement("Name");

    XElement  Address=new Xelement("Address");

    Customers.Add(Customer);

    Customers.Add(Name);

    Customers.Add(Address);

    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, May 4, 2014 10:45 PM

All replies

  • User1508394307 posted

    Dim xml As String = ""

    For each c in myCustomerData

    xml &= String.Format("<Customer id={0}>" & vbCrlf & _
    "<Name><Name>" & vbCrlf & _
    "<Address></Address>" & vbCrlf & _
    "</Customer>" & vbCrlf, c.id)

    Next

    xml = "<Customer>" & xml & "</Customer>"

    Thursday, May 1, 2014 6:33 AM
  • User832087614 posted

    XElement Customers=new XElement("Customers")

    For each c in myCustomerData

    {

    XElement  Customer=new Xelement("Customer");

    Customer.SetAttributeValue("id",c.id);

    XElement  Name=new Xelement("Name");

    XElement  Address=new Xelement("Address");

    Customers.Add(Customer);

    Customers.Add(Name);

    Customers.Add(Address);

    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, May 4, 2014 10:45 PM