In R, how do I combine two XML documents into one document?

前端 未结 2 846
别那么骄傲
别那么骄傲 2021-01-28 16:36

I\'m querying data from an XML-based API. The API responses are paginated, so I have to make a bunch of queries to get the full data set.

Using read_xml fro

2条回答
  •  一生所求
    2021-01-28 17:09

    Consider the XML package to initialize an empty document with and iteratively append other XML content using addChildren() method from the root of each XML.

    library(XML)
    
    doc = newXMLDoc()
    root = newXMLNode("root", doc = doc)
    
    # LOOP THROUGH 50 REQUESTS
    lapply(seq(50), function(i) {
        # PARSE ALL CONTENT
        tmp <- xmlParse("/path/to/API/call")
    
        # APPEND FROM API XML ROOT
        addChildren(root, getNodeSet(tmp, '/apixmlroot'))
    })
    
    # SAVE TO FILE OR USE doc FOR FURTHER WORK 
    saveXML(doc, file="/path/to/output.xml")
    

    I cannot find a counterpart method in xml2 as its xml_add_child requires a character string not node(s).

提交回复
热议问题