Flat xml from typed dataset

G

Guest

Hi all,

I use a typed dataset in my applicaiton. There are three levels defined in
the .xsd, first level is member, which has child element named plan, which
has child element named fund. The structure looks like:
<xs:element name="mem">
<xs:complexType>
<xs:sequence>
<xs:element name="plan" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:element name="fund" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence></xs:sequence>
<xs:attribute name="fund_key" form="unqualified"
type="xs:string" />
<xs:attribute name="plan_key" form="unqualified"
type="xs:string" />
<xs:attribute name="fund_value" form="unqualified"
type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="plan_key" form="unqualified" type="xs:string" />
<xs:attribute name="mem_key" form="unqualified" type="xs:string" />
<xs:attribute name="plan_name" form="unqualified" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="mem_key" form="unqualified" type="xs:string" />
<xs:attribute name="mem_name" form="unqualified" type="xs:string" />
</xs:complexType>
<xs:key name="memKey1">
<xs:selector xpath="." />
<xs:field xpath="@mem_key" />
</xs:key>
<xs:keyref name="mem_plan" refer="memKey1">
<xs:selector xpath=".//mstns:mem_plan" />
<xs:field xpath="@mem_key" />
</xs:keyref>
<xs:key name="memKey2">
<xs:selector xpath=".//mstns:mem_plan" />
<xs:field xpath="@plan_key" />
</xs:key>
<xs:keyref name="plan_fund" refer="memKey2">
<xs:selector xpath=".//mstns:plan_fund" />
<xs:field xpath="@plan_key" />
</xs:keyref>
</xs:element>
I also defined nested relationship. But when I get xml from the dataset, the
file is flat format instead nested.
For example, I have a member, who has 2 plans, each plan has 2 funds. I want
to get a xml file like:
<mem1 mem_key=1 mem_name=john >
<plan1 plan_key=1 mem_key=1 plan_name=ESP>
<fund1 fund_key=1 plan_key=1 fund_value=20 />
<fund2 fund_key=2 plan_key=1 fund_value=30 />
</plan1>
<plan2 plan_key=2 mem_key=1 plan_name=RRSP>
<fund3 fund_key=3 plan_key=2 fund_value=20 />
<fund4 fund_key=4 plan_key=2 fund_value=30 />
</plan2>
</mem1>
But what I got is:
<mem1 mem_key=1 mem_name=john />
<plan1 plan_key=1 mem_key=1 plan_name=ESP/>
<plan2 plan_key=2 mem_key=1 plan_name=RRSP/>
<fund1 fund_key=1 plan_key=1 fund_value=20 />
<fund2 fund_key=2 plan_key=1 fund_value=30 />
<fund3 fund_key=3 plan_key=2 fund_value=20 />
<fund4 fund_key=4 plan_key=2 fund_value=30 />

Could anyone give me a sample code to fix it?

Thanks in advance.

william
 
R

RYoung

I believe I had a similar situation. I had "Document" as a root element, and
"CareBill" and "DocumentChanges" as elements relelated to a Document,
therefore child elements. I designed all three as elements in the VS
designer, and established the relationship. But the xml came out flat, and
not nested. So, I designed the CareBill and DocumentChanges as complex
types - CareBillType, and DocumentChangeType. In my Document element I added
two more element names - CareBill which is a CareBillType, and Changes which
is DocumentChangeType. that gave me the nested xml, and makes more sense
anyways.

Ron
 

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