Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to read an XML input file, manipulate some nodes (remove and rename some) and write the output to a new XML output file?
    primarykey
    data
    text
    <p>I need to read an XML file from internet and re-shape it. Here is the XML file and the code I have so far.</p> <pre><code>library(XML) url='http://ClinicalTrials.gov/show/NCT00001400?displayxml=true' doc = xmlParse(url,useInternalNode=TRUE) </code></pre> <p>I was able to use some functions within the XML package with sucess(e.g., getNodeSet), but I am not an expert and there are some examples on the internet but I was not able to crack this problem myself. I also know some XPath but this was 4 years ago and I am not an expert on sapply and similar functions.</p> <p>But my goal is this:</p> <ol> <li><p>I need to remove a whole set of XML children branches about location, for example: <code>&lt;location&gt; ... anything &lt;/location&gt;</code>. There can be multiple nodes with location data. I simply don't need that detail in the output. The XML file above always complies to an XSD schema. The root node is called <code>&lt;clinical_study&gt;</code>.</p></li> <li><p>The resulted simplified file should be written into a new XML file called "data-changed.xml".</p></li> <li><p>I also need to rename and move one branch from old nested place of </p> <p><code>&lt;eligibility&gt; &lt;criteria&gt; &lt;textblock&gt; Inclusion criteria are xyz &lt;/textblock/&gt;...</code></p></li> <li><p>In new output ("data-changed.xml") the structure should say a different XML node and be directly under root node: </p> <p><code>&lt;eligibility_criteria&gt; Inclusion criteria are xyz &lt;/eligibility_criteria&gt;</code></p></li> </ol> <p>So I need to:</p> <ul> <li>read the XML into memory</li> <li>manipulate the tree (prune it somewhere)</li> <li>move some XML nodes to a new place and under a new name and </li> <li>write the resulting XML output file. </li> </ul> <p>Any ideas are greatly appreciated?</p> <p>Also, if you know about a nice (recent !) tutorial on XML parsing within R (or book chapter which tackles it, please share the reference). (I read the vignettes by Duncan and these are too advanced (too concise)). </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload