Why does this XPATH request not work?

My xml document looks like this

When I run the XPATH request //collected_objects, I do not get the selected nodes. What am I doing wrong? I want to highlight all collected node_objects.

+5
source share
1 answer

Since your XML document has an XML ( <oval_system_characteristics xmlns="http://oval.mitre.org/XMLSchema/oval-system-characteristics-5") namespace - you need to include it in your query!

How you can do this depends on which system / programming language you use. In .NET / C # you can do it something like this:

// create XmlDocument and load XML file
XmlDocument doc = new XmlDocument();
doc.Load(yourXmlFileNameHere);

// define XML namespace manager and a prefix for the XML namespace used
XmlNamespaceManager mgr = new XmlNamespaceManager(doc.NameTable);
mgr.AddNamespace("ns", "http://oval.mitre.org/XMLSchema/oval-system-characteristics-5");

// get list of nodes, based on XPath - using the XML namespace manager
XmlNodeList list = doc.SelectNodes("//ns:collected_objects", mgr);
+7
source

All Articles