Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old February 17th, 2006, 07:15 PM
Keith Patrick
Guest
 
Posts: n/a
Default Problems with XmlSerializer and namespaces

I have an object, Teacher, that has a namespace. Let's call it http://foo.
Teacher has a child object called Name, composed of String first, middle,
last, etc. Problem I have is when I try to deserialize it. When I
deserialize a single Teacher, it works when I put the namespace on the
Teacher element. However, if I have just the namespace on Teacher, it will
deserialize fine as Teacher. *However*, if I try to deserialize an
ArrayOfTeacher, Teacher.Name doesn't deserialize (it's null); without the
array, it's OK. What I wound up doing was serializing both a Teacher and an
ArrayOfTeacher and found that when it's just TEacher, the serializer puts
the xsd and xsi namespaces on the array & put the http://foo namespace *on
the Name element only*. If I put that same namespace on both Teacher *and*
Name, it comes out OK, except when deserializing an ArrayOfTeacher.
So basically, my problem is: where do I put the namespaces for consistent
deserialization? If the object to be deserialized is in an array, only its
children can have the namespace declared on it, but not vice versa, so I
have no consistent way to represent the Teacher as XML and have it
deserialize both as a single entity and an array of them.


  #2  
Old February 17th, 2006, 07:25 PM
Keith Patrick
Guest
 
Posts: n/a
Default Re: Problems with XmlSerializer and namespaces

BTW: This is the properly serialized version of the array and the single
object, to show the difference in where the namespace is placed; I have not
found a way to deserialize both forms with the same namespace structure:

<!-- Puts namespace on inner-most child -->
<?xml version="1.0" encoding="utf-16"?>
<ArrayOfTeacher xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Teacher Ssn="123-34-3425">
<Name ID="0" LastName="Patrick" FirstName="Richard" MiddleName="K"
Type="01" xmlns="http://www.sifinfo.org/infrastructure/1.x" />
</Teacher>
</ArrayOfTeacher>


<!-- Puts namespace on overall parent (this one actually makes sense to
me...the previous one does not) -->
<?xml version="1.0" encoding="utf-16"?>
<Teacher xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" Ssn="123-34-3425"
xmlns="http://www.sifinfo.org/infrastructure/1.x">
<Name ID="0" LastName="Patrick" FirstName="Richard" MiddleName="K"
Type="01" />
</Teacher>


 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles