Question about XmlNamespaceManager

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Greetings:
I have been experimenting with the xi:include element. To do this I need to locate any such elements in my document and perform the includes. Because of the namespace prefix, I need to provide an XmlNamespaceManager to the Select... method. I can instantiate
one, add the namespace, and it works. But I would prefer not to have to manually set up the manager -- there should be an automatic way to have one populated with the namespaces in the document. I have also had success iterating all the attributes on
all the elements and adding any namespaces I discover -- that works too, but it seem that it must be a duplication of effort.
The documentation says that XmlReader uses an XmlNamespaceManager. I use an XmlReader to read my XML documents, so I have tried to access (via Reflection) the one it uses with little success. I _have_ managed to use Reflection to provide an XmlNamespaceManager
to the XmlReader and tell it to use it -- and indeed the XmlNamespaceManager gets populated with the namespaces from the document (yay!).
But when I pass the resultant XmlNamespaceManager to the Select... method it still fails. I can see the namespace in there, but its at scope 2 (and 3?). I have tried to push and pop the scope, but to no avail.
(I havent yet tried to copy the namespaces into another XmlNamespaceManager to flatten it; Ill have to try that later.)
Is there some proper way to have the XmlReader provide an XmlNamespaceManager that can be used directly with the Select... methods? This would avoid a bunch of duplicated effort.

View the full article
 
Back
Top