473,406 Members | 2,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Flattening XML data during deserialization

Hi,

If I have an XML file that stores its data in a hierarchical relationship,
is there a way to automatically "flatten" this relationship when I
deserialize it (using the XmlSerializer) to a collection of objects?

For example, assume that I have an XML file that contains the following data
for lastnames/firstnames:

Anderson
Bob
Ann
Jones
Betty
Fred
Mark
Smith
Paul
Gina

I'd like to deserialize this file into a set of "Person" objects, with each
Person containing both a lastname and firstname (rather than separate
"LastName" and "FirstName" objects in a hierarchical relationship):

Anderson, Bob
Anderson, Ann
Jones, Betty
Jones, Fred
Jones, Mark
Smith, Paul
Smith, Gina

Is there any Framework way to do this automatically (perhaps by using an
attribute), or do I need to write custom deserialization code to do this?
Many thanks.
Nov 20 '05 #1
2 1921
Deserialize and run through an XSLT stylesheet that gives you what you are
looking for. With XSLT, this exercise will be fairly easy and fast.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************** ********************
Think Outside the Box!
************************************************** ********************
"Robert Jacobson" <rj**********************@nospam.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
Hi,

If I have an XML file that stores its data in a hierarchical relationship,
is there a way to automatically "flatten" this relationship when I
deserialize it (using the XmlSerializer) to a collection of objects?

For example, assume that I have an XML file that contains the following data for lastnames/firstnames:

Anderson
Bob
Ann
Jones
Betty
Fred
Mark
Smith
Paul
Gina

I'd like to deserialize this file into a set of "Person" objects, with each Person containing both a lastname and firstname (rather than separate
"LastName" and "FirstName" objects in a hierarchical relationship):

Anderson, Bob
Anderson, Ann
Jones, Betty
Jones, Fred
Jones, Mark
Smith, Paul
Smith, Gina

Is there any Framework way to do this automatically (perhaps by using an
attribute), or do I need to write custom deserialization code to do this?
Many thanks.

Nov 20 '05 #2
It looks like that will do the trick. Thanks!

"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamM> wrote in
message news:uq**************@tk2msftngp13.phx.gbl...
Deserialize and run through an XSLT stylesheet that gives you what you are
looking for. With XSLT, this exercise will be fairly easy and fast.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************** ********************
Think Outside the Box!
************************************************** ********************
"Robert Jacobson" <rj**********************@nospam.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
Hi,

If I have an XML file that stores its data in a hierarchical relationship, is there a way to automatically "flatten" this relationship when I
deserialize it (using the XmlSerializer) to a collection of objects?

For example, assume that I have an XML file that contains the following

data
for lastnames/firstnames:

Anderson
Bob
Ann
Jones
Betty
Fred
Mark
Smith
Paul
Gina

I'd like to deserialize this file into a set of "Person" objects, with

each
Person containing both a lastname and firstname (rather than separate
"LastName" and "FirstName" objects in a hierarchical relationship):

Anderson, Bob
Anderson, Ann
Jones, Betty
Jones, Fred
Jones, Mark
Smith, Paul
Smith, Gina

Is there any Framework way to do this automatically (perhaps by using an
attribute), or do I need to write custom deserialization code to do this? Many thanks.


Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: zhaounknown | last post by:
I have a field set to Image data type, and store a long string(possible other objects)into it with size 5663, and returned with 5663+28 bytes. These strings wil be deserialized after retrieving....
1
by: solex | last post by:
Hello, Part of my XML application will allow the user to select any field(s) from the hiearchy as output to a CSV file for viewing/ manipulation. The datastore consists of many XML files that...
3
by: parrot toes | last post by:
Summary: I have been trying to make requests of a web service provided by Axis using a dotnet client with code generated by wsdl.exe and have been getting exceptions when trying to process the...
1
by: parrot toes | last post by:
I tried to post this question before, but there was an error when posting. I case it did get posted and in order to avoid duplication, I'll just repost a summary. I have written a dotnet client...
0
by: jcsnippets.atspace.com | last post by:
Hi everyone, I'm trying to read an xml config file in C#. To do this, I have used the xsd.exe tool to create an xsd file from my xml, and to generate code to read this xml file. Here is a...
1
by: jcsnippets.atspace.com | last post by:
Hi everyone, I'm trying to read an xml config file in C#. To do this, I have used the xsd.exe tool to create an xsd file from my xml, and to generate code to read this xml file. Here is a...
2
by: gangesmaster | last post by:
as we all know, * (asterisk) can be used to "inline" or "flatten" a tuple into an argument list, i.e.: def f(a, b, c): ... x = (1,2,3) f(*x) so... mainly for symmetry's sake, why not make a...
4
by: dani k | last post by:
How do I write my own serialization of a class that has non-serializable data members? this problem arose when I tried to serialize RSAParameters, for which the private stuff is not serializable
7
by: Benjamin | last post by:
How would I go about "flattening" a dict with many nested dicts within? The dicts might look like this: {"mays" : {"eggs" : "spam"}, "jam" : {"soda" : {"love" : "dump"}}, "lamba" : 23 } I'd...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.