I am trying to get list of all defined namespaces by XmlNamespaceManager in this code:
var manager = new XmlNamespaceManager(xmlDoc.NameTable);
var dic = manager.GetNamespacesInScope(XmlNamespaceScope.All);
and this is my xml:
<?xml version='1.0' encoding='UTF-8'?>
<psf:PrintCapabilities
version='1'
xmlns:psf='http://schemas.microsoft.com/windows/2003/08/printing/printschemaframework'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:ns0000='http://schemas.microsoft.com/windows/printing/oemdriverpt/Lexmark T650/6.1.7601.17514/'
xmlns:psk='http://schemas.microsoft.com/windows/2003/08/printing/printschemakeywords'>
</psf:PrintCapabilities>
Interestingly GetNamespacesInScope() method returns only one item (key=”xml”, value=”http://www.w3.org/XML/1998/namespace”)
What is missing here?
Note: even if I use one of the defined namespace prefixes (for example by adding <ns0000:a>hi</ns0000:a>) it does not change anything.
Try using XPathDocument as well as XmlNamespaceScope… Something like this will work