473,397 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

select XML node containing a matching string

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>

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.

thanks in advance.

Saurabh

May 16 '07 #1
1 4388
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/
May 16 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Chris | last post by:
Hi, Maybe I've got a strange question. I've got a XML document (main.xml) with several nodes. Additional I've another XML docuement (role.xml), with allowed nodes. In a XSL-File I just would...
3
by: Earl Teigrob | last post by:
I am considering writing a Class that Selects, Adds, Updates and Deletes Nodes in an XML File but do not what to reinvent the wheel. (See XML file below) That data format would emulate records...
4
by: bill salkin | last post by:
The code below creates a dataset containing a table called "Customers" from the Northwind database Later on in my code, after the database connection is closed, I need to access this dataset to...
13
by: André Nogueira | last post by:
Hi there. I know you can view a node's fullpath property, but is it posible to select a node using its path? Like, tell the treeview that the node that should be selected is the node with the...
3
by: ANTISPAM_garycnew_ANTISPAM | last post by:
What is the simplest way to retain the last option value selected in an html select object using javascript? I am currently using a server-side cgi language to accomplish this task, but it adds...
4
by: praveen | last post by:
I have a form with treeview control loaded from xml document,text box, two buttons named "Find" and "FindNext" and my treeview which looks like below. Details |__ policy status |__ created by...
22
by: MP | last post by:
vb6,ado,mdb,win2k i pass the sql string to the .Execute method on the open connection to Table_Name(const) db table fwiw (the connection opened via class wrapper:) msConnString = "Data Source="...
4
by: Matt Kruse | last post by:
According to standards, if an option is selected and it has no VALUE attribute, the contents of the option tag is to be submitted. So: <select name="sel"> <option selected>Value</option>...
8
by: =?Utf-8?B?WVhR?= | last post by:
I want to do the multi-language program, save the language text in XML file, but how to read the specified node value? the xml is below, for example, i want to get the value(AAA content) that named...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.