Jump to content

XPath Parsing (attibutes of self-closed elements)


 Share

This topic is 4369 days old. Please don't post here. Open a new topic instead.

Recommended Posts

  • Newbies

I'm pretty new to XPath, an could use a little help with walking incoming XML strings.

Focusing on the element:

<birthTime value="19530215112005"/>

How do I structure a query to return just the enclosed data for this type of XML element (self-closed, with attributes)? (i.e. 19530215112005). These occur throughout my XML, and I need to know how to pull them out in general.

Thanks,

Drew Tenenholz

Sample XML

<?xml version="1.0" encoding="utf-8"?>

<ClinicalDocument xmlns="urn:hl7-org:v3" xmlns:sdtc="urn:hl7-org:sdtc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:hl7-org:v3 http://xreg2.nist.gov:8080/hitspValidation/schema/cdar2c32/infrastructure/cda/C32_CDA.xsd">

<realmCode code="US" />

<typeId root="2.16.840.1.113883.1.3" extension="POCD_HD000040" />

<templateId root="2.16.840.1.113883.3.27.1776" assigningAuthorityName="CDA/R2" />

<templateId root="2.16.840.1.113883.10.20.1" assigningAuthorityName="CCD" />

<templateId root="2.16.840.1.113883.10.20.3" assigningAuthorityName="HL7/CDT Header" />

<templateId root="2.16.840.1.113883.3.88.11.32.1" assigningAuthorityName="HL7/CDT Header" />

<templateId root="1.3.6.1.4.1.19376.1.5.3.1.1.1" assigningAuthorityName="HL7/CDT Header" />

<id root="2.16.840.1.113883.3.72" extension="CCD_AMBv14_DS01" assigningAuthorityName="NIST Healthcare Project" />

<code code="34133-9" displayName="Summarization of episode note" codeSystem="2.16.840.1.113883.6.1" codeSystemName="LOINC" />

<title>Patient Summary - Ambulatory</title>

<effectiveTime value="20100405130945-0500" />

<confidentialityCode>

<originalText>Test Data Only</originalText>

</confidentialityCode>

<languageCode code="en-US" />

<recordTarget>

<patientRole>

<id extension="9996799589" root="METROCLINIC" assigningAuthorityName="Metropolitan Clinic" />

<addr>

<streetAddressLine>5739 Hazel Street</streetAddressLine>

<city>Williamsport</city>

<state>PA</state>

<postalCode>17701</postalCode>

</addr>

<telecom value="+1-570-898-2189" />

<patient>

<name>

<given>James</given>

<given>D.</given>

<family>Stewart</family>

</name>

<administrativeGenderCode code="M" displayName="Male" codeSystem="2.16.840.1.113883.5.1" codeSystemName="HL7 AdministrativeGender" />

<birthTime value="19530215112005" />

<languageCommunication>

<languageCode code="en-US" />

</languageCommunication>

</patient>

</patientRole>

</recordTarget>

<!-- SOME MORE STUFF -->

</ClinicalDocument>

Link to comment
Share on other sites

Roughly:

<xsl:value-of select="ClinicalDocument/recordTarget/patientRole/patient/birthTime/@value"/>

It's actually a bit more complicated, because your document uses a private namespace.

This, BTW, is a purely XSLT/XPath question - not necessarily related to ScriptMaster.

Link to comment
Share on other sites

  • Newbies

Dear Comment --

Thanks for the reply, that helped me quite a bit. It turns out I just needed a suggestion about XPath syntax, I didn't know you could use a reference like //element/element/@attribute, I thought you had to type //element/element[@attribute] which does work for some XML, but not for these cases.

In part, I'm trying to compare the FMNexus Web Services XPath abilities and those of ScriptMaster. Also, I'm not using XSLT, just the XPathParse function that already comes with ScriptMaster.

So, while

XPathParse( $XML ; "xsl:value-of select=\"ClinicalDocument/recordTarget/patientRole/patient/birthTime/@value\"" )

gives an error:

javax.xml.transform.TransformerException: Extra illegal tokens: 'select', '=', '\', '"ClinicalDocument/recordTarget/patientRole/patient/birthTime/@value\"'

XPathParse( $XML ; "//ClinicalDocument/recordTarget/patientRole/patient/birthTime/@value" )

gets me what I was looking for.

And in FMNexus, the syntax is:

_FmNx_XPATH_query(

Tests::Receive

; "//dfns:patientRole/dfns:patient/dfns:birthTime/@value"

; "True"

; "dfns=urn:hl7-org:v3"

)

where the namespace is specifically referenced. (I see no way to do that with XPathParse but would if it will make selecting elements easier/more efficient.)

Link to comment
Share on other sites

Well, ScriptMaster is just a away to run Java (Groovy, actually) from Filemaker and get the results back. So whatever the selected/imported java package does, that's what you'll get.

IMHO, the path:

ClinicalDocument/recordTarget/patientRole/patient/birthTime/@value

should return an error (or empty) since the namespace is not specified.

I thought you had to type //element/element[@attribute] which does work for some XML

Square brackets contain predicates. The syntax above would select the first child element whose attribute evaluates as true.

BTW, is there a reason why you can't use Filemaker's built-in XML/XSLT import?

Link to comment
Share on other sites

This topic is 4369 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.