Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

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

Question posted by: Karl Rhodes (Guest) on June 27th, 2008 07:20 PM
I have the following XML file (Called CustomerList.xml) ...

<?xml version="1.0" encoding="utf-8"?>
<customerList xmlns="http://tempuri.org/CustomerListSchema.xsd">
<customer>
<CompanyName>Company One</CompanyName>
<ContactName>Joe</ContactName>
<Email>Joe@CompanyOne.com</Email>
<Phone>01234 567890</Phone>
<BillToAddress>
<Name>Company One</Name>
<Street>1 Some Street</Street>
<City>Some City</City>
<State>Some State</State>
<Zip>12345</Zip>
</BillToAddress>
<ShipToAddress>
<Name>Company One</Name>
<Street>1 Some Street</Street>
<City>Some City</City>
<State>Some State</State>
<Zip>12345</Zip>
</ShipToAddress>
</customer>
<customer>
<CompanyName>Company Two</CompanyName>
<ContactName>Fred</ContactName>
<Email>fred@companytwo.com</Email>
<Phone>09876 543210</Phone>
<BillToAddress>
<Name>Company Two</Name>
<Street>1 This Street</Street>
<City>This City</City>
<State>This State</State>
<Zip>67890</Zip>
</BillToAddress>
<ShipToAddress>
<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 CustomerListSchema.xsd)...

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="CustomerListSchema"
targetNamespace="http://tempuri.org/CustomerListSchema.xsd"
elementFormDefault="qualified"
xmlns="http://tempuri.org/CustomerListSchema.xsd"
xmlns:mstns="http://tempuri.org/CustomerListSchema.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="postalCode">
<xs:restriction base="xs:positiveInteger">
<xs:pattern value="\d{5}" />
</xs:restriction>
</xs:simpleType>
<xs:complexType 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="postalCode" />
</xs:sequence>
</xs:complexType>
<xs:element name="customerList">
<xs:complexType>
<xs:sequence>
<xs:element name="customer">
<xs:complexType>
<xs:sequence>
<xs:element name="CompanyName" type="xs:string" />
<xs:element name="ContactName" type="xs:string" />
<xs:element name="Email" type="xs:string" />
<xs:element name="Phone" type="xs:string" />
<xs:element name="BillToAddress" type="usAddress" />
<xs:element name="ShipToAddress" 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.xml")
oDgv.DataSource = oDSet
oDgv.DataMember = "customer"

oDGV2.DataSource = oDSet
oDGV2.DataMember = "ShipToAddress"

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 Join Bytes! 01234 567890
Company Two Fred Join Bytes! 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
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
 
Not the answer you were looking for? Post your question . . .
183,968 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors