Connecting Tech Pros Worldwide Forums | Help | Site Map

Serialize XML with Qualified or Prefixed Root Element

Hone
Guest
 
Posts: n/a
#1: Oct 26 '06
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.

How do you make this work?

John Saunders
Guest
 
Posts: n/a
#2: Oct 28 '06

re: Serialize XML with Qualified or Prefixed Root Element


"Hone" <Hone@discussions.microsoft.comwrote in message
news:27D11D1B-7D9F-40F2-A1F2-0C650802009D@microsoft.com...
Quote:
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.
>
How do you make this work?
It would help if you were to elaborate.

John


Hone
Guest
 
Posts: n/a
#3: Oct 30 '06

re: Serialize XML with Qualified or Prefixed Root Element


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.

"John Saunders" wrote:
Quote:
"Hone" <Hone@discussions.microsoft.comwrote in message
news:27D11D1B-7D9F-40F2-A1F2-0C650802009D@microsoft.com...
Quote:
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.

How do you make this work?
>
It would help if you were to elaborate.
>
John
>
>
>
John Saunders
Guest
 
Posts: n/a
#4: Oct 31 '06

re: Serialize XML with Qualified or Prefixed Root Element


"Hone" <Hone@discussions.microsoft.comwrote in message
news:C09C4EEC-5B44-476B-BCC4-0AB64A8F2D06@microsoft.com...
Quote:
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.
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


Phil Galey
Guest
 
Posts: n/a
#5: Nov 13 '06

re: Serialize XML with Qualified or Prefixed Root Element


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.



"Hone" <Hone@discussions.microsoft.comwrote in message
news:27D11D1B-7D9F-40F2-A1F2-0C650802009D@microsoft.com...
Quote:
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
Quote:
a namespace, but cannot achieve this with the root element, which is
required
Quote:
to serialize and deserialize RDF documents.
>
How do you make this work?

Closed Thread