473,799 Members | 2,665 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XmlElement SetAttribute problem

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

string name = "xmlns:"+"a bc";
string value = "http://www.abc.com";
myElem.SetAttri bute(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 3536


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

string name = "xmlns:"+"a bc";
string value = "http://www.abc.com";
myElem.SetAttri bute(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.Cre ateElement("god s");
XmlAttribute attribute = xmlDocument.Cre ateAttribute("x mlns",
"prefix", xmlns);
attribute.Value = "http://example.org/2004/08/whatever";
rootElement.Set AttributeNode(a ttribute);
xmlDocument.App endChild(rootEl ement);
Console.WriteLi ne(xmlDocument. OuterXml);
}
}

that is you have to use CreateAttribute Node 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
2286
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 xmlns:dt="urn:schemas-microsoft-com:datatypes" Is there a way to do this through the setattribute or createelement methods? Whenever I try all i get is the xmlns="urn:schemas-microsoft-com:datatypes" -------------------------------- From:...
2
3308
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) : base(prefix, localName, namespaceUri, doc) { }
0
1546
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, Brown) and two sizes (Large, Small). My algorithm will run through a special XML tree (not a regular tree,
2
7252
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 = controlDocument.CreateElement( "ns0:MyRootElement" ); rootNode.SetAttribute( "xmlns:ns0", "http://my.namespace.uri" ); controlDocument.AppendChild(rootNode); I'm trying to get it so that it comes out as follows:
6
8069
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 Opera, but in IE the table looks like those properties haven't been set. When I use the 'view generated source' (from webdevelopers toolbar in FF) and I use that to create a static html-page, it looks OK in IE. I've checked but the setAttribute is...
1
1476
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 it to display author/subtitle etc as itunes:author/itunes:subtitle so on XmlElement newElem = doc.CreateElement("item"); XmlElement titleNode = doc.CreateElement("title"); XmlElement authorNode =...
4
5057
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 value then put it back as the oncontextmenu attribute. Here's an example page if you want to try it out... <html> <head> <titletesting </title> <script><!--
2
9043
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. XmlDocument document = new XmlDocument();
2
2289
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 responses in variables. When the user has answered all questions, a report is produced directing the user to take action based on his answers to the questions. Because there are very many questions, these are not presented all at one time. ...
0
9689
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10495
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10269
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10248
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10032
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4148
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2942
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.