Newbie, need help with complex document

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Im trying to find an example of navigating an XML document with nested child nodes.<br/> <br/> Was wondering if there are any posts or resources can help me.<br/> <br/> I have pasted the document Id like to read below.<br/> <br/> The document contains 3 sections.<br/> <br/> Id like to read these 3 sections, then navigate to child nodes of this section.<br/> <br/> In some cases, I have to read child nodes of the child nodes.<br/> <br/> How do I do this?<br/> <br/> For example, Id like to get to <substanceAdministration> from <section>, and then read each element in the <substanceAdministration> node.<br/> <br/> <component><br/> <structuredBody><br/> <component><br/> <section><br/> <templateId /><br/> <code /><br/> <entry><br/> <substanceAdministration><br/> <templateId /><br/> <doseQuantity /><br/> <br/> I dont know the number of sections in a document in advance.<br/> <br/> So I would like to loop through each section of the document, then read all the elements in the <substanceAdministration> node.<br/> <br/> So far, I can get to the <section> node, but I cant get to the <substanceAdministration> node and read its elements.<br/> <br/> XmlDocument doc = new XmlDocument();<br/> doc.Load(destPath);<br/> XmlNodeList sections = doc.GetElementsByTagName("section");<br/> lblStatus.Text += "<ol>";<br/> foreach (XmlNode node in sections)<br/> {<br/> XmlElement sectionElement = (XmlElement)node;<br/> string templateId_root = string.Empty;<br/> string section_name = string.Empty;<br/> foreach (XmlNode x in sectionElement.ChildNodes)<br/> {<br/> section_name = x.Name;<br/> lblStatus.Text += "" + section_name + "";<br/> } <br/> }<br/> lblStatus.Text += "</ol>"; <br/> <br/> Would appreciated guidance to some resources on navigating child nodes in this case.<br/> <br/> Thanks,<br/> Gary<br/> <br/> <br/> DOCUMENT<br/> <br/> <component><br/> <structuredBody classCode="DOCBODY" moodCode="EVN <br/> <component><br/> <section classCode="DOCSECT" moodCode="EVN <br/> <templateId root="2.16.840.1.113883.10.20.1.8" /><br/> <code code="10160-0" codeSystem="2.16.840.1.113883.6.1" /><br/> <entry typeCode="DRIV <br/> <substanceAdministration classCode="SBADM" moodCode="EVN <br/> <templateId root="2.16.840.1.113883.10.20.1.24" /><br/> <doseQuantity /><br/> <consumable typeCode="CSM <br/> <manufacturedProduct><br/> <templateId root="2.16.840.1.113883.10.20.1.53" /><br/> <manufacturedMaterial classCode="MMAT <br/> <name>IBUPROFEN 600 MG ORAL TAB</name><br/> </manufacturedMaterial><br/> </manufacturedProduct><br/> </consumable><br/> <entryRelationship typeCode="SUBJ <br/> <act classCode="ACT" moodCode="INT <br/> <templateId root="2.16.840.1.113883.10.20.1.49" /><br/> <code displayName="Instructions" /><br/> <text><br/> <reference value="#medicationInstructionID0" /><br/> </text><br/> </act><br/> </entryRelationship><br/> <entryRelationship typeCode="REFR <br/> <supply classCode="SPLY" moodCode="INT <br/> <templateId root="2.16.840.1.113883.10.20.1.34" /><br/> <id /><br/> <effectiveTime value="20090818" /><br/> <repeatNumber value="0" /><br/> <quantity value="0" /><br/> <expectedUseTime value="457" /><br/> </supply><br/> </entryRelationship><br/> <entryRelationship typeCode="REFR <br/> <supply classCode="SPLY" moodCode="INT <br/> <templateId root="2.16.840.1.113883.10.20.1.34" /><br/> <id /><br/> </supply><br/> </entryRelationship><br/> </substanceAdministration><br/> </entry><br/> <entry typeCode="DRIV <br/> <substanceAdministration classCode="SBADM" moodCode="EVN <br/> <templateId root="2.16.840.1.113883.10.20.1.24" /><br/> <doseQuantity /><br/> <consumable typeCode="CSM <br/> <manufacturedProduct><br/> <templateId root="2.16.840.1.113883.10.20.1.53" /><br/> <manufacturedMaterial classCode="MMAT <br/> <name>ASPIRIN 325 MG ORAL TAB</name><br/> </manufacturedMaterial><br/> </manufacturedProduct><br/> </consumable><br/> <entryRelationship typeCode="SUBJ <br/> <act classCode="ACT" moodCode="INT <br/> <templateId root="2.16.840.1.113883.10.20.1.49" /><br/> <code displayName="Instructions" /><br/> <text><br/> <reference value="#medicationInstructionID1" /><br/> </text><br/> </act><br/> </entryRelationship><br/> <entryRelationship typeCode="REFR <br/> <supply classCode="SPLY" moodCode="INT <br/> <templateId root="2.16.840.1.113883.10.20.1.34" /><br/> <id /><br/> <effectiveTime value="20070808" /><br/> <repeatNumber value="0" /><br/> <quantity value="0" /><br/> <expectedUseTime /><br/> </supply><br/> </entryRelationship><br/> <entryRelationship typeCode="REFR <br/> <supply classCode="SPLY" moodCode="INT <br/> <templateId root="2.16.840.1.113883.10.20.1.34" /><br/> <id /><br/> </supply><br/> </entryRelationship><br/> </substanceAdministration><br/> </entry><br/> <entry typeCode="DRIV <br/> <substanceAdministration classCode="SBADM" moodCode="EVN <br/> <templateId root="2.16.840.1.113883.10.20.1.24" /><br/> <doseQuantity /><br/> <consumable typeCode="CSM <br/> <manufacturedProduct><br/> <templateId root="2.16.840.1.113883.10.20.1.53" /><br/> <manufacturedMaterial classCode="MMAT <br/> <name>ACETAMINOPHEN 325 MG ORAL TAB</name><br/> </manufacturedMaterial><br/> </manufacturedProduct><br/> </consumable><br/> <entryRelationship typeCode="SUBJ <br/> <act classCode="ACT" moodCode="INT <br/> <templateId root="2.16.840.1.113883.10.20.1.49" /><br/> <code displayName="Instructions" /><br/> <text><br/> <reference value="#medicationInstructionID2" /><br/> </text><br/> </act><br/> </entryRelationship><br/> <entryRelationship typeCode="REFR <br/> <supply classCode="SPLY" moodCode="INT <br/> <templateId root="2.16.840.1.113883.10.20.1.34" /><br/> <id /><br/> <effectiveTime value="20070607" /><br/> <repeatNumber value="0" /><br/> <quantity value="0" /><br/> <expectedUseTime /><br/> </supply><br/> </entryRelationship><br/> <entryRelationship typeCode="REFR <br/> <supply classCode="SPLY" moodCode="INT <br/> <templateId root="2.16.840.1.113883.10.20.1.34" /><br/> <id /><br/> </supply><br/> </entryRelationship><br/> </substanceAdministration><br/> </entry><br/> </section><br/> </component><br/> <component><br/> <section classCode="DOCSECT" moodCode="EVN <br/> <templateId root="2.16.840.1.113883.10.20.1.2" /><br/> <code nullFlavor="NA" code="11450-4" codeSystem="2.16.840.1.113883.6.1" /><br/> <title>Allergies, Adverse Reactions, Alerts</title><br/> <entry typeCode="DRIV <br/> <act nullFlavor="NA" classCode="ACT" moodCode="EVN <br/> <templateId root="2.16.840.1.113883.10.20.1.27" /><br/> <code nullFlavor="NA" /><br/> <entryRelationship typeCode="SUBJ <br/> <observation classCode="OBS" moodCode="INT <br/> <templateId root="2.16.840.1.113883.10.20.1.54" /><br/> <code code="ASSERTION" codeSystem="2.16.840.1.113883.5.4" displayName="Diagnosis" /><br/> <effectiveTime value="20070823" /><br/> <value xsi:type="CD" nullFlavor="NI" code="282100009" codeSystem="2.16.840.1.113883.6.96" displayName="Adverse reaction to substance" /><br/> <participant typeCode="CSM" contextControlCode="OP <br/> <participantRole classCode="MANU <br/> <playingEntity classCode="MMAT" determinerCode="INSTANCE <br/> <code nullFlavor="NI" code="70618" codeSystem="2.16.840.1.113883.6.88" displayName="SEAFOOD" /><br/> </playingEntity><br/> </participantRole><br/> </participant><br/> <entryRelationship typeCode="MFST <br/> <observation classCode="OBS" moodCode="INT <br/> <templateId root="2.16.840.1.113883.10.20.1.54" /><br/> <code code="ASSERTION" codeSystem="2.16.840.1.113883.5.4" /><br/> <effectiveTime value="20070823" /><br/> <value xsi:type="CD" codeSystem="2.16.840.1.113883.6.96" displayName=" " /><br/> </observation><br/> </entryRelationship><br/> </observation><br/> </entryRelationship><br/> </act><br/> </entry><br/> </section><br/> </component><br/> <component><br/> <section classCode="DOCSECT" moodCode="EVN <br/> <templateId root="2.16.840.1.113883.10.20.1.6" /><br/> <code code="11369-6" codeSystem="2.16.840.1.113883.6.1" /><br/> <title>Immunizations</title><br/> <entry nullFlavor="NA" typeCode="DRIV <br/> <substanceAdministration classCode="SBADM" moodCode="EVN <br/> <templateId root="2.16.840.1.113883.10.20.1.24" /><br/> <effectiveTime xsi:type="IVL_TS" value="20040501" /><br/> <consumable typeCode="CSM <br/> <manufacturedProduct><br/> <templateId root="2.16.840.1.113883.10.20.1.53" /><br/> <manufacturedMaterial classCode="MMAT <br/> <code nullFlavor="NI" code="88" codeSystem="2.16.840.1.113883.6.59" displayName="HBV (HEPATITIS B) <br/> <originalText>HBV (HEPATITIS B)</originalText><br/> [/code]<br/> </manufacturedMaterial><br/> </manufacturedProduct><br/> </consumable><br/> </substanceAdministration><br/> </entry><br/> <entry nullFlavor="NA" typeCode="DRIV <br/> <substanceAdministration classCode="SBADM" moodCode="EVN <br/> <templateId root="2.16.840.1.113883.10.20.1.24" /><br/> <effectiveTime xsi:type="IVL_TS" value="20070906" /><br/> <consumable typeCode="CSM <br/> <manufacturedProduct><br/> <templateId root="2.16.840.1.113883.10.20.1.53" /><br/> <manufacturedMaterial classCode="MMAT <br/> <code nullFlavor="NI" code="88" codeSystem="2.16.840.1.113883.6.59" displayName="TETIG (TETANUS IMMUNE GLOBULIN) <br/> <originalText>TETIG (TETANUS IMMUNE GLOBULIN)</originalText><br/> [/code]<br/> </manufacturedMaterial><br/> </manufacturedProduct><br/> </consumable><br/> </substanceAdministration><br/> </entry><br/> <entry nullFlavor="NA" typeCode="DRIV <br/> <substanceAdministration classCode="SBADM" moodCode="EVN <br/> <templateId root="2.16.840.1.113883.10.20.1.24" /><br/> <effectiveTime xsi:type="IVL_TS" value="20090611" /><br/> <consumable typeCode="CSM <br/> <manufacturedProduct><br/> <templateId root="2.16.840.1.113883.10.20.1.53" /><br/> <manufacturedMaterial classCode="MMAT <br/> <code nullFlavor="NI" code="88" codeSystem="2.16.840.1.113883.6.59" displayName="SMA (SMALLPOX) <br/> <originalText>SMA (SMALLPOX)</originalText><br/> [/code]<br/> </manufacturedMaterial><br/> </manufacturedProduct><br/> </consumable><br/> </substanceAdministration><br/> </entry><br/> </section><br/> </component><br/> </structuredBody><br/> </component>

View the full article
 
Back
Top