![]() |
![]() | ![]() | ![]() | Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - default namespace xmlns [Thread Next] Re: default namespace xmlnsTo: NULL Date: 8/12/2008 2:50:00 PM
byggemandBob wrote:
> Hi I written some x++ code to export a xml file but I bumped into a small
> problem
> my root node have 3 attributes and I add them like this.
>
> XMLDocOR = new XMLDocument();
>
> interchange = XMLDocOR.createElement("Interchange");
> XMLDocOR.appendChild(Interchange);
> att1 = XMLDocOR.createAttribute("xmlns");
> att1.nodeValue("http://...Omitted...");
If you want to create an element in a certain namespace then you need to
use a namespace aware creation method. I am not sure which DOM
implementation you use with x++, if that is MSXML then you need to use
interchange = XMLDocOR.createNode(1, "Interchange",
"http://example.com/foo")
where http://example.com/foo is the namespace URI.
You need to take that approach for all elements to be created in that
namespace so if you want to create any child elements then you need to
use the same approach e.g.
bar = XMLDocOR.createNode(1, "bar", "http://example.com/foo")
interchange.appendChild(bar)
If you are using the .NET DOM implementation then you don't need to use
createNode, instead then there is a namespace aware overload of
createElement e.g.
interchange = XMLDocOR.createElement("Interchange",
"http://example.com/foo")
bar = XMLDocOR.createElement("bar", "http://example.com/foo")
interchange.appendChild(bar)
There is no need to create xmlns attribute.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
| ![]() | ![]() | ![]() |
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | |||
|
