Accessing xmlns attributes via SAX in MSXML
Accessing xmlns attributes via SAX in MSXML
Hi,
I'm having a little trouble using the MSXML implementation of SAX,
specifically with reading xmlns attributes using ISAXAttributes::getName. The
calling application is written in C++ with Visual Studio 2008.
MORE BACKGROUND: We're using the SAX interface to import data from an XML
document (file) to our application's own internal memory structure. Since the
document may be large, we chose SAX rather than the DOM to avoid having too
much duplication of data in memory at once. In the XML, elements defined in a
namespace separate from our own may have been inserted by a third party. The
third-party elements and their namespace declarations must be preserved in
memory, then written back out to the file as-is with the other data native to
the application. As such, we need to have the namespace declarations as
defined in element attributes loaded and preserved so that they can be
written back to the file intact.
To load the element attributes that define namespaces (e.g.
xmlns:myns="my_namespace_url.com") and other attributes, we're using the
ISAXAttributes interface pointer passed to ISAXContentHandler::startElement.
Also, the "namespaces" feature is set to true, and the "namespace-prefixes"
feature is set to true.
PROBLEM: When we call ISAXAttributes::getName, specifying the index of a
namespace declaration attribute, the local name for the attribute returned is
empty. Is this to be expected? This seems inconsistent and leads me to wonder
if I'm using the API correctly.
EXAMPLE: Given the following XML start element tag: <myns:MyElement
xmlns:myns="my_namespace_url.com" myns:title="My Title">, calling
ISAXAttributes::getName with index zero returns the following:
Local name: ""
Qualified name: "xmlns:myns"
Uri: "http://www.w3.org/2000/xmlns/"
(getValue retrieves the value: "my_namespace_url.com")
In contrast, when I pass index one, getName returns the following:
Local name: "title"
Qualified name: "xmlns:title"
Uri: "mynamespace_url.com"
(getValue retrieves the value: "My Title")
So the local name returned for index one is what I would expect, but the
local name returned for index zero is not.
Thanks in advance for any help.
Jim
date: Mon, 14 Jul 2008 13:07:00 -0700
author: Jim F.