473,902 Members | 4,610 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CreateElement and xmlns empty attribute

Hi everybody,
in vb.net I have this code:
......
myNode= XmlDoc.CreateEl ement("aNode")

myAttribute = XmlDoc.CreateAt tribute("xlink" , "href",
"http://www.w3.org/1999/xlink")

myAttribute.Val ue ="foo"

myNode.Attribut es.Append(myAtt ribute)

......

Purtroppo quello che ottengo è:
<aNode xlink:href="foo " xmlns="">

How can I avoid the default empty attribute xmlns?

Thank you in advance for any suggest.
Fede


Apr 28 '06 #1
3 12489


Fede wrote:

in vb.net I have this code:
.....
myNode= XmlDoc.CreateEl ement("aNode") <aNode xlink:href="foo " xmlns="">


That happends during serialization if there is an
xmlns="http://example.com/" declaration on an ancestor element. Thus if
you want to be aNode in a particular namespace then you need to use an
overload of CreateElement that allows you to set the namespace e.b.
myNode = XmlDoc.CreateEl ement("aNode", "http://example.com/");
That way the serialization will work as you want it and no xmlns="" will
occur.

<http://msdn.microsoft. com/library/default.asp?url =/library/en-us/cpref/html/frlrfSystemXmlX mlDocumentClass CreateElementTo pic2.asp>

The namespace a node is in is determined when you create the node so
always use namespace aware methods to create an element or attribute if
namespaces matter.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Apr 28 '06 #2
> That happends during serialization if there is an
xmlns="http://example.com/" declaration on an ancestor element. Thus if
you want to be aNode in a particular namespace then you need to use an
overload of CreateElement that allows you to set the namespace e.b.
myNode = XmlDoc.CreateEl ement("aNode", "http://example.com/");
That way the serialization will work as you want it and no xmlns="" will
occur.


the problem is that i don't want xmlns attribute in my xml neither empty
neither with a value, how can i do?

Apr 28 '06 #3


Fede wrote:
the problem is that i don't want xmlns attribute in my xml neither empty
neither with a value, how can i do?


Well then make sure there is no element in the DOM tree that is in a
namespace. If the serializer does e.g.
xmlns=""
when serializing your DOM tree then that means there is an element in
the DOM tree which is in a namespace.
So somewhere up the tree you have an element in a namespace, if you
don't want that then don't create it at all or remove it before serializing.

For instance with the code

XmlDocument xmlDocument = new XmlDocument();
xmlDocument.App endChild(xmlDoc ument.CreateEle ment("root"));

xmlDocument.Doc umentElement.Ap pendChild(xmlDo cument.CreateEl ement("child")) ;
xmlDocument.Sav e(Console.Out);

the result is

<root>
<child />
</root>

so you can see there is no xmlns="" declaration. However if the code is e.g.

XmlDocument xmlDocument = new XmlDocument();
xmlDocument.App endChild(xmlDoc ument.CreateEle ment("root",
"http://example.com/2006/ns1"));

xmlDocument.Doc umentElement.Ap pendChild(xmlDo cument.CreateEl ement("child")) ;
xmlDocument.Sav e(Console.Out);

then the result is

<root xmlns="http://example.com/2006/ns1">
<child xmlns="" />
</root>

You can see that the creation of the element with tag name "child" is
the same in both examples, only the serialization differs as the parent
element is in a namespace in the second example. That means you have to
look at the ancestors of the element where you get xmlns="" and make
sure that the ancestor is in no namespace.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Apr 29 '06 #4

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

Similar topics

4
3157
by: Kevin | last post by:
I have a document, lets say: <Doc> <Ele1 Att1='hello'> <Ele2 Att2='goodbye'/> </Ele1> </Doc> In XSLT I need to generate an attribute value which contains part of this document as a text string, ie:
2
1519
by: Jacques | last post by:
Is it possible to predicate by attribute, and if so, how? <System xmlns="" name="SAP_R3_Financials_DEV200"> <Attributes xmlns=""> <pcd:Attribute name="ApplicationServer" value="secacsap"/> <pcd:Attribute name="ServerPort" value="3200"/> </Attributes> </System> --------------------------------------------- I want to be able to
0
1906
by: chris.stromberger | last post by:
New to SOAP. I am working on something that uses the paypal web services. All the examples have this as the first portion of the soap doc <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
1
1480
by: rlcavebmg | last post by:
I need to generate an XML document that will be validated against a DTD. Up to this point, I have been using XML Serialization with good results, but there is one item I haven't been able to figure out. The generated XML needs to look something like this: <?xml version="1.0" encoding="utf-8" standalone="no"?> <!DOCTYPE MY_XML_Doc SYSTEM "http://dtd_location.com/abc.dtd"> <MY_XML_Doc attr1="val"> <Element1>
1
8423
by: NeilL | last post by:
I'm trying to create an XML document that can be opened in Excel. I have some simple code that ... eventually does the following elem = _doc.CreateElement("Style"); elem.SetAttribute("ss:ID","Default"); elem.SetAttribute("ss:Name","Normal"); parentElem.AppendChild(elem); to add a "Style" item with 2 attributes. My problem is that when I do a Save on the XML document I get an Attribute exception "Cannot use a prefix
2
2570
by: aglaforge | last post by:
I'm attempting to write a quick piece of Javascript code that will validate if the end user of the javascript has the necessary VML attributes set in their HTML. The problem in IE is that "xmlns:v" does not appear in their attributes property or the getAttribute('xmlns:v') calls. The real kicker is that the 'xmlns' attribute does return something. The HTML Snippet would look like this: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0...
1
2835
by: Paul J. Lucas | last post by:
I have code that builds a DOM using the Java org.w3c.dom API and it adds an extra attribute to one of the elements that I don't want. Not only that, the value it adds is wrong. The code to create the DOM is: String emptyXMPString = "<x:xmpmeta xmlns:x='adobe:ns:meta/'>\n" + " <rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'/>\n" + "</x:xmpmeta>\n";
0
987
by: Ik | last post by:
Hi all, I use XslCompiledTranform to transform one XML file into another. In my stylesheet I use the msxsl:node-set() function, so I have a namespace import in my stylesheet. After transforming, the root node of my resulting XML file has an attribute xmlns:msxsl="urn:schemas-microsoft-com:xslt"
4
4687
by: jpdogg | last post by:
Hi all, I'll trying to tell the difference between the following three cases: <img alt="text string" /> <img alt="" /> <img /> I can do this in Firefox with the following code, where elem is the HTMLElement representing each image, but IE doesn't seem to
0
9997
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
11279
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
10981
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
8047
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
7205
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();...
0
5893
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...
1
4725
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
4306
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3323
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.