Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / February 2007

Tip: Looking for answers? Try searching our database.

Removing xmlns:xsd and xmlns:xsi when using ImportNode

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Keith Patrick - 22 Feb 2007 21:12 GMT
I'm doing some document merging where I want to bring in an XmlDocument and
import its document element into another document deeper in its tree.
However, when serializing my underlying objects, .Net likes to add these
namespaces:
<RootNode xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <ChildNode xmlns="MyObjectHierarchyNamespace/>
</RootNode>

The problem this is causing me is that any node(s) that have those
namespaces get properly imported into the XML, but those nodes fail to
deserialize. Is there a wya to prevent the aforementioned namespace issue
(in either importation or deserialization) without manually removing the
attributes during merging?
John Saunders - 23 Feb 2007 00:36 GMT
> I'm doing some document merging where I want to bring in an XmlDocument
> and import its document element into another document deeper in its tree.
[quoted text clipped - 10 lines]
> (in either importation or deserialization) without manually removing the
> attributes during merging?

Keith, if they fail to deserialize, it's probably because you don't have the
correct namespaces declared on the properties they should deserialize into.
For instance, what namespace do you have declared on the ChildNode property?

In other words, this is more likely because of the
xmlns="MyObjectHierarchyNamespace" rather than because of the xmlns:xsd or
xmlns:xsi namespace nodes.

Here's a very brief lesson on XML namespaces, in case you need it:

<foo xmlns="bar"/>

and

<foo xmlns="baz"/>

Are elements of two totally different and unrelated types. If you had a
property that the first one deserialized into, you would not want the second
one to be able to deserialize into that same property, because it's a
totally different entity that happens to also have the local name "foo".

John
Keith Patrick - 23 Feb 2007 15:39 GMT
I've got all my classes tagged with XmlType("MyObjectHierarchyNamespace")
but not the properties of those types. But the thing is, my namespace is
already being declared on the primary document so that when it merges in,
I'll have:

   <Grades xmlns="MyObjectHierarchyNamespace">
       <Grade Name="1st">
           <Subjects>
               <Subject Name="Math">
                   <Segments>
                       <Segment Name="SegmentOne" />
                   </Segments>
               </Subject>
               <Subject Name="English">
                   <Segments>
                       <Segment Name="SegmentOne">
                           <Modules>
                               <Module
xmlns="MyObjectHierarchyNamespace"/>
                               <Module />
                               <Module />
                           </Modules>
                           .
                           .
                           .

In this case, everything shows up except that first module (Modules contains
2 Module objects).  public class Module has
XmlType("MyObjectHierarchyNamespace") as does ModuleCollection, but not the
property Modules
Keith Patrick - 23 Feb 2007 15:53 GMT
Ahh, found a fix. I was using XmlTypeAttribute, but converting to
XmlRootAttribute wound up working.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.