Stop xmlns="" being added as attribute to child element.

Hi,


I am trying to open an XML file, clear the child elements of an element and then add a new child element.  This I can do successfully, except that when I do it adds xmlns="" as an attribute of my element.

Example:

  
    
  

Why is it doing things?



This is my code:



string FileName = @"C:\Documents and Settings\whitfies\My Documents\test.xml";

XmlDocument Doc = new XmlDocument();

Doc.Load(FileName);

Doc.DocumentElement.LastChild.RemoveAll();

XmlElement El = Doc.CreateElement("Test");

Doc.DocumentElement.LastChild.AppendChild(El);   
        
Doc.Save(FileName);



Any advice would be apprciated.

Steve
0
jingles
7/12/2007 3:35:23 PM
asp.net.xml-datasource 7181 articles. 0 followers. Follow

2 Replies
428 Views

Similar Articles

[PageSpeed] 20

Hi,

I think one of the parent XML ements or LastChild element hs default namespace declaration.  (Typically it is on the root element).  Something like:

<root xmlns="http://something">

When you add an element without namespace, xmlns="" is added to override default namespace.

-yuriy

0
ysw
7/12/2007 6:06:52 PM
Ah I've fixed it now.

Thanks for your reply.  I'm not sure why my origional post didn't keep any of the carriage returns though, I did format it before I posted it... Weird!


Steve
0
jingles
7/13/2007 7:25:21 AM
Reply:

Similar Artilces:

xmlns="" attribute on child node
I'm using IXmlDocument to write an XML file. The node "leveranse" automatically get a xmlns attribute that is empty. How can I avoid/remove this? Here is my code and result: XML := NewXMLDocument; XML.Encoding := 'utf-8'; XML.Options := [doNodeAutoIndent]; root := XML.AddChild('melding'); root.Attributes['xmlns'] := 'urn:ske:fastsetting:innsamling:slakt:2.0'; root.Attributes['xmlns:xsi'] := 'http://www.w3.org/2001/XMLSchema-instance'; root.Attributes['xsi:schemaLocation'] := '&...

AD driver does not update "name" or "CN" attributes
I have an AD driver that's been running for a little over a year, it's version is 3.5.8 and is running on IDM 3.6.1. My client wishes to change their naming scheme and so I have written a loopback driver that renames user object with the new scheme. Most things work fine, the sAMAccountName and userPrincipalName attributes change appropriately. However, the "name" attribute, which I am guessing is the attribute that is displayed in the AD Users and Computers interface on the AD server, is not changing nor the "CN" attribute. When I perform the rename fr...

superreview granted: [Bug 375493] Adding an element with "counter-increment " does not update subsequent elements with "counter"
David Baron [:dbaron] <dbaron@mozilla.com> has granted superreview: Bug 375493: Adding an element with "counter-increment" does not update subsequent elements with "counter" https://bugzilla.mozilla.org/show_bug.cgi?id=3D375493 Attachment 270416: Patch https://bugzilla.mozilla.org/attachment.cgi?id=3D270416&action=3Dedit ------- Additional Comments from David Baron [:dbaron] <dbaron@mozilla.com> r+sr=3Ddbaron= ...

.Attributes.Add("onclick","...") causes validators to stop working
I added the following line of code to my codebehind and my Validators stopped working. What can I do to make my validators continue to work and still be able to use a confirm() call with the onclick event? btnSubmit.Attributes.Add("onclick", "return confirm('You are about to submit a new application. Continue?');") It's because a javascript for validation is added to the button and your confirmation javascript happens to get called first with the second validation javascript never being invoked.  You can possibly tweak the javasript to include the validation logic (after setting the ...

"type" attribute of "Section" element in web.config file
Hi, I want to create my custom section in web.config, but it dosn`t work and no exceptions are thrown My code: namespace Bus {   public class WebConfigurationSection: ConfigurationSection   {     public WebConfigurationSection()     {     }     [ConfigurationProperty("FromMail", IsRequired=true)]     public String FromMail     {       get { return (string)this["FromMail"]; }       set { this["FromMail"] = value; }   &nb...

.ALLCOL("%COLUMN%", " ", ", ", ", ")
Do you know anyway for me to exclude a subset of columns returned by this function. We have two columns (rec_user and rec_datetime) which are in all of our tables, but when generating triggers I want automatically generate a script which does not include those two columns but does include all other columns in that table. Bruce I should add that I am using PD 9.0.0.580. Bruce "Bruce Lamb" <lamb.bruce@mayo.edu> wrote in message news:6HgI315nCHA.155@forums.sybase.com... > Do you know anyway for me to exclude a subset of columns returned by this > function. ...

Precedence of "where" ("of", "is", "will")?
Nobody on #perl6 today could answer this one. Is: Str | Int where { $_ } the same as: (Str | Int) where { $_ } or: Str | (Int where { $_ }) ? Followup questions, Mr. President: What kind of operators are "where", "of", "is", and "will"? Is there a reason that S03 doesn't list them? What are their precedence(s)? -- Chip Salzenberg - a.k.a. - <chip@pobox.com> Open Source is not an excuse to write fun code then leave the actual work to others. Chip Salzenberg writes: &...

A problem when added btnName.Attributes.Add("onclick","return Validate()");
I added btnName.Attributes.Add("onclick","return Validate()"); to make validations befor page is submited but it ignores validations and submites pages even if validation is not valid. I tried to put 'function Validate(){return false;}' it ignores it! Does anybody knows why is that? Thanks in advance. remove the returnChristian CalderonNeed to work in Classic ASP? then do it the right way with CLASP!Classic ASP Framework btnName.Attributes.Add("onclick","Validate()");Christian CalderonNeed to work in Classic ASP? then do it the right way w...

Dynamically adding "Child" User Controls to "Parent" User Control
Hello group..Need some advice/help with some issue...Am having trouble dealing with nested user controls that i will be having. My business need is as follows...Need to display a Page Header , data Grid(for some details) and Page footer...And the grid will display only a set of data. If i have more data, the parent page should have another set of Page Header, data Grid and Page Footer. So, this is how it looks like***************************Page HeaderGridPage Footer--------Page Break---------Page HeaderGridPage Footer--------Page Break---------Page HeaderGridPage Footer--------Page Break---...

Calling A VB.NET Function in TextBox1.Attributes.Add("OnKeyUp", "search_log()")
Please tell me where i am wrong.  I am trying to call a vb.net function in attributes.add("OnKeyUp", "search_log()")   Function search_log() some codes here End Function   There is an error that "object expected"   Please Help JavaScript can not call a function that is serverside code. It can only call JavaScript code. If you want to call code on the server, you should ook into using the Ajax controls. Eric Pascarello.com | Twitter epascarello | LinkedIn Hi, I suggest you use pagemethod. For more infomation, see http...

Adding "emocions" or "emotions"
Not really sure what the funny faces are called, but is there a way to use them with newsgroups? They are available in other mail, but not here. Thanks! Steve Stephen Fox wrote: > Not really sure what the funny faces are called, but is there a way to > use them with newsgroups? They are available in other mail, but not here. This isn't mail. If you use the standard smiley punctuation, it will work just as well -- probably better, actually -- as an actual graphic character :-) However... Tools/options/display/formatting/'display emoticons as graphics&...

"Attribute" vs. "Property"
I just want to verify that I properly understand the use of these two terms in Perl 6. * An "attribute" is a data member of a class. * A "property" is a piece of metadata on a...uh...thing -- e.g., on an attribute, on a class, or on a method. Do I have it right? For some reason, I've always referred to class data members as "properties", and thought of metadata on such things as "attributes" -- the reverse of the above. This despite the use of "attribute" in the above usage in Damian's book. So do I just need to t...

quotes, quotes, quotes...
I am getting this error and I know what is causing it, but I have no idea how to fix it, any help would be great. The script steps through the /var/log/messages file on a linux server and puts The entries into a mysql database. However when it gets to the 'hlt' line in the messages file it just barfs. The single quotes are freaking it out. I know about quotes but not how to use in this situation. Thanks, Paul Error: May 27 17:53:00 localhost kernel: Checking 'hlt' instruction... OK. <----- doesn't like this in the messages file DBD::mysql::st exec...

superreview requested: [Bug 286010] Attribute selector rewrites selectorText so that element[attribute] looks like element[attribute=""] : [Attachment 178627] Same as diff -w
Boris Zbarsky <bzbarsky@mit.edu> has asked David Baron <dbaron@mozilla.org> for superreview: Bug 286010: Attribute selector rewrites selectorText so that element[attribute] looks like element[attribute=""] https://bugzilla.mozilla.org/show_bug.cgi?id=286010 Attachment 178627: Same as diff -w https://bugzilla.mozilla.org/attachment.cgi?id=178627&action=edit ...

Web resources about - Stop xmlns="" being added as attribute to child element. - asp.net.xml-datasource

Resources last updated: 1/10/2016 9:52:07 PM