My XML document looks like this
When I run XPATH query //collected_objects
, I don't get any nodeset selected. What am I doing wrong? I want to select the whole collected_objects node.
0 votes. Single Slash “/” – Single slash is used to create Xpath with absolute path i.e. the xpath would be created to start selection from the document node/start node.
XPath (XML Path Language) is a query language that can be used to query data from XML documents. In RUEI, XPath queries can be used for content scanning of XML documents. A complete specification of XPath is available at http://www.w3.org/TR/xpath .
xpath=//tag[@attribute='value'] // : Select current node. tag: Tagname of the particular node. Also, "*" is for searching any tag in the xml structure.
Because your XML document has a XML namespace defined (<oval_system_characteristics xmlns="http://oval.mitre.org/XMLSchema/oval-system-characteristics-5"
) - you need to include that in your query!
How you can do this depends on what system/programming language you're using. In .NET / C#, you could do this 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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With