[R] XML package help

Duncan Temple Lang duncan at wald.ucdavis.edu
Sat Jan 24 01:48:01 CET 2009



Skewes,Aaron wrote:
> Please consider this:
> 
> <Manifest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
> <!-- eName       : name of the element.
>       eValue       : value of the element. -->
> 
>         <OutputFilePath>./XYZ</OutputFilePath>
>         <FilesList>
>                 <File>
>                         <FileTypeId>10</FileTypeId>
>                         <FilePath>./XYZ/</FilePath>
>                         <PatientCharacteristics eName="one" eValue="1"/>
>                         <PatientCharacteristics eName="two" eValue="2"/>
>                         <PatientCharacteristics eName="three" eValue="3"/>
>                 </File>
> </FilesList>
> </Manifest>
> 
> I am attempting to use XML package and xpathSApply() to extract, say, the eValue attribute for eName=='0ne' for all <File> nodes that have <FileTypeId>==10.  I try the following, amoung several things:
> 


  getNodeSet(doc, 
"//File[FileTypeId/text()='10']/PatientCharacteristics[@eName='one']/@eValue")


should do it.
You need to compare the text() of the FileTypeId node.
And the / after the PatientCharacterstics and before the [] will cause 
trouble.


HTH,

   D.


> doc<-xmlInternalTreeParse(Manifest)
> Root = xmlRoot(doc)
> xpathSApply(Root, "//File[FileTypeId=10]/PatientCharacteristics/[@eName='one']", xmlAttrs)
> 
> and it does not work.
> 
> Might somebody help me with the syntax here?
> 
> Thanks a lot!!
> Aaron
> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list