Skip to content

XML package- accessing nodes based on attributes

2 messages · Skewes,Aaron, Duncan Temple Lang

#
XPath is your friend here.


getNodeSet(mf,
           '//Characteristic[@Type="File" and @eName="FileTypeId"
                and @eValue="10"]/parent::File
            /Characteristic[@Type="Patient"
                         and @eName="PatientReference"]/@eValue')

I have broken the XPath expression across lines to try to format it
more legibly.

The basic idea is to first find only the File nodes which have the
required Characteristic with the specific values for the
File, FileTypeId and eValue attributes.
Then go back up to the parent <File> element and
then extract the other Characteristic that you want.

You can then call unlist if you want a character vector.

  D.
Skewes,Aaron wrote: