XPath and namespace specification for XML documents with an explicit default namespace

后端 未结 3 797
深忆病人
深忆病人 2020-12-03 19:25

I\'m struggling to get the correct combination of an XPath expression and the namespace specification as required by package XML (argument namespaces) f

3条回答
  •  执念已碎
    2020-12-03 20:19

    I think @HansHarhoff provides a very good solution.

    For anybody else still searching for a solution, in my experience I think the following works more generally since a single XML document can have multiple namespaces.

    doc <- xmlInternalTreeParse(xml_source)
    
    ns <- getDefaultNamespace(doc)[[1]]$uri
    names(ns)[1] <- "xmlns"
    
    getNodeSet(doc, "//xmlns:Parameter", namespaces = ns)
    

提交回复
热议问题