473,388 Members | 1,256 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,388 software developers and data experts.

How do I serialize element references as IDREFs?

Hi,

Is it possible in .NET XML serialization to store element references in
attributes, maybe using IDs and IDREF? For element references, I always get a
copy of the element instead of a reference in the XML code.

That's what I want:

<FlightData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="htt
p://www.w3.org/2001/XMLSchema" xmlns="http://demo.ns/flightdata">
<airport code="FRA" cityName="Frankfurt" />
<airport code="SFO" cityName="San Francisco" />
<flight flightNumber="UA2344" from="#FRA" to="#SFO" />
</FlightData>

That's what I get instead:

<FlightData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="htt
p://www.w3.org/2001/XMLSchema" xmlns="http://demo.ns/flightdata">
<airport code="FRA" cityName="Frankfurt" />
<airport code="SFO" cityName="San Francisco" />
<flight flightNumber="UA2344">
<from code="FRA" cityName="Frankfurt" />
<to code="SFO" cityName="San Francisco" />
</flight>
</FlightData>

Is there any combination of serialization attributes that can accomplish this,
or do I have to use a custom XML serializer? BTW, I'm using Visual Studio
2008.

Regards,
Niklas

Jun 27 '08 #1
2 2313
Niklas Deutschmann wrote:
Is there any combination of serialization attributes that can accomplish this,
or do I have to use a custom XML serializer? BTW, I'm using Visual Studio
2008.
SOAP serialization does allow references I think. It will however not
have the format you describe.

The new DataContractSerializer in .NET 3.5 also allows references to
objects. Here is an example from MSDN:
------------------------- quote -------------------------------------
For these reasons, some DataContractSerializer constructor overloads
have a preserveObjectReferences parameter (the default is false). When
this parameter is set to true, a special method of encoding object
references, which only WCF understands, is used. When set to true, the
XML code example now resembles the following.
<PurchaseOrder ser:id="1">
<billTo ser:id="2"><street ser:id="3">123 Main St.</street></billTo>
<shipTo ser:ref="2"/>
</PurchaseOrder>

----------------------- quote ----------------------------------------

The documentation is here:
http://msdn.microsoft.com/en-us/library/ms731073.aspx
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 27 '08 #2
Hi Martin,
The new DataContractSerializer in .NET 3.5 also allows references to
objects. Here is an example from MSDN
So, if I'm understanding it correctly, with this kind of serialization, I
cannot choose the attributes for ID and reference myself? I would like to say
that "code" is the identifying attribute of "Airport", for instance, and that
any reference to an "Aiport" should be encoded as an ID reference with the
"code" attribute of this "Aiport".

Regards,
Niklas
Jun 27 '08 #3

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

Similar topics

3
by: Rabe | last post by:
Hi all, here a little brain-twister (starting to spoil my weekend if I do not find a solution ... ;-) ) What I want to do is to find a XML-Schema expression that builds a grammar for the...
0
by: IMS.Rushikesh | last post by:
Hi All, I want to serialize an object which contain the DataTable. As DataSet is MarshalByRef object and is serializable. I am using it directly. Even my data is also serialize and save it to...
2
by: Alex | last post by:
I have a XML node defined as such: <node element="data"/> this loads into my class correctly: class node { public string element;
7
by: Microsoft News | last post by:
Hi all. Does id() xpath function work in System.XML? I have built dtd, schema, xdr for a simple xml which includes attributes definded as ID and IDREFS. Validation is occurring properly for all...
3
by: MAY | last post by:
Hi, I have a problem about serialize the form controls. I wrote a test program to test serialize a from but fail (->An unhandled exception of type...
3
by: Jerry | last post by:
Hi, I have a class like the following: class A { private B _b; A (B b) { _b = b; } ...
2
by: films | last post by:
I understand the concept. Serialization of a class will add all the sub-objects of the class to the stream if there are also serializible. So say I have: class Author {
6
by: Mark | last post by:
In a specification I'm designing, I'd like to specify that the order of Names (IDs) in an attribute value of datatype IDREFS is significant. My question is if most real-world XML parsers...
4
by: Hone | last post by:
I'm trying to serialize/deserialize the XML for an RSS 1.0 Feed (i.e. RDF) and the root element, as required by the standard, looks like this: <rdf:RDF ...> </rdf:RDF> However, I've tried...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.