473,399 Members | 3,919 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,399 software developers and data experts.

assign dt as namespace for xmlelement

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: Matt Torline

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>X8iAJQuYZEulcatGDsqe+w==</Id>
Nov 12 '05 #1
2 2265


Matt Torline via .NET 247 wrote:
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"


You need to create an attribute node in the namespace
http://www.w3.org/2000/xmlns/, as in the following example:

using System;
using System.Xml;

public class Test20040504 {
public static void Main (string[] args) {
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(@"test20040504.xml");
XmlAttribute attribute = xmlDocument.CreateAttribute("xmlns", "dt",
"http://www.w3.org/2000/xmlns/");
attribute.Value = "urn:schemas-microsoft-com:datatypes";
xmlDocument.DocumentElement.SetAttributeNode(attri bute);
Console.WriteLine(xmlDocument.OuterXml);
}
}
--

Martin Honnen
http://JavaScript.FAQTs.com/

Nov 12 '05 #2
Martin Honnen wrote:
You need to create an attribute node in the namespace
http://www.w3.org/2000/xmlns/, as in the following example:


Yeah, but don't expect this namespace declaration to be in effect on the
DOM in memory. The DOM needs to be reparsed again to make namespaces
changed.
--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #3

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

Similar topics

4
by: Krishna Tulasi via .NET 247 | last post by:
Hi, I am having trouble with creation of XML programmatically using .NET. Specifically Im trying to create an element which looks like below and insert into an existing xml doc: <Worksheet...
1
by: Bill Geake | last post by:
I am successfully serializing to XML from a class like this: private static void CreateXML() { testClass c = new testClass(); c.stringElement = "data1"; c.stringElement2 = "data2"; ...
0
by: Alberto Grosso Nicolin | last post by:
We have the following XML schema: there's a root element (Response) with of a single child element (Result). ...
4
by: David Grogan | last post by:
Hi, 2 questions.... 1. I'm parsing an XHTML document that contains both the default namespace (xmlns="http://www.w3.org/1999/xhtml") and a custom one (xmlns:r="...") - both of these being...
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 =...
3
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...
7
by: Michael Peters | last post by:
I wish to change/set the namespace for a header in my web service. I have found the following code and it does not appear to work and my assumption is because I am using RPC encoding... ...
2
by: scottpet | last post by:
Hi, I want to add a namespace prefix to the root node of an object I am serializing to XML. I have been reading though this article:...
3
by: Markus Bauer | last post by:
Hello, I have a problem with the namespace prefix. I need to add nodes to a xml file that is not created by me. It has a namespace with the prefix "NFD". So an already existing node looks...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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
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
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
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,...
0
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...

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.