all groups > dotnet xml > october 2006 >
You're in the

dotnet xml

group:

Serialize XML with Qualified or Prefixed Root Element


Serialize XML with Qualified or Prefixed Root Element Hone
10/26/2006 12:59:02 PM
dotnet xml:
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 everything using XmlRootAttribute, XmlTypeAttribute,
XmlSerializerNamespacesAttribute, etc, and nothing will serialize to or
deserialize from this root element format.

I can get child elements to be prefixed by using the XmlElementAttribute and
a namespace, but cannot achieve this with the root element, which is required
to serialize and deserialize RDF documents.

Re: Serialize XML with Qualified or Prefixed Root Element John Saunders
10/28/2006 12:00:00 AM
[quoted text, click to view]

It would help if you were to elaborate.

John

Re: Serialize XML with Qualified or Prefixed Root Element Hone
10/29/2006 10:06:01 PM
Ok, I'm using XmlSerializer to serialize and deserialize an object to Xml.
Primarily, I am attempting to use the XmlSerializer.Deserialize method to
deserialize an RSS 1.0 (RDF) feed directly into a .NET object.

However, by the specification of the RSS 1.0 (RDF) format, the root element
of the Xml should be <rdf:RDF>.

I have tried everything with the .NET framework to create a .NET class that
will serialize or deserialize to Xml that can begins with a prefixed or
qualified root element such as <rdf:RDF>.

I can use the XmlElement tag to generate Xml elements with a prefix,
however, I cannot make this work for the root element. No combination of
XmlRootAttribute, XmlTypeAttribute, etc will serialize or deserialize Xml
files with a prefixed or qualified root element.

[quoted text, click to view]
Re: Serialize XML with Qualified or Prefixed Root Element John Saunders
10/30/2006 9:59:48 PM
[quoted text, click to view]

Here's the declaration of a class which is at the root of my XML:

[XmlType("testResults",
Namespace = "urn:testResults.namespace.com")]
public class TestResults
{
}


John

Re: Serialize XML with Qualified or Prefixed Root Element Phil Galey
11/13/2006 4:05:38 PM
Answer:

1. Instantiate an XmlSerializerNamespaces object.
2. Use the Add method of the object to add all (prefix, namespace) pairs
needed.
3. Include the object as the third parameter in the Serialize method of the
XMLSerializer object.



[quoted text, click to view]

AddThis Social Bookmark Button