pa*********@gmail.com wrote:
I've an XML file as follows.
<?xml version="1.0"?>
<packet>
<proto name="bootp" size="272" pos="46">
<field name="bootp.type" size="1" pos="46" show="1" value="01"/></
field>
<field show="Agent Circuit ID: 3031323334" size="7" pos="310"
value="01053031323334"/></field>
</proto>
<packet>
That sample is not well-formed XML at all, you need to correct that to:
<?xml version="1.0"?>
<packet>
<proto name="bootp" size="272" pos="46">
<field name="bootp.type" size="1" pos="46" show="1" value="01"/>
<field show="Agent Circuit ID: 3031323334" size="7" pos="310"
value="01053031323334"/>
</proto>
</packet>
I want to select a node in this tree where node field[show] has a
string that contains string "Agent Circuit ID". How can I do it using
javascript and xmlDoc.selectSingleNode function?
I tried using //field[@show=~"Agent Circuit ID"] and //
field[contains(@show,'Agent Circuit ID')], but '=~' and
'contains' are not recognised within javascript.
Make sure you set the SelectionLanguage property, then contains should
work e.g.
var xmlDocument = new ActiveXObject('Msxml2.DOMDocument.3.0');
xmlDocument.async = false;
xmlDocument.load('file.xml');
xmlDocument.setProperty('SelectionLanguage', 'XPath');
var field = xmlDocument.selectSingleNode(
'packet/proto/field[contains(@show, "Agent Circuit ID")]');
alert(field.xml);
--
Martin Honnen
http://JavaScript.FAQTs.com/