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

Deserialize Attribute with a Namespace

Jon
I have an xml document like so...

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:ng="http://newsgator.com/schema/extensions">
<channel>
<title></title>
<link></link>
<description></description>

...

</channel>
</rss>

What .NET XmlAttribute properties do I need to use in order to
deserialize the namespace value?

I tried this and a bunch of other options, but nothing seems to work.

[XmlAttribute("ng", "http://newsgator.com/schema/extensions")]
public string XmlnsNg {
get {
return _xmlnsNg;
}
set {
_xmlnsNg = value;
}
}
Thanks in advance!

Jon

Jan 19 '07 #1
3 3475
The namespace declaration is not the same as an attribute, even though they
are declared in the same way (although I think I stated it incorrectly in a
different message). The namespace itself would be applied to the "RSS"
class as part of the XmlRootAttribute decl.

BTW: Hint for figuring this stuff out -xsd.exe. You can generate a schema
for the XML (VS.Net's XML menu does that) and then generate a class for the
schema (xsd MySchema.xsd /classes), which will show you how the runtime
expects the attributes to be applied.

Jan 19 '07 #2
Jon

Keith Patrick wrote:
The namespace declaration is not the same as an attribute, even though they
are declared in the same way (although I think I stated it incorrectly in a
different message). The namespace itself would be applied to the "RSS"
class as part of the XmlRootAttribute decl.

BTW: Hint for figuring this stuff out -xsd.exe. You can generate a schema
for the XML (VS.Net's XML menu does that) and then generate a class for the
schema (xsd MySchema.xsd /classes), which will show you how the runtime
expects the attributes to be applied.

Thanks Keith.

I'm trying that. Here's where I'm at.

I generated the xsd:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
xmlns:ng="http://newsgator.com/schema/extensions"
xmlns:dc="http://purl.org/dc/elements/1.1/"
attributeFormDefault="unqualified" elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="http://newsgator.com/schema/extensions" />
<xs:import namespace="http://purl.org/dc/elements/1.1/" />
<xs:import namespace="http://purl.org/rss/1.0/modules/slash/" />
<xs:import namespace="http://wellformedweb.org/CommentAPI/" />
<xs:element name="rss">
<xs:complexType>
<xs:sequence>
<xs:element name="channel">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string" />
<xs:element name="link" type="xs:string" />
<xs:element name="description" type="xs:string" />
<xs:element ref="ng:mceImage" />
<xs:element maxOccurs="unbounded" name="item">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string" />
<xs:element name="pubDate" type="xs:string" />
<xs:element name="link" type="xs:string" />
<xs:element ref="dc:creator" />
<xs:element minOccurs="0" maxOccurs="unbounded"
name="category" type="xs:string" />
<xs:element name="guid">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="isPermaLink"
type="xs:boolean" use="required" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="description" type="xs:string" />
<xs:element ref="slash:comments" />
<xs:element name="comments" type="xs:string" />
<xs:element ref="wfw:comment" />
<xs:element ref="wfw:commentRss" />
<xs:element minOccurs="0" name="enclosure">
<xs:complexType>
<xs:attribute name="url" type="xs:string"
use="required" />
<xs:attribute name="length"
type="xs:unsignedInt" use="required" />
<xs:attribute name="type" type="xs:string"
use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="version" type="xs:decimal" use="required" />
</xs:complexType>
</xs:element>
</xs:schema>

When I run XSD.exe I get this:

Schema validation warning: The
'http://newsgator.com/schema/extensions:mceImage' element is not
declared. Line 16, position 16.
Schema validation warning: The
'http://purl.org/dc/elements/1.1/:creator' element is not declared.
Line 23, position 22.
Schema validation warning: The
'http://purl.org/rss/1.0/modules/slash/:comments' element is not
declared. Line 35, position 22.
Schema validation warning: The
'http://wellformedweb.org/CommentAPI/:comment' element is not declared.
Line 37, position 22.
Schema validation warning: The
'http://wellformedweb.org/CommentAPI/:commentRss' element is not
declared. Line 38, position 22.

Warning: Schema could not be validated. Class generation may fail or
may produce incorrect results.

Error: Error generating classes for schema ''.
- The element 'http://newsgator.com/schema/extensions:mceImage' is
missing.

If you would like more help, please type "xsd /?".
Any ideas?

Jan 22 '07 #3
Jon
When I run XSD.exe I get this:
may produce incorrect results.

Error: Error generating classes for schema ''.
- The element 'http://newsgator.com/schema/extensions:mceImage' is
missing.

If you would like more help, please type "xsd /?".
Any ideas?

I got this to work, but it doesn't generate the declarations for the
namespaces and doesn't create a property for them like it does for
other attributes.

I think I'm okay. I will just not render the attributes as well.

Jan 22 '07 #4

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

Similar topics

2
by: Greg | last post by:
I'm writing a class in C# .... I have a collection calls Reports made up of Report objects. I'm trying to deserialize an XML file that looks like : <Reports> <Report> <Title>some title</Title>...
4
by: Sebastien Tardif | last post by:
Subject: XmlSerializer.Deserialize complain when root declare the namespace If I do XmlSerializer.Deserialize( myString ) and myString is: String myString = "<?xml version=\"1.0\"...
0
by: JMD | last post by:
I have a set of schemas for two different XML files that share common structures through the use of "import". Eventually, the main XSD file (which just gathers pieces from the common stuff to...
5
by: Rene | last post by:
I created a class (SomeClass), on that class, I declared a delegate (OnXyz) and then declared an event based on that delegate (Xyz). All this in the same class. After that, I created another class...
0
by: Matt S | last post by:
Hello, I'm trying to build a C# client to consume an AXIS Web Service (running SOAP over HTTP). The Web Service encodes full server-side exception traces in the Soap Fault > Detail element...
1
by: Yewen Tang | last post by:
I have a schema file datamodel.xsd, element "properties" is declared as a type of "baseProperty". The schema file also defines "derivedProperty" is a derived type of "baseProperty". <?xml...
0
by: PSingh | last post by:
Hi, I know this is a frequently asked question but have tried several combinations and cant seem to figure this out. I am serializing my object as follows: XmlSerializer serializer = new...
0
by: anchiang | last post by:
Hi All, I have XML: <RegistryResponse status="Success" xmlns="urn:oasis:names:tc:ebxml-regrep:registry:xsd:2.1"> <AdhocQueryResponse xmlns="urn:oasis:names:tc:ebxml-regrep:query:xsd:2.1"> ...
9
by: =?Utf-8?B?ai5hLiBoYXJyaW1hbg==?= | last post by:
Hi, I have a schema that has an optional element, fieldTag4000Field. If the element is omitted from the XML request, when it is deserialized, it will be null when I check it - which is fine. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.