0

How can I get observation element and its inner elements?

 <organizer moodCode="EVN" classCode="CLUSTER">
    <templateId root="2.16.840.1.113883.3.129.3.3.6.0"/>
    <statusCode code="completed"/>
    <component>
       <observation moodCode="EVN" classCode="OBS">
          <templateId root="2.16.840.1.113883.3.129.3.3.6.1"/>
          <code codeSystemVersion="2.0" displayName="Kabul Bilgileri" codeSystemName="Veri Kısmı" code="KABUL_BILGILERI" codeSystem="2.16.840.1.113883.3.129.2.2.3"/>
          <effectiveTime value="20120102134751"/>
          <value xsi:type="CD" codeSystemVersion="2.0" displayName="Diğer" codeSystemName="Kabul Şekli" code="98" codeSystem="2.16.840.1.113883.3.129.1.2.7"/>
       </observation>
    </component>
    <component>
       <observation moodCode="EVN" classCode="OBS">
          <templateId root="2.16.840.1.113883.3.129.3.4.365"/>
          <code codeSystemVersion="2.0" displayName="Vaka Türü" codeSystemName="Veri Elemanı" code="VAKA_TURU" codeSystem="2.16.840.1.113883.3.129.2.2.7"/>
          <value xsi:type="CD" codeSystemVersion="2.0" displayName="Normal" codeSystemName="Vaka Türü" code="1" codeSystem="2.16.840.1.113883.3.129.1.2.53"/>
       </observation>
    </component>
 </organizer>

UPDATE: This could be html or another markup language. I just want to retrieve observation elements and inner elements. I won't use this in a program when it is running.

uzay95
  • 16,052
  • 31
  • 116
  • 182
  • 5
    [By using an XML parser.](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454) – rid Jul 26 '12 at 13:42
  • 1
    Don't use regex, use parsers! – Ωmega Jul 26 '12 at 13:43
  • 1
    See http://stackoverflow.com/a/1732454/647772 –  Jul 26 '12 at 13:43
  • regex? What language are you using? Why to you need to get observation? Is the XML you have a string or some other object (XElemenet, XmlDocument, etc.) – james31rock Jul 26 '12 at 13:44

2 Answers2

3

As Jeff explained, you should definitely avoid using regular expressions for that job, when XML parsers exist and would take care of all the nasty details for you!

Wookai
  • 20,883
  • 16
  • 73
  • 86
1

As noted by others you need an XML parse not regular expressions.

Use your XML parser's1 XPath selection with the query:

//observation

to get all the <observation> elements with their child nodes.


1 Without knowing you programming platform we cannot help you with that part.

Richard
  • 106,783
  • 21
  • 203
  • 265