473,473 Members | 1,935 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Can't deserialize when root node has a qualified name

JMD
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 show what goes in this root element) contains:

<xs:element name= "ImageBox" type="ns:ImageBox_t" form="qualified"
/>

I use a validating reader to pull this into an XmlDocument. Then, step
through the immediate children of the DocumentElement and then create
individual objects based on what I found. To do that,

XmlNodeReader nodereader= new XmlNodeReader (el);
XmlSerializer s= blah blah blah
ImageBox_t newbie= (ImageBox_t) s.Deserialize (nodereader);
// >> do something with newbie.

That worked fine in a different XML file, where that shcema contains:

<xs:element name="ImageBox" type="MIM:ImageBox_t" />

The prefix is different, but both XSD files have the same
targetNamespace which is the same namespace as the targetNamespace in
the XSD file where ImageBox_t is defined. Note that there is only one
place where ImageBox_t is defined, and I am not trying to read
different things with one serializer as is so often the answer in these
posts.

Now, when deserializing from the file that contains
<clinical:Imagebox>... , where clinical is the prefix defined for that
namespace in that XML file, I got an error deserializing to the effect
of "<ImageBox xmlns='blahblah'> was not expected.

I added an [XmlRoot] C# attribute to the ImageBox class definition
telling it the Namespace to expect. Now it deserializes it without
complaint.

BUT, the object is empty. It did not object to the opening tag's name,
but it ignored everything inside it without complaint, and left the
object with [XmlAttribute] things set and any [XmlElement]'s left where
the default constructor had it.

*** >>> I'm at my wit's end here. How can I get the deserializer to
read from this initial node that has a qualified name?

Meanwhile, now it did not read the first one anymore, with a similar
but opposite error. I could not change the XmlNode I started from
because (1) the NamespaceURI is read-only and (2) there is no public
constructor to make a new one copying over all the children, and (3)
changing the Prefix didn't do anything. So I used
XmlAttributeOverrides to change the XmlRoot Namespace back to empty,
and use two different XmlSerializer's based on whether a namespace is
present or not in that node:

XmlSerializer s= (el.NamespaceURI == string.Empty) ?
my_serializer_NC : my_serializer;

That part works, but is a work-around. I would like to know how to get
the serializer to properly recognise that the element is indeed in the
same target namespace.

But my show-stopping problem, which I must do something about quickly,
is getting the prefixed one to be read at all. It's just not working,
no work-around in sight!

Please help.

--John

Nov 12 '05 #1
0 1476

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

Similar topics

8
by: Michael Wohlwend | last post by:
Hi, this is my first xpath try and after reading many web-pages that xpath is still not working :-( (btw, it's my own project, not a homework) I have something like that: <root> <one/>
0
by: Julia | last post by:
Hi,i am trying to DeSerialize the following class from an XML string and i get "<root xmlns=''> was not expected." public class Person { private string m_Name; private string m_Phone; ...
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\"...
5
by: Geoff | last post by:
Is it possible to pull a single node (element) out of a complex XML file, using SelectSingleNode(), and then deserialize that node to an object? Could someone please post, or point me to, a...
4
by: Samuel R. Neff | last post by:
I'm deserializing an XML file. If I pass a Stream to the file directly to the deserializer as follows it works fine: o = (New XmlSerializer( GetType(...
4
by: David S. Alexander | last post by:
I am trying to transform XML to XML using an XSLT in C#, but the root node of my XML is not being matched by the XSLT if it has an xmlns attribute. Am I handling my namespaces incorrectly? My C#...
0
by: RJN | last post by:
Hi I have to read an xml and add the node elements into a hashtable with nodename as key and nodetext as value. If the selected node has childnodes, then value should go as an array. for eg.,...
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...
6
by: Redowl | last post by:
Hi, I am having an issue deserializing a business object from a SQL stored procedure. I have created the class using the XSD tool and the resulting XMLDATA schema but when I try to create the...
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
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.