473,513 Members | 2,425 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I prefix attributes with a namespace?

I need to create xml like the following:
<item mynamespace:name="MyName" mynamespace:age="100" />

I am using code similar to this:
XmlDocument meegoInfo = _LoadTemplateXml("Avatar");

// Create downlevel item
XmlNode node= xmlDoc.DocumentElement;
XmlElement item = xmlDoc.CreateElement("item");
item.SetAttribute("name", "MyName");
item.SetAttribute("age", "100");
node.AppendChild(item);

Cheers,

Sam-I-Am
Nov 16 '05 #1
1 3046
Then you will need to use XmlAttribute rather than SetAttribute.
You will need to associate an URI with the namespace prefix.

XmlAttribute a = [XmlDocument].CreateAttribute
("mynamespace", "name", "http://ourcompany.com/mynamespace/");
[XmlNode].Attributes.Append(a);

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Sam-I-Am" <sa****@3hgroup.com> wrote in message
news:eD**************@tk2msftngp13.phx.gbl...
I need to create xml like the following:
<item mynamespace:name="MyName" mynamespace:age="100" />

I am using code similar to this:
XmlDocument meegoInfo = _LoadTemplateXml("Avatar");

// Create downlevel item
XmlNode node= xmlDoc.DocumentElement;
XmlElement item = xmlDoc.CreateElement("item");
item.SetAttribute("name", "MyName");
item.SetAttribute("age", "100");
node.AppendChild(item);

Cheers,

Sam-I-Am

Nov 16 '05 #2

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

Similar topics

0
1172
by: Ajay | last post by:
hi! for the XML <appel:RULESET xmlns:appel="http://www.w3.org/2001/02/appelv1" xmlns:p3p="http://www.w3.org/2000/12/p3pv1"> <appel:RULE prompt="no"> <p3p:POLICY> <p3p:ACCESS...
4
12140
by: AP | last post by:
Hi, I have a class that I wish to serialize to XML, part of which looks like this: public class TitleNotification { public string NoNameSpaceSchemaLocation =...
6
2561
by: Martin | last post by:
Hi, I have a xml file like the one below <?xml version="1.0" encoding="utf-8"?><e1 xmlns:e1="http://tempuri.org/Source1.xsd" e1:att1="1" e1:att2="2" e1:rest="345"/> If I try to create a...
1
1078
by: David Thielen | last post by:
Hi; I am creating an XmlDocument (.net 2.0) and then saving it. I need the final xml file to look as follows (SpreadsheetML schema - I have no control over it): <Workbook...
0
874
by: heidi | last post by:
Hello, how can I find association between tag prefix and namespace programatically? I have .aspx page with @Register directive and want to check if tag prefix points to desired namespace. ...
3
27035
by: Andy Fish | last post by:
Hi, I am creating a new XmlDocument from scratch, but I can't see how I can make a namespace declaration and associate a prefix with it. For instance in the following example: XmlDocument doc...
18
7704
by: jacksu | last post by:
I have a simple program to run xpath with xerces 1_2_7 XPathFactory factory = XPathFactory.newInstance(); XPath xPath = factory.newXPath(); XPathExpression xp = xPath.compile(strXpr);...
5
2603
by: asciz | last post by:
Hi I'm having a problem with an XML file, most likely because of my lack of understanding of XML schemas I have the following XML file: <?xml version="1.0" encoding="ISO-8859-1"?>...
10
3568
by: Andy Fish | last post by:
hi, I have an XSLT which is producing XML output. many of the nodes in the output tree contain namespace declarations for namespaces that are used in the source document even though they are...
0
7264
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,...
0
7166
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7534
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...
0
5689
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5094
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4749
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...
0
3236
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3226
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1601
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 ...

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.