Of course I could have an XSL to remove those namespaces from original XML files, but I would like to have some solution that works within R. Is there some way to tell R just to ignore everything in the XML declaration?推荐答案我认为没有简单的方法可以忽略命名空间.最好的方法是学习与他们生活在一起.该答案将使用较新的XML2包.但是,同样适用于XML包解决方案.I think there is no easy way to ignore the namespaces. The best way is to learn to live with them. This answer will use the newer XML2 package. But the same applies to the XML package solution.使用library(XML2)fname='myfile.xml'doc <- read_xml(fname)#peak at the namespacesxml_ns(doc)第一个名称空间已分配给d1.如果您的XPath找不到所需的内容,则最可能的原因是名称空间问题.The first namespace is assigned to d1. If you XPath does not find what you want, the most likely cause is the namespace issue.xpath <- "//d1:FormDef"ns <- xml_find_all(doc,xpath, xml_ns(doc))ns此外,您必须对路径中的每个元素都执行此操作因此,保存输入即可,Also, you have to do this for every element in the pathSo to save typing, you can dolibrary(stringr)> xpath <- "/ODM/Study"> (xpath<-str_replace_all(xpath,'/','/d1:'))[1] "/d1:ODM/d1:Study" 这篇关于在R中解析XML:不正确的名称空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!