473,326 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

XmlElement SetAttribute problem

I'm doign the following:
XmlElement myElem....;

string name = "xmlns:"+"abc";
string value = "http://www.abc.com";
myElem.SetAttribute(name, value);

I get an exception saying that name cannot have ':' in it. However, MSDN
usage doc for this method explicitly says that ':' will be parsed and the
prefix would be retrieved.

Any help would be appreciated!

Nov 12 '05 #1
1 3506


nibble wrote:
I'm doign the following:
XmlElement myElem....;

string name = "xmlns:"+"abc";
string value = "http://www.abc.com";
myElem.SetAttribute(name, value);

I get an exception saying that name cannot have ':' in it. However, MSDN
usage doc for this method explicitly says that ':' will be parsed and the
prefix would be retrieved.


If you want to create a namespace attribute I think you have to do it as
follows:

using System;
using System.Xml;

public class Test2004082101 {
public static void Main (string[] args) {
string xmlns = "http://www.w3.org/2000/xmlns/";
XmlDocument xmlDocument = new XmlDocument();
XmlElement rootElement = xmlDocument.CreateElement("gods");
XmlAttribute attribute = xmlDocument.CreateAttribute("xmlns",
"prefix", xmlns);
attribute.Value = "http://example.org/2004/08/whatever";
rootElement.SetAttributeNode(attribute);
xmlDocument.AppendChild(rootElement);
Console.WriteLine(xmlDocument.OuterXml);
}
}

that is you have to use CreateAttributeNode and you have to make sure
you have the right namespace when you create the attribute.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 12 '05 #2

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

Similar topics

2
by: Matt Torline via .NET 247 | last post by:
I am trying to duplicate an xml document, and I am pretty new to xml. I am using hte Xml namespace and taking advantage of the xmldocument class. I would like to add the following to an element ...
2
by: Compic | last post by:
Hi! I have this class: public class StoredItemElement : XmlElement { protected internal StoredItemElement(string prefix, string localName, string namespaceUri, XmlDocument doc) :...
0
by: ryanr | last post by:
I've run into a problem with a recursive algorithm. Basically, it grabs a tree, and creates premutations based off it. For example: Suppose you have you sell shoes in two colors (Black,...
2
by: Christoph | last post by:
I'm using the following code to create what will be the root element of my XML document. XmlDocument controlDocument = new XmlDocument(); //add root node XmlElement rootNode =...
6
by: Pugi! | last post by:
I use mycurrent_cell.setAttribute("style", "background-color:green"); and mycurrent_cell.setAttribute("colspan", "3"); to set some attributes of a table. The code works perfect in FireFox and...
1
by: funkymp | last post by:
im trying to create a user interface that allows a user to upload there own mixes which are then added to a itunes podcast. basically, my problem is. when it updates the podcast.xml file, i need...
4
by: ICPooreMan | last post by:
I've got some code which works in firefox that's giving me fits in IE7 (maybe other versions too I haven't tested it). What I want to do is get the oncontextmenu attribute of something, change the...
2
by: nygiantswin2005 | last post by:
Hi I have wrote a method in my C# class with the following code, to create an XMl file. The root element is suppose to have 3 attibutes. I can not get attributes to appear correctly. ...
2
by: tbullock | last post by:
Hello Forum, I am using FireFox 3.0.1 and Internet Explorer 7.0. My operating system is Vista. My application is using client-side Javascript. It asks many questions of the user and saves user...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.