我的XML文档看起来像这样
当我运行XPATH查询时//collected_objects,我没有选择任何节点集.我究竟做错了什么?我想选择整个gather_objects节点.
因为您的XML文档定义了一个XML命名空间(<oval_system_characteristics xmlns="http://oval.mitre.org/XMLSchema/oval-system-characteristics-5") - 您需要在查询中包含它!
如何执行此操作取决于您使用的系统/编程语言.在.NET/C#中,你可以这样做:
// 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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3067 次 |
| 最近记录: |