Thursday, 26 June 2008

c# with XmlDocument and xpaths

Im almost embarrassed to admit it but I have spend almost a day playing around with the XmlDocument .NET class and xpaths. My problem was that I have the XML shown below(only a snipped of it is pasted below)

And wanted to get hold of the "id" tag inside patient. To do this I found that the fast way was to use the method SelectSingleNode to and a xpath expression like the following:

"/ClinicalDocument/recordTarget/patientRole/id".

In the following way:

XmlDocument xml = new XmlDocument();
xml.LoadXml(cda.Xmlcda);
XmlNode node = xml.SelectSingleNode("/ClinicalDocument/recordTarget/patientRole/id");

But no element was found. I tried quite a lot of different stuff. But nothing worked.

Until finally I found this article: (link) (which I only skimmed(to be completely honest))which described the funny thing that even if the elements is not prefixed in the XML the base namespace is used anyway. So to enable me to Xpath my way to the patient Id tag I needed a XmlNameSpaceManager to handle the namespaces.


The working code looks like this:
XmlDocument xml = new XmlDocument();
xml.LoadXml(cda.Xmlcda);
XmlNamespaceManager nsmgr = new XmlNamespaceManager(xml.NameTable);
nsmgr.AddNamespace("cda", "urn:hl7-org:v3");
XmlNode node = xml.SelectSingleNode("/ClinicalDocument/recordTarget/patientRole/id", nsmgr);



The XML:

<!-- ?xml-stylesheet type="text/xsl" href="CDA.xsl"? -->
<!-- Readers should be aware of the evolving "Using SNOMED CT in HL7 Version 3" implementation guide, currently in a draft state. The guide, co-developed by HL7 and the College of American Pathologists, will be balloted by HL7 as an Informative Document. Recommendations in the final published guide should usurp patterns of SNOMED CT usage found in this sample instance. -->
<clinicaldocument xmlns="urn:hl7-org:v3" voc="urn:hl7-org:v3/voc"
xsi="http://www.w3.org/2001/XMLSchema-instance"
schemalocation="urn:hl7-org:v3 CDA.xsd">
<!-- ******************************************************** CDA Header ******************************************************** -->
<typeid root="2.16.840.1.113883.1.3" extension="POCD_HD000040">
<templateid root="2.16.840.1.113883.3.27.1776">
<id extension="c266" root="2.16.840.1.113883.19.4">
<code code="11488-4" codesystem="2.16.840.1.113883.6.1" codesystemname="LOINC" displayname="Consultation note">
<title>Good Health Clinic Consultation Note</title>
<effectivetime value="20000407">
<confidentialitycode code="N" codesystem="2.16.840.1.113883.5.25">
<languagecode code="en-US">
<setid extension="BB35" root="2.16.840.1.113883.19.7">
<versionnumber value="2">
<recordtarget>
<patientrole>
<id extension="12345" root="2.16.840.1.113883.19.5">
<patient>
<name>
</name></patient></id></patientrole></recordtarget></versionnumber></setid></languagecode></confidentialitycode></effectivetime></code>

60 comments:

Anonymous said...

xanax online effects of alprazolam 0.5mg - order xanax with mastercard

Anonymous said...

buy tramadol online tramadol dosage renal failure - buy tramadol online usa cheap

Anonymous said...

xanax online xanax 1mg dose - xanax 2mg erowid

Anonymous said...

buy tramadol online tramadol dosage recommendations - order tramadol online no prescription

Anonymous said...

generic xanax xanax bars coke - xanax bars for sale

Anonymous said...

buy tramadol online buy tramadol rx online - tramadol 25mg tablets

Anonymous said...

buy tramadol online tramadol hcl 50 mg addiction - tramadol vs norco

Anonymous said...

generic xanax where to buy xanax online no prescription - xanax zoloft interaction

Anonymous said...

xanax online xanax bars mg - xanax withdrawal long do symptoms last

Anonymous said...

tramadol 50 mg can you buy tramadol in the usa - tramadol high duration

Anonymous said...

buy carisoprodol carisoprodol online cod - carisoprodol online no prescription

Anonymous said...

xanax without prescription drug get off xanax - generic equivalent for xanax

Anonymous said...

xanax sale xanax pills with alcohol - drug interactions tramadol xanax

Anonymous said...

online xanax xanax side effects depression - xanax effects long term

Anonymous said...

buy tramadol online tramadol 50 mg street price - tramadol hcl 50mg buy

Anonymous said...

xanax buy online no prescription xanax and alcohol wiki - xanax show up 5 panel drug test

Anonymous said...

generic xanax xanax overdose renal failure - can buy xanax vietnam

Anonymous said...

soma carisoprodol buy carisoprodol online us - listaflex carisoprodol 350 mg para sirve

Anonymous said...

order tramadol overnight tramadol hcl 25 mg - tramadol for dogs sleepy

Anonymous said...

buy tramadol no prescription tramadol premature ejaculation - overdose of tramadol side effects

Anonymous said...

cialis 20mg where to buy cialis online no prescription - cialis price with prescription

Anonymous said...

cheap tramadol online tramadol 50mg capsules dosage - tramadol 50mg how many

Anonymous said...

xanax online buy xanax 2mg bars - what does xanax pills do to you

Anonymous said...

buy tramadol online what is tramadol dosage - tramadol with acetaminophen high

Anonymous said...

xanax online xanax .5 side effects - xanax bars to buy

Anonymous said...

buy cialis online cialis samples - cialis que es

Anonymous said...

cheap cialis 20mg cialis daily trial - cialis online miglior prezzo

Anonymous said...

cialis tadalafil safe order cialis online - generic cialis names

Anonymous said...

can you buy cialis over the counter cheap cialis in usa - cialis last longer

Anonymous said...

order tadalafil cialis online legale - cialis 0 2

Anonymous said...

buy tramadol online tramadol 627 recommended dosage - tramadol addiction message board

Anonymous said...

http://landvoicelearning.com/#44827 tramadol hcl lethal dose - tramadol 50 mg with ibuprofen

Anonymous said...

http://landvoicelearning.com/#30896 what dosage tramadol for dogs - tramadol 50mg how many to take

Anonymous said...

http://landvoicelearning.com/#62431 tramadol dosage 627 - get cheap tramadol

Anonymous said...

buy tramadol tramadol hcl 50 mg dogs side effects - buy tramadol american express

Anonymous said...

buy tramadol cash on delivery tramadol withdrawal day 5 - tramadol generic ultracet

Anonymous said...

buy tramadol tramadol purchase online no prescription - tramadol addiction therapy

Anonymous said...

buy tramadol online zydol tramadol dosage - tramadol highest dosage

Anonymous said...

tramadol without prescription tramadol stronger than vicodin - tramadol yahoo

Anonymous said...

http://buytramadolonlinecool.com/#63102 buy tramadol in usa - buy tramadol online legit

Anonymous said...

buy tramadol 50mg tramadol high dose - order tramadol online reviews

Anonymous said...

http://buytramadolonlinecool.com/#59473 tramadol journal - buy from online texas tramadol

Anonymous said...

buy tramadol rx tramadol zanaflex - tramadol for dogs recommended dosage

Anonymous said...

buy tramadol ultram side effects itching - buy tramadol online no prescription

Anonymous said...

buy tramadol buy tramadol online cheap no prescription - tramadol buy cheap no prescription

Anonymous said...

buy tramadol online no prescription overnight tramadol cream - tramadol 200mg high

Anonymous said...

buy tramadol 4 50 mg tramadol - buy tramadol cod next day delivery

Anonymous said...

buy ativan online ativan for norco withdrawal - generic ativan online

Anonymous said...

buy ativan online ativan dosage body weight - buy lorazepam online with mastercard

Anonymous said...

http://ranchodelastortugas.com/#58720 cost of generic xanax at walmart - .5mg xanax drug test

Anonymous said...

buy tramadol online tramadol hcl para que sirve - buy tramadol england

Anonymous said...

buy tramadol online tramadol hcl high effects - tramadol for dogs and people the same

Anonymous said...

buy tramadol online what does tramadol high feel like - buy tramadol overnight saturday delivery

Anonymous said...

xanax 2mg xanax no prescription legal - xanax drug abuse symptoms

Anonymous said...

buy tramadol online tramadol 400 mg dose - tramadol ultram over the counter

Anonymous said...

buy tramadol online tramadol 50 mg and - tramadol hcl 50 mg tablet uses

Anonymous said...

cheap xanax buy xanax in china - alprazolam0 5mg germed ms

Anonymous said...

buy xanax online no prescription overnight buy alprazolam online forum - xanax nursing implications

Anonymous said...

alprazolam without prescription xanax withdrawal weight loss - xanax dose for recreational use

Anonymous said...

http://bayshorechryslerjeep.com/#8193 xanax side effects 2012 - xanax weight loss