This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > Microsoft XML > February 2005 > Creating Namespace Node





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Creating Namespace Node
Mike King

2005-02-24, 6:38 pm

How can one create a namespace node using MSXML?


Martin Honnen

2005-02-24, 6:38 pm



Mike King wrote:

> How can one create a namespace node using MSXML?


In what context, DOM, XSLT? What exactly is a namespace node for you, an
attribute node xmlns:prefix="URI"? Or are asking about XPath/XSLT
namespace nodes?



--

Martin Honnen
http://JavaScript.FAQTs.com/
Mike King

2005-02-24, 6:38 pm

"Martin Honnen" <mahotrash@yahoo.de> wrote in message
news:%23UvXbbpGFHA.3088@tk2msftngp13.phx.gbl...
>
>
> Mike King wrote:
>
>
> In what context, DOM, XSLT? What exactly is a namespace node for you, an
> attribute node xmlns:prefix="URI"? Or are asking about XPath/XSLT
> namespace nodes?
>
> --
>
> Martin Honnen
> http://JavaScript.FAQTs.com/


In the context of the DOM (e.g. xmlns:myprefix="http://tempuri.org/").


Martin Honnen

2005-02-24, 6:38 pm



Mike King wrote:

> In the context of the DOM (e.g. xmlns:myprefix="http://tempuri.org/").


You need to use createNode with the proper arguments e.g.

var xmlDocument1 = new ActiveXObject('Msxml2.DOMDocument.4.0');
xmlDocument1.async = false;
var element = xmlDocument1.createNode(1, 'gods:god',
'http://example.com/2005/02/gods');
xmlDocument1.appendChild(element);

and then the "namespace attribute nodes" are automatically added e.g. in
the example above xmlDocument1.xml is serialized as

<gods:god xmlns:gods="http://example.com/2005/02/gods"/>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Mike King

2005-02-24, 6:38 pm

"Martin Honnen" <mahotrash@yahoo.de> wrote in message
news:%23I4WippGFHA.3916@TK2MSFTNGP12.phx.gbl...
>
>
> Mike King wrote:
>
>
> You need to use createNode with the proper arguments e.g.
>
> var xmlDocument1 = new ActiveXObject('Msxml2.DOMDocument.4.0');
> xmlDocument1.async = false;
> var element = xmlDocument1.createNode(1, 'gods:god',
> 'http://example.com/2005/02/gods');
> xmlDocument1.appendChild(element);
>
> and then the "namespace attribute nodes" are automatically added e.g. in
> the example above xmlDocument1.xml is serialized as
>
> <gods:god xmlns:gods="http://example.com/2005/02/gods"/>
>
> --
>
> Martin Honnen
> http://JavaScript.FAQTs.com/


That seems like a work-around. Is there a way without creating an element
or attribute? I have a good reason -- I just haven't gone into the details
about it yet.


Martin Honnen

2005-02-25, 6:36 pm



Mike King wrote:

> "Martin Honnen" <mahotrash@yahoo.de> wrote


[color=darkred]
> That seems like a work-around. Is there a way without creating an element
> or attribute?


The DOM doesn't know about particular nodes called namespace nodes,
during creation of a node it is associated with a namespace or it is
not, that won't change.
You can of course directly create such an attribute xmlns:prefix="URI"
if you regard that as a namespace node e.g.

var xmlDocument1 = new ActiveXObject('Msxml2.DOMDocument.4.0');
xmlDocument1.async = false;
xmlDocument1.loadXML('<gods />');
var namespaceAttribute = xmlDocument1.createNode (
2,
'xmlns:gods',
'http://www.w3.org/2000/xmlns/'
);
namespaceAttribute.nodeValue = 'http://example.com/2005/02/gods';
xmlDocument1.documentElement.setAttributeNode(namespaceAttribute);

but that doesn't help you much, if you later want to create an element
in that namespace you need to use createNode as in the example cited above.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Mike King

2005-02-28, 6:34 pm

> The DOM doesn't know about particular nodes called namespace nodes, during
> creation of a node it is associated with a namespace or it is not, that
> won't change.
> You can of course directly create such an attribute xmlns:prefix="URI" if
> you regard that as a namespace node e.g.
>
> var xmlDocument1 = new ActiveXObject('Msxml2.DOMDocument.4.0');
> xmlDocument1.async = false;
> xmlDocument1.loadXML('<gods />');
> var namespaceAttribute = xmlDocument1.createNode (
> 2,
> 'xmlns:gods',
> 'http://www.w3.org/2000/xmlns/'
> );
> namespaceAttribute.nodeValue = 'http://example.com/2005/02/gods';
> xmlDocument1.documentElement.setAttributeNode(namespaceAttribute);
>
> but that doesn't help you much, if you later want to create an element in
> that namespace you need to use createNode as in the example cited above.
>
> --
>
> Martin Honnen
> http://JavaScript.FAQTs.com/



Thanks that worked.


Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews