views:

96

answers:

1

Specifically (taking a deep breath): How would you go about finding all the XML name spaces within a C#/.NET XmlDocument for which there are no applicable schemas in the instance's XmlSchemaSet (Schemas property)?

My XPath magic is lacking the sophistication to do something like this, but I will keep looking in the meantime ...

+1  A: 

You need to get a list of all the distinct namespaces in the document, and then compare that with the distinct namespaces in the schema set.

But namespace declaration names are typically not exposed in the XPath document model. But given a node you can get its namespace:

// Match every element and attribute in the document
var allNodes = xmlDoc.SelectNodes("//(*|@*)");
var found = new Dictionary<String, bool>(); // Want a Set<string> really
foreach (XmlNode n in allNodes) {
  found[n.NamespaceURI] = true;
}
var allNamespaces = found.Keys.OrderBy(s => s);
Richard