"Yingzi Le" wrote:
>
> Hi Krzysztof,
>
> The root element should have namespace declared. The following code works:
>
> XmlDocument xmlDocument = new XmlDocument();
>
> XmlDocument xmlDoc = new XmlDocument();
> string rootElement = "<foo xmlns:xsl='urn:test'/>";
>
> xmlDoc.Load(new StringReader(rootElement));
>
> XmlElement boo = xmlDoc.CreateElement("boo");
> boo.InnerText = "boo";
> xmlDoc.DocumentElement.AppendChild(boo);
>
> XmlElement coo = xmlDoc.CreateElement("coo");
> XmlElement doo = xmlDoc.CreateElement("xsl","doo","urn:test");
> doo.InnerText = "test";
> coo.AppendChild(doo);
> xmlDoc.DocumentElement.AppendChild(coo);
> xmlDoc.Save(Console.Out);
>
> Thanks,
> -- Yingzi Le
>
> This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at
>
http://www.microsoft.com/info/cpyright.htm >
> Note: For the benefit of the community-at-large, all responses to this message are best directed to the newsgroup/thread from which they originated.
> --------------------
> >Thread-Topic: How to add XmlElement with a namespace
> >thread-index: AcWs2qgEgMfEc9vSSKambaDeZcbAZw==
> >X-WBNR-Posting-Host: 135.196.230.8
> >From: =?Utf-8?B?S3J6eXN6dG9mIEthem1pZXJjemFr?= <KrzysztofKazmierczak@discussions.microsoft.com>
> >Subject: How to add XmlElement with a namespace
> >Date: Mon, 29 Aug 2005 13:45:57 -0700
> >Lines: 46
> >Message-ID: <61B7B155-1A67-4424-839D-C1F3F9BBDF7E@microsoft.com>
> >MIME-Version: 1.0
> >Content-Type: text/plain;
> > charset="Utf-8"
> >Content-Transfer-Encoding: 7bit
> >X-Newsreader: Microsoft CDO for Windows 2000
> >Content-Class: urn:content-classes:message
> >Importance: normal
> >Priority: normal
> >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
> >Newsgroups: microsoft.public.dotnet.xml
> >NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
> >Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGXA03.phx.gbl
> >Xref: TK2MSFTNGXA01.phx.gbl microsoft.public.dotnet.xml:8186
> >X-Tomcat-NG: microsoft.public.dotnet.xml
> >
> >Hi All!
> >
> >I have problem with creating xml document with a namespace:
> >
> >XmlDocument xmlDocument = new XmlDocument();
> >
> >XmlElement rootElement = xmlDocument.CreateElement("foo");
> >xmlDocument.AppendChild(rootElement);
> >
> >XmlElement boo = xmlDocument.CreateElement("boo");
> >boo.InnerText = "boo";
> >rootElement.AppendChild(boo);
> >
> >XmlElement coo = xmlDocument.CreateElement("coo");
> >coo.InnerXml = "<doo>test</doo>";
> >rootElement.AppendChild(coo);
> >
> >I would like to have:
> >coo.InnerXml = "<xsl:doo>test</xsl:doo>";
> >instead of
> >coo.InnerXml = "<doo>test</doo>";
> >
> >but I receive an error message:
> >
> >'xsl' is undeclared namespace
> >
> >I tried to add something like that:
> >
> >XmlAttribute namespaceAttribute = xmlDocument.CreateAttribute("xmlns",
> >"xsl", "
http://www.w3.org/2000/xmlns/");
> >namespaceAttribute.InnerText = "
http://www.w3.org/1999/XSL/Transform"; > >rootElement.Attributes.Append(namespaceAttribute);
> >
> >or
> >
> >XmlAttribute namespaceAttribute = xmlDocument.CreateAttribute("xmlns",
> >"xsl", "
http://www.w3.org/2000/xmlns/");
> >namespaceAttribute.Value = "
http://www.w3.org/1999/XSL/Transform"; > >xmlDocument.DocumentElement.SetAttributeNode(namespaceAttribute);
> >
> >but without effects, stil got error message. Is that possible to create
> >XmlDocument in memory with a namespace?
> >
> >Thank you very much for any help
> >Kind regards
> >Krzysztof Kazmierczak
> >
>
>
>
>