473,581 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MSXML 4.0 loadXML and namespaces - what's wrong with this picture

I was having a bear of a time today trying to figure out some inconsistent
behavior selecting nodes from and MSXML DOM document, so I distilled the issue
down to a trivial test demonstrating the confusing behavior.

The deal is that I want to create most of my XML nodes from code using
createNode, but the code is much more clear if I can start by building the
basic skeleton of the document using a simple XML string. The catch is, I'll
need to use namespaces.

== First - my test code output ==

name=root namespaceURI=ur i:foo
name=child1 namespaceURI=ur i:foo
name=value namespaceURI=
== Now - the code that makes that output ==

Public Sub TestDomFromStri ng()
Dim objDoc As New MSXML2.DOMDocum ent40

objDoc.setPrope rty "SelectionNames paces", _
"xmlns:foo='uri :foo'"

objDoc.setPrope rty "SelectionLangu age", "XPath"

objDoc.loadXML _
"<root xmlns='uri:foo' >" & _
"<child1 value='123'/>" & _
"</root>"

PrintNodeProfil e objDoc.selectSi ngleNode("/*")
PrintNodeProfil e objDoc.selectSi ngleNode("/*/*[1]")
PrintNodeProfil e objDoc.selectSi ngleNode("/*/*[1]/@*")

End Sub

Public Sub PrintNodeProfil e(Node As MSXML2.IXMLDOMN ode)
Debug.Print "name=" & Node.nodeName & " " & _
"namespaceU RI=" & Node.namespaceU RI
End Sub

== End of code ==

It looks like MSXML automatically trats child elements as being in the parent
namespace as expected, but the unqualified attribute of an element in a
namespace has no namespace! needless to say, that was leading to some
confusion earlier today while debugging my selectNode results.

Now - the question is, is this an MSXML bug or quirk, or is there something I
just don't get yet about how a DOM loadXML call is supposed to behave? If
this is a problem with MSXML, how do I work around it. If I'm doing it wrong,
how should I do it right?

I have another issue that builds off that one. I notice that when I do a
selectNodes or SelectSingleNod e, if I'm trying to select an attribute that
does have a namespace, I have to prefix the attribute name, but I don't have
to do that in XSLT nor when building key and keyref expressions in W3C XML
Schemas. Why is the MSXML selectNodes behavior different than these cases.

Thanks,

- Steve J.
Aug 18 '05 #1
5 4382
Steve Jorgensen wrote:
I was having a bear of a time today trying to figure out some inconsistent
behavior selecting nodes from and MSXML DOM document, so I distilled the issue
down to a trivial test demonstrating the confusing behavior.

The deal is that I want to create most of my XML nodes from code using
createNode, but the code is much more clear if I can start by building the
basic skeleton of the document using a simple XML string. The catch is, I'll
need to use namespaces.

== First - my test code output ==

name=root namespaceURI=ur i:foo
name=child1 namespaceURI=ur i:foo
name=value namespaceURI=
== Now - the code that makes that output ==

Public Sub TestDomFromStri ng()
Dim objDoc As New MSXML2.DOMDocum ent40

objDoc.setPrope rty "SelectionNames paces", _
"xmlns:foo='uri :foo'"

objDoc.setPrope rty "SelectionLangu age", "XPath"

objDoc.loadXML _
"<root xmlns='uri:foo' >" & _
"<child1 value='123'/>" & _
"</root>"

PrintNodeProfil e objDoc.selectSi ngleNode("/*")
PrintNodeProfil e objDoc.selectSi ngleNode("/*/*[1]")
PrintNodeProfil e objDoc.selectSi ngleNode("/*/*[1]/@*")

End Sub

Public Sub PrintNodeProfil e(Node As MSXML2.IXMLDOMN ode)
Debug.Print "name=" & Node.nodeName & " " & _
"namespaceU RI=" & Node.namespaceU RI
End Sub

== End of code ==

It looks like MSXML automatically trats child elements as being in the parent
namespace as expected, but the unqualified attribute of an element in a
namespace has no namespace! needless to say, that was leading to some
confusion earlier today while debugging my selectNode results.
the default namespace doesn't apply on attributes
unprefixed attributes are not is a namespace ; it is useless because
they are told to "belong" to their host element ; those that do have a
namespace are not belonging to it, they are "foreign attributes" and
must be prefixed

Now - the question is, is this an MSXML bug or quirk, or is there something I
just don't get yet about how a DOM loadXML call is supposed to behave? If
this is a problem with MSXML, how do I work around it. If I'm doing it wrong,
how should I do it right?

I have another issue that builds off that one. I notice that when I do a
selectNodes or SelectSingleNod e, if I'm trying to select an attribute that
does have a namespace, I have to prefix the attribute name, but I don't have
to do that in XSLT
the behaviour is the same ; the XML data model is the same whatever the
tool you use, an XSLT stylesheet or an XPath engine

nor when building key and keyref expressions in W3C XML Schemas. Why is the MSXML selectNodes behavior different than these cases.

Thanks,

- Steve J.

--
Cordialement,

///
(. .)
-----ooO--(_)--Ooo-----
| Philippe Poulard |
-----------------------
Aug 18 '05 #2


Steve Jorgensen wrote:

It looks like MSXML automatically trats child elements as being in the parent
namespace as expected, but the unqualified attribute of an element in a
namespace has no namespace! needless to say, that was leading to some
confusion earlier today while debugging my selectNode results.


But that is nothing specific to MSXML, an attribute is in no namespace
unless it has a qualified name which the value attribute does not have,
it is in no namespace.
Exception is an xmlns="http://example.com/ns1" attribute but you would
not see that in XPath as an attribute but as a namespace node. In the
DOM however such an attribute is by definition in the namespace
http://www.w3.org/2000/xmlns/. Looks however as if MSXML 4 does not
implement that.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 18 '05 #3
On Thu, 18 Aug 2005 13:38:37 +0200, Martin Honnen <ma*******@yaho o.de> wrote:


Steve Jorgensen wrote:

It looks like MSXML automatically trats child elements as being in the parent
namespace as expected, but the unqualified attribute of an element in a
namespace has no namespace! needless to say, that was leading to some
confusion earlier today while debugging my selectNode results.


But that is nothing specific to MSXML, an attribute is in no namespace
unless it has a qualified name which the value attribute does not have,
it is in no namespace.
Exception is an xmlns="http://example.com/ns1" attribute but you would
not see that in XPath as an attribute but as a namespace node. In the
DOM however such an attribute is by definition in the namespace
http://www.w3.org/2000/xmlns/. Looks however as if MSXML 4 does not
implement that.


OK, what you're saying clears up a lot of things. I think I may be having a
different problem with MSXML and XML Schema validation, then, or I never would
have thought I had a problem with attributes being unqualified in the first
place. In any case, I'll proceed with diagnosis today with a much more useful
understanding.

Thanks very much to you and to Philippe for your explanations.
Aug 18 '05 #4
On Thu, 18 Aug 2005 07:05:19 -0700, Steve Jorgensen <no****@nospam. nospam>
wrote:

....
OK, what you're saying clears up a lot of things. I think I may be having a
different problem with MSXML and XML Schema validation, then, or I never would
have thought I had a problem with attributes being unqualified in the first
place. In any case, I'll proceed with diagnosis today with a much more useful
understandin g.


OK, this turned out to be all just a series of my misconceptions. I had
declared one of the attributes in my schema globally, and I didn't realize
that forced it to be qualified. That was compounded by my lack of
understanding that when attributes are "unqualifie d", that really means they
have no namespace, and doesn't just mean that they don't need a prefix to be
in the parent element's namespace.
Aug 19 '05 #5
Philippe Poulard wrote:

Hi, forgive med for breaking in here, I think the OP's had his questions
answered anyway ;)
the default namespace doesn't apply on attributes
unprefixed attributes are not is a namespace ; it is useless because
they are told to "belong" to their host element ; those that do have a
namespace are not belonging to it, they are "foreign attributes" and
must be prefixed


That's the most normal way to use namespace-qualified attributes, yes...

From Namespaces in XML (http://www.w3.org/TR/REC-xml-names/)

5.2 Namespace Defaulting

A default namespace is considered to apply to the element where it is
declared (if that element has no namespace prefix), and to all elements
with no prefix within the content of that element. If the URI reference
in a default namespace declaration is empty, then unprefixed elements in
the scope of the declaration are not considered to be in any namespace.
Note that default namespaces do not apply directly to attributes.

On the other hand:

[Definition:] The attribute's value, a URI reference, is the namespace
name identifying the namespace. The namespace name, to serve its
intended purpose, should have the characteristics of uniqueness and
persistence. It is not a goal that it be directly usable for retrieval
of a schema (if any exists). An example of a syntax that is designed
with these goals in mind is that for Uniform Resource Names [RFC2141].
However, it should be noted that ordinary URLs can be managed in such a
way as to achieve these same goals.

I have a situation where I need to insert an element in no-namespace
land into a document where the default namespace is declared. Is it
permitted to do:

<foo xmlns="gedefims ">
<blah/>
<blah/>
<blah/>
<namespaceles s-intruder xmlns=""/>
</foo>

- It should be permitted because 5.2 in NS in XML says it is
but
- The empty string ain't no URI

Does anyone know if I can always expect it to work? At least one XML
validator complains about the empty URI. I know I can always get around
it the hard way -- using a prefix-declared namespace for foo and blahs
instead. But there's too much trouble with it .. for one thing, I also
have attribute VALUES being interpreted depending on the bindings of the
NSs.

Soren
Aug 20 '05 #6

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

Similar topics

4
2380
by: isee | last post by:
I want to send xml to some site and get response (also XML). I am using vb.net,but I don't want to install MSXML 4.0 .
2
1844
by: Andy Norman | last post by:
I have a strange problem. When I try to call the input property of the MSXML processor object from VBScript in an ASPX page I get the error "Member not found". The same code (with a few "set" statements added) works find in ASP. What on earth is going on ? I can't find anything in the knowledge base on it.
3
4861
by: awong | last post by:
Hi there, I was trying to convert the following VB6 code to VB.NET. But I can't find a corresponding System.XML object for MSXML IXMLDOMSelection. I am thinking to use System.XML XMLNodeList object and GetElementsByTagName method to find the "selection". Any suggestion/comment? Thanks in advance.
4
3485
by: Tim Haughton | last post by:
I think I might be misunderstanding just what the LoadXml method is doing. I have 2 seemingly identical XmlDocuments, an XPath query succeeds on one of them, and fails on the other. Can anyone tell me what I'm doing wrong, and how to do it right? public void RetrieveDirectoryNumbersWithCirsAndDirs() { BillViewServiceRef.AccountRef acref...
0
1544
by: upendra.desai | last post by:
Hi, I have written an application in Microsoft Visual C++ (Visual Studio 6.0) that uses MSXML 4.0 SP2. When I try to load an XML from a file, it throws an E_ACCESSDENIED (HRESULT = 0x80070005) exceptioon. I am not sure why this is happenning. The sample code is: IXMLDOMDocument2Ptr spXMLDocument;...
0
1777
by: upendra.desai | last post by:
Hi, I have written an application in Microsoft Visual C++ (Visual Studio 6.0) that uses MSXML 4.0 SP2. When I try to load an XML from a file, it throws an E_ACCESSDENIED (HRESULT = 0x80070005) exceptioon. I am not sure why this is happenning. The sample code is: IXMLDOMDocument2Ptr spXMLDocument;...
19
2593
by: Matthias Truxa | last post by:
Hello, can anyone confirm the existence of the following effects which I'd consider being a critical bug in msxml according to w3c's xpath specs? The Spec says: "The parent, ancestor, ancestor-or-self, preceding, and preceding-sibling axes are reverse axes" http://www.w3.org/TR/2005/CR-xpath20-20051103/#doc-xpath-ReverseAxis
6
7985
by: Anthony Jones | last post by:
People, Anyone else got an IIS7 server out there that they can test this little ASP file:- <% Set xml = Server.CreateObject("MSXML2.DOMDocument.3.0") xml.loadXML "<root />" Set xsl = Server.CreateObject("MSXML2.DOMDocument.3.0")
0
7862
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...
0
8301
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7894
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...
0
6551
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3803
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...
0
3820
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2300
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
1
1400
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1132
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...

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.