Relations read from .XSD XML schema do not seem to appear in dataset

E

Ed

I've created a .XSD XML schema (see below) with 2 tables and a
relation defined between those tables. When I read the schema and XML
data into the dataset I can see and access the datatables, but the
dataset.relations collection is empty. If someone could help me get
this to work, explain why it won't, and/or give me a workaround, I
would appreciate it.
(FYI, I'm attempting to use this in a VB.NET Windows Forms application
to store application & config info. I'd like to be able to call
Datatable.GetChildRows() using the relation.)

Here's a snippet of the VB.NET code:
'Notes: "XMLConfigSchema" & "XMLConfigData" are const containing
file/path info
'"HCMgmt.HC_Computers" is the Dataset object created by the XSD in my
VS solution
dsConfig = New HCMgmt.HC_Computers
dsConfig.ReadXmlSchema(XMLConfigSchema)
dsConfig.ReadXml(XMLConfigData)

Here's the .XSD XML Schema:
(Note that this was created in VS.NET 2003 using the XML designer.)

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="HC_Computers"
targetNamespace="http://tempuri.org/HC_Computers.xsd"
elementFormDefault="qualified"
xmlns="http://tempuri.org/HC_Computers.xsd"
xmlns:mstns="http://tempuri.org/HC_Computers.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="ComputerInfo">
<xs:complexType>
<xs:sequence>
<xs:element name="DisplayName" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:key name="ComputerInfoKey1" msdata:primaryKey="true">
<xs:selector xpath="." />
<xs:field xpath="mstns:DisplayName" />
</xs:key>
</xs:element>
<xs:element name="AccessInfo">
<xs:complexType>
<xs:sequence>
<xs:element name="DisplayName" type="xs:string" />
<xs:element name="IPorName" type="xs:string" />
<xs:element name="ID" type="xs:string" />
<xs:element name="PW" type="xs:string" />
<xs:element name="Domain" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:key name="AccessInfoKey1">
<xs:selector xpath="." />
<xs:field xpath="mstns:DisplayName" />
</xs:key>
<xs:keyref name="ComputerInfoComputerInfo" refer="ComputerInfoKey1"
msdata:DeleteRule="Cascade"
msdata:UpdateRule="Cascade">
<xs:selector xpath="." />
<xs:field xpath="mstns:DisplayName" />
</xs:keyref>
</xs:element>
</xs:schema>
 
E

Ed

I did find a solution. I will attempt to explain. I've posted a copy
of my working schema at the end for you to review.

I'd initially created the schema using the XML Schema editor in VS.NET
2003. I created the relations using this tool by creating keys and
adding relations
between the tables. This was not working as I wanted when reading the
XSD/XML into a datset.

I then read some newsgroups and found the MSDN Library
section here:
http://msdn.microsoft.com/library/e...sd_relationships_to_dataset_relationships.asp

It states:
"In a DataSet, you form an association between two or more columns by
creating a parent-child relation. There are three ways to represent a
DataSet relation
within an XML Schema definition language (XSD) schema:

1. Specify nested complex types.
2. Use the msdata:Relationship annotation.
3. Specify an xs:keyref without the msdata:ConstraintOnly annotation."

I used option #2. I created a top level/parent/root table that
contains/nests the 2 data tables. None of the tables contain relations
or keys. THEN I edited
the XSD directly and created the "msdata:Relationship" tags to
configure the relationships between the tables. Note that the VS.NET
schema editor UI does NOT show these relationships. However, when you
read the XSD/XML into a dataset, it recognizes them (you can see them
in the dataset's relations collection) and use the
"row.getchildrows()" function successfully.

The only thing I don't like about the current solution is that the
data for each table is stored in separate XML sections...the data is
not nested. But, it's a minor annoyance and works correctly in the
dataset.

So, do as MSDN says, not as the UI suggests should makes sense.

Note that I'd also tried other things, such as creating the schema in
SQL Server and then opening it in the VS.NET schema editor and saving
that as an XSD. That did not work either...it essentially did the same
thing as I had done the 1st time by creating keys and relations using
the schema editor UI. Editing the XML of the XSD manually was the only
way I found to make this work.

-Ed

Here's the schema:

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="HC_Computers"
targetNamespace="http://tempuri.org/HC_Computers.xsd"
elementFormDefault="qualified"
xmlns="http://tempuri.org/HC_Computers.xsd"
xmlns:mstns="http://tempuri.org/HC_Computers.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:annotation>
<xs:appinfo>
<msdata:Relationship name="ComputerInfo_AccessInfo"
msdata:parent="ComputerInfo" msdata:child="AccessInfo"
msdata:parentkey="DisplayName"
msdata:childkey="DisplayName"></msdata:Relationship>
</xs:appinfo>
</xs:annotation>
<xs:element name="HC_Computers">
<xs:complexType>
<xs:sequence>
<xs:element name="ComputerInfo">
<xs:complexType>
<xs:sequence>
<xs:element name="DisplayName" type="xs:string"
/>
<xs:element name="SystemRefresh"
type="xs:string" />
<xs:element name="DiskRefresh" type="xs:string"
/>
<xs:element name="CPULevelMedium"
type="xs:string" />
<xs:element name="CPULevelHigh"
type="xs:string" />
<xs:element name="MemoryLevelMedium"
type="xs:string" />
<xs:element name="MemoryLevelHigh"
type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="AccessInfo">
<xs:complexType>
<xs:sequence>
<xs:element name="DisplayName" type="xs:string"
/>
<xs:element name="IPorName" type="xs:string" />
<xs:element name="ID" type="xs:string" />
<xs:element name="PW" type="xs:string" />
<xs:element name="Domain" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top