472,782 Members | 1,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,782 software developers and data experts.

Removing xmlns="" from XmlTextWriter output

I am creating an XmlDocument in code and then using XmlTextWriter via
doc.WriteTo(xwriter) to output the result to a text box. I have a root
element that defines a default namespace. However, the sub-elements are
created without any namespaces like so:

XmlElement elem = doc.CreateElement("Foo");
root.AppendChild(elem);

but in the output I get this:

<?xml version="1.0" encoding="utf-8"?>
<Root xmlns="http://tempuri.org">
<Foo xmlns="" />
</Root>

How can I get rid of the ' xmlns="" ' attribute on the Foo element?

--
Keith
Nov 12 '05 #1
3 7061
* Keith Hill wrote in microsoft.public.dotnet.xml:
I am creating an XmlDocument in code and then using XmlTextWriter via
doc.WriteTo(xwriter) to output the result to a text box. I have a root
element that defines a default namespace. However, the sub-elements are
created without any namespaces like so:

XmlElement elem = doc.CreateElement("Foo");
root.AppendChild(elem);

but in the output I get this:

<?xml version="1.0" encoding="utf-8"?>
<Root xmlns="http://tempuri.org">
<Foo xmlns="" />
</Root>


If you call CreateElement without any namespace it creates an element
without any namespace. In XML, this is expressed via xmlns="". If you
want to have the Foo element in the same namespace as the Root element
you need to specify the namespace for CreateElement. Remember that

<Root xmlns="http://tempuri.org">
<Foo xmlns="http://tempuri.org" />
</Root>

is equivalent to

<Root xmlns="http://tempuri.org">
<Foo />
</Root>

For more information on XML namespaces try the various MSDN articles
and e.g.

* http://www.rpbourret.com/xml/NamespacesFAQ.htm
* http://www.jclark.com/xml/xmlns.htm
--
Björn Höhrmann · mailto:bj****@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
Nov 12 '05 #2
That works and thanks for the pointer to FAQ. That's good reading.

--
Keith

"Bjoern Hoehrmann" <bj****@hoehrmann.de> wrote in message
news:41****************@news.bjoern.hoehrmann.de.. .
If you call CreateElement without any namespace it creates an element
without any namespace. In XML, this is expressed via xmlns="". If you
want to have the Foo element in the same namespace as the Root element
you need to specify the namespace for CreateElement. Remember that

<Root xmlns="http://tempuri.org">
<Foo xmlns="http://tempuri.org" />
</Root>

is equivalent to

<Root xmlns="http://tempuri.org">
<Foo />
</Root>

For more information on XML namespaces try the various MSDN articles
and e.g.

* http://www.rpbourret.com/xml/NamespacesFAQ.htm
* http://www.jclark.com/xml/xmlns.htm

Nov 12 '05 #3

So that it is clear, in order to use a default namespace under the .Net
FX DOM, you have to specify the default? That is odd for a couple
reasons. First, a default can be defined as a value to use in the
absence of a provided value. This behavior of the DOM implementation
is changing that definition to if a particular value is supplied, we
will represent it as the default, yuck!. Second, in parent-child
entity relationships, it is the normal pattern for the child to take on
the attributes of it's parent unless specified as different (just like a
default, only oriented in objects hierarchies). Again, this behavior
changes that relationship, again, yuck!

--
okie_greg
------------------------------------------------------------------------
Posted via http://www.mcse.ms
------------------------------------------------------------------------
View this thread: http://www.mcse.ms/message1334934.html

Nov 12 '05 #4

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

Similar topics

3
by: Mike Dickens | last post by:
hi, i'm sure this has come up before but havn't managed to find an answer. if i have the following xslt <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet method="xml" version="1.0"...
5
by: NeilL | last post by:
In the XML document I'm trying to create I do the following elem = _doc.CreateElement("Author"); elem.InnerText = "something"; parentElem.AppendChild(elem); Thiw works properly however the...
3
by: Jim Hsu | last post by:
when I use the XmlWebSerivce to response the xmlelement to Web Service client. the ASP.net plumbing work ( the XmlSerializer in WebServices ) will serialize the XML if we can control the wrapper...
3
by: ano | last post by:
Hi, Anyone knows how to get "xmlns" value from XML file? For example, how to check that this xml file has a xmlns or not? Or how to read the xmlns value? <bookstore...
0
by: R. Ian Lee | last post by:
I've built an XSLT file that transforms data to SpreadsheetML format. The XSLT uses a <xsl:call-template/to build each worksheet. For some reason, when I transform the file, it is inserting...
0
by: SolaFide | last post by:
I have an XML doc that looks something like this: <?xml version="1.0" encoding="utf-8"?> <elem1> <elem2 xmlns="http://someurl.com"> <elem3> <item>some stuff here</item> ...
3
by: Lee | last post by:
Hello guys, I am new to XML and working on a XSLT to transforn yahoo shopping search result to html. my problem is the return XML contain xmlns in root element, here is the sample xml: <?xml...
4
by: BorisBoshond | last post by:
Hi all, Hope someone is able and willing to help me with following problem. I received a xsd file from another company, our company i supposed to return xml based on that xsd. Problem is that I...
4
markmcgookin
by: markmcgookin | last post by:
Hi, I am creating an MXL doc using XSLT but for some reason it is churning out elements like this <DateTimeLastSaved xmlns="" /> <UserName xmlns="" /> when I delete xmlns="" it works fine,...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.