473,811 Members | 3,055 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:s chemas-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:sche mas-microsoft-com:datatypes"
--------------------------------
From: Matt Torline

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

<Id>X8iAJQuYZEu lcatGDsqe+w==</Id>
Nov 12 '05 #1
2 2286


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:s chemas-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:sche mas-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.Loa d(@"test2004050 4.xml");
XmlAttribute attribute = xmlDocument.Cre ateAttribute("x mlns", "dt",
"http://www.w3.org/2000/xmlns/");
attribute.Value = "urn:schema s-microsoft-com:datatypes";
xmlDocument.Doc umentElement.Se tAttributeNode( attribute);
Console.WriteLi ne(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
20506
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 ss:Name="TKCSheet1"> </Worksheet> The existing xml doc is: <?xml version="1.0"?> <?mso-application progid="Excel.Sheet"?>
1
5924
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"; subClassDataType s = new subClassDataType(); s.subThingElement1 = "data3";
0
1708
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). ---------------------------------------------------------------------------------------------- <?xml version="1.0" encoding="utf-8"?> <xs:schema id="TaskRequest" targetNamespace="http://xyz.com/TaskResponse/1.0" elementFormDefault="qualified" xmlns="http://xyz.com/TaskResponse/1.0"
4
4183
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 attributes of <html>. When I then insert new XmlNodes into the DOM the HTML tags all end up getting an unnecesarry 'xmlns' attribute added, elements with the 'r' prefix don't, which is correct. Is there any way to stop the XmlNode/XmlWriter from...
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:
3
27063
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 = new XmlDocument(); XmlElement el = doc.CreateElement("foo:data"); doc.AppendChild(el); doc.Save("foo.xml");
7
7054
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... public class Service1 : System.Web.Services.WebService { // ...
2
21648
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: http://msdn2.microsoft.com/en-gb/library/system.xml.serialization.xmlnamespacedeclarationsattribute.aspx I get namespace prefixes in the document, but not on the root node. Specifically, the serializer does not work as described in the last
3
8451
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 like that: <NFD:Sonstiger_Hinweis> <NFD:Erfassungsdatum>20070102</NFD:Erfassungsdatum>
0
9731
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
9605
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10651
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...
1
10405
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,...
1
7671
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5556
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5697
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3871
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3020
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.