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 / March 2007

Tip: Looking for answers? Try searching our database.

Redundant xmlns attribute

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Greg - 15 Mar 2007 21:51 GMT
If I have an XmlDocument with a deep hierarchy of nodes, with a
documentElement having an attribute xmlns="http://someurl.com" and all
children inheriting that namespace (but not having the xmlns attribute
explicitly declared), then why is it that when I perform
appendChild(someNode) on an existing node deep in the hierarchy, where
someNode has been created by an XmlSerializer with the namespace set to be
the aforementioned "http://someurl.com", the appended node has the xmlns
attribute explicitly declared in the output of saving the XmlDocument?

In other words, why doesn't AppendChild() remove redundant attributes that
are inherited from the parent, specifically xmlns?

Oh, it does?  How do I instruct it to?

Greg
John Saunders - 16 Mar 2007 17:10 GMT
> If I have an XmlDocument with a deep hierarchy of nodes, with a
> documentElement having an attribute xmlns="http://someurl.com" and all
[quoted text clipped - 7 lines]
> In other words, why doesn't AppendChild() remove redundant attributes that
> are inherited from the parent, specifically xmlns?

May I ask, why do you care? The "xmlns" aren't really attributes. They're
namespace declarations. What kind of problem is this causing you?

John
Greg - 19 Mar 2007 16:28 GMT
Having the redundant ns declarations bloats the file and slows parsing.  I do
not know if it bloats/slows transmission of a similar hierarchy such as an
array of objects converted with XmlSerializer in the following web service:

[WebMethod]
MyStruct[] foo() {
  MyStruct[] bar = new MyStruct[5];
  for (int i = 0; i < 5 ++i) {
     bar[i] = new MyStruct();
  }
  return bar;
}

Does each MyStruct in bar have its own namespace declaration in transit as
below, or does each MyStruct inherit the namespace declaration of
ArrayOfMyStruct?

<ArrayOfMyStruct xmlns="http://yadayada">
 <MyStruct xmlns="http://yadayada">
   ...
 </MyStruct>
 <MyStruct xmlns="http://yadayada">
   ...
 </MyStruct>
 ...
</ArrayOfMyStruct>

I am just trying to optimize my program for transmission/space/UI-latency
and XML handling is often a major offender.  Having an Xml web-service that
transmits twice as much information as is necessary to yield the same effect
is silly, annoying, and detracts from a product that consumes it.

Greg  

> > If I have an XmlDocument with a deep hierarchy of nodes, with a
> > documentElement having an attribute xmlns="http://someurl.com" and all
[quoted text clipped - 12 lines]
>
> John
John Saunders - 19 Mar 2007 18:02 GMT
> Having the redundant ns declarations bloats the file and slows parsing.  I
> do
[quoted text clipped - 31 lines]
> effect
> is silly, annoying, and detracts from a product that consumes it.

Thanks for the reply, Greg.

My only addition is to ask by how much does it detract from the program that
consumes it?  Have you measured the performance loss versus the cost of
fixing the problem?

Also, have you measured just how bad the problem is? Is the file really
twice as large?

Thanks,
John

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.