How to read from different'levels' of xml to a datagridview?

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

    How to read from different'levels' of xml to a datagridview?

    I have the following XML file (Called CustomerList.xm l) ...

    <?xml version="1.0" encoding="utf-8"?>
    <customerList xmlns="http://tempuri.org/CustomerListSch ema.xsd">
    <customer>
    <CompanyName>Co mpany One</CompanyName>
    <ContactName>Jo e</ContactName>
    <Email>Joe@Comp anyOne.com</Email>
    <Phone>01234 567890</Phone>
    <BillToAddres s>
    <Name>Company One</Name>
    <Street>1 Some Street</Street>
    <City>Some City</City>
    <State>Some State</State>
    <Zip>12345</Zip>
    </BillToAddress>
    <ShipToAddres s>
    <Name>Company One</Name>
    <Street>1 Some Street</Street>
    <City>Some City</City>
    <State>Some State</State>
    <Zip>12345</Zip>
    </ShipToAddress>
    </customer>
    <customer>
    <CompanyName>Co mpany Two</CompanyName>
    <ContactName>Fr ed</ContactName>
    <Email>fred@com panytwo.com</Email>
    <Phone>09876 543210</Phone>
    <BillToAddres s>
    <Name>Company Two</Name>
    <Street>1 This Street</Street>
    <City>This City</City>
    <State>This State</State>
    <Zip>67890</Zip>
    </BillToAddress>
    <ShipToAddres s>
    <Name>Company Two</Name>
    <Street>1 This Street</Street>
    <City>This City</City>
    <State>This State</State>
    <Zip>67890</Zip>
    </ShipToAddress>
    </customer>
    </customerList>


    With the following Scema file (Called CustomerListSch ema.xsd)...

    <?xml version="1.0" encoding="utf-8"?>
    <xs:schema id="CustomerLis tSchema"
    targetNamespace ="http://tempuri.org/CustomerListSch ema.xsd"
    elementFormDefa ult="qualified"
    xmlns="http://tempuri.org/CustomerListSch ema.xsd"
    xmlns:mstns="ht tp://tempuri.org/CustomerListSch ema.xsd"
    xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:simpleTyp e name="postalCod e">
    <xs:restricti on base="xs:positi veInteger">
    <xs:pattern value="\d{5}" />
    </xs:restriction>
    </xs:simpleType>
    <xs:complexTy pe name="usAddress ">
    <xs:sequence>
    <xs:element name="Name" type="xs:string " />
    <xs:element name="Street" type="xs:string " />
    <xs:element name="City" type="xs:string " />
    <xs:element name="State" type="xs:string " />
    <xs:element name="Zip" type="postalCod e" />
    </xs:sequence>
    </xs:complexType>
    <xs:element name="customerL ist">
    <xs:complexType >
    <xs:sequence>
    <xs:element name="customer" >
    <xs:complexType >
    <xs:sequence>
    <xs:element name="CompanyNa me" type="xs:string " />
    <xs:element name="ContactNa me" type="xs:string " />
    <xs:element name="Email" type="xs:string " />
    <xs:element name="Phone" type="xs:string " />
    <xs:element name="BillToAdd ress" type="usAddress " />
    <xs:element name="ShipToAdd ress" type="usAddress " />
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:schema>

    In a VB.Net Windows App project I can easily get some of the data into
    DataGridViews (one called oDGV1 and the called oDGV2) using the
    following code in the form_Load...


    Dim oDSet As New DataSet
    oDSet.ReadXml(" customerList.xm l")
    oDgv.DataSource = oDSet
    oDgv.DataMember = "customer"

    oDGV2.DataSourc e = oDSet
    oDGV2.DataMembe r = "ShipToAddr ess"

    However this only gives me bits of the data and I would like to know
    how to "join" the data?

    IE. In oDGV1 I get the following...

    Company One Joe Joe@CompanyOne. com 01234 567890
    Company Two Fred fred@companytwo .com 09876 543210

    and in oDGV2 I get...

    Company One House 1 Some Street Some City Some State 12345
    Company Two House 1 This Street This City This State 67890

    How do I get the following into a DataGridView?

    Company One Joe Company One House 1 Some Street Some City Some State
    12345
    Company Two Fred Company Two House 1 This Street This City This State
    67890
Working...