This is my XML: monitor.xml
<?xml version="1.0" encoding="utf-8" ?>
<ORU_R01>
<MSH>
<MSH.1>|</MSH.1>
<MSH.2>^~\&</MSH.2>
<MSH.3>hospital</MSH.3>
<MSH.7>20170509090310</MSH.7>
<MSH.9>
<MSH.9.1>ORU</MSH.9.1>
<MSH.9.2>R01</MSH.9.2>
</MSH.9>
<MSH.12>2.3.1</MSH.12>
</MSH>
<PID>
<PID.2>SOPITA PALOMINO</PID.2>
<PID.3>SOPITA PALOMINO</PID.3>
<PID.5>S S</PID.5>
<PID.7>19881107</PID.7>
<PID.8>U</PID.8>
</PID>
<PV1>
<PV1.2>U</PV1.2>
<PV1.3>
<PV1.3.3>Bed1</PV1.3.3>
</PV1.3>
<PV1.18>adult</PV1.18>
<PV1.44>20170421</PV1.44>
</PV1>
<OBR>
<OBR.7>20170509090310</OBR.7>
</OBR>
<OBX>
<OBX.2>NM</OBX.2>
<OBX.3>WEIGHT</OBX.3>
<OBX.5>-1.0</OBX.5>
<OBX.6>kg</OBX.6>
</OBX>
<OBX>
<OBX.2>NM</OBX.2>
<OBX.3>HEIGHT</OBX.3>
<OBX.5>-1.0</OBX.5>
<OBX.6>cm</OBX.6>
</OBX>
<OBX>
<OBX.2>NM</OBX.2>
<OBX.3>SpO2</OBX.3>
<OBX.5>96</OBX.5>
<OBX.6>%</OBX.6>
<OBX.7>90-100</OBX.7>
</OBX>
<OBX>
<OBX.2>NM</OBX.2>
<OBX.3>PR</OBX.3>
<OBX.5>69</OBX.5>
<OBX.6>bpm</OBX.6>
<OBX.7>50-120</OBX.7>
</OBX>
</ORU_R01>
I'm trying to find the <OBX.3>
tag inside the <OBX>
tag, but when I use the find() method it does not recognize the dot character (.)
When I change the <OBX.3>
XML tag to <OBX3>
(without a dot character) the find() method recognizes the tag.
$("#btnProbar").click(function (e) {
var TXT_URL = "http://localhost:44467/xml/monitor.xml";
$.ajax({
crossDomain: true,
type: "GET",
url: TXT_URL,
dataType: "XML",
success: function (xml) {
$(xml).find('OBX').each(function () {
var hl7_cabecera = $(this).find("OBX.3").text();
var hl7_valor = $(this).find('OBX.5');
var hl7_metrica = $(this).find('OBX.6');
console.log(hl7_cabecera + ": "+hl7_valor +" " +hl7_metrica);
});
},
error: function() {
alert("The XML File could not be processed correctly.");
}
});
});
What method can I use instead of find() to detect the dot character?
You need to use the regular expressions to fetch the xml nodes which has dot in it.
You need to change your statements as,
var hl7_cabecera = $(xmlDoc).find('OBX.3'.replace(/\./g,'\\.')).text();
var hl7_valor = $(xmlDoc).find('OBX.5'.replace(/\./g,'\\.')).text();
var hl7_metrica = $(xmlDoc).find('OBX.6'.replace(/\./g,'\\.')).text();
Hope this helps!