473,785 Members | 2,498 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XPath

Hi all,

I am new to XPath. I have a doubt in it.

My xml is like this:

<UserInfo>
<Contacts>
<Name>Chris Bob</Name>
</Contacts>
<Contacts>
<Name>Mike Chris</Name>
</Contacts>
<Contacts>
<Name>Chris</Name>
</Contacts>
<Contacts>
<Name>Chrisin e</Name>
</Contacts>
<Contacts>
<Name>Kiran Kumar</Name>
</Contacts>
<Contacts>
<Name>Kumar</Name>
</Contacts>
</UserInfo>

So, i want to search for all names with the value in enter in html text
box.

If i enter Kumar then the last two nodes should come as it has kumar in
it. Similarly if i enter Chris then first three nodes should display,
but the fourth one should not come.
Is this possible. Please help me on how to do it.

--Phani

Jul 20 '05 #1
10 6141


Phani wrote:

I am new to XPath. I have a doubt in it.

My xml is like this:

<UserInfo>
<Contacts>
<Name>Chris Bob</Name>
</Contacts>
<Contacts>
<Name>Mike Chris</Name>
</Contacts>
<Contacts>
<Name>Chris</Name>
</Contacts>
<Contacts>
<Name>Chrisin e</Name>
</Contacts>
<Contacts>
<Name>Kiran Kumar</Name>
</Contacts>
<Contacts>
<Name>Kumar</Name>
</Contacts>
</UserInfo>

So, i want to search for all names with the value in enter in html text
box.

If i enter Kumar then the last two nodes should come as it has kumar in
it. Similarly if i enter Chris then first three nodes should display,
but the fourth one should not come.


If you use the XPath
/UserInfo/Contacts/Name[contains(., 'Kumar')]
then all <Name> elements that contain the string 'Kumar' are found.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #2
> Hi all,

I am new to XPath. I have a doubt in it.

My xml is like this:

<UserInfo>
<Contacts>
<Name>Chris Bob</Name>
</Contacts>
<Contacts>
<Name>Mike Chris</Name>
</Contacts>
<Contacts>
<Name>Chris</Name>
</Contacts>
<Contacts>
<Name>Chrisin e</Name>
</Contacts>
<Contacts>
<Name>Kiran Kumar</Name>
</Contacts>
<Contacts>
<Name>Kumar</Name>
</Contacts>
</UserInfo>

So, i want to search for all names with the value in enter in html text
box.

If i enter Kumar then the last two nodes should come as it has kumar in
it. Similarly if i enter Chris then first three nodes should display,
but the fourth one should not come.
Is this possible. Please help me on how to do it.

Hi,

This is a regular expression problem, regexes are not defined in XSLT1.0, but will be in XSLT2.0

Meanwhile you can use extension, or work around it (in a quite ugly way):
<xsl:apply-templates select="Contact s[contains(concat (' ',Name,' '),concat(' ',$name,' '))]"/>
Or, alternatively, if you can, you should extend the XML structure: split the name node in a 'name' and 'surname' node.
regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
Jul 20 '05 #3
Hi Martin,

I have tried your suggestion and it didn't worked out. It is popping up
an error message saying :

Unknown method.
/UserInfo/Contacts/Name[-->contains(.<--,"Apple")]
The following is the code which i have written:

<html>
<head>
<style type="text/css">
Body {font-family:Arial; }
th {font-size:0.8em;}
td {font-size:0.8em;}
p {font-size:0.8em;}
</style>
</head>
<body>

<xml id="UserInfo" src="test.xml"> </xml>

<p>Enter Name: <input type='text' name=col_no style='border:1 px solid
#d2d2d2'> &nbsp;&nbsp;&nb sp;&nbsp;&nbsp;
<input type=button name='Search' value='Search Now' style='border:1 px
solid black;height=20 px'onClick='jav ascript:var sepvar
= col_no.value;
SetAndFilter(Us erInfo,DataExtr actLower,"UserI nfo/Contacts/Name[contains(.,\"Ap ple\")]")'></p>

<xml id="DataExtract Lower"></xml>
<table datasrc="#DataE xtractLower" width=100% border=0>
<thead bgcolor="#d2d2d 2">
<th>Name</th>
<th>Location</th>
<th>Phone</th>
<th>Extn</th>
<th>Title</th>
<th>Departmen t</th>
</thead>
<tr bgcolor="#e2e2e 2">
<td width="15%"><sp an datafld="Name"> </span></td>
<td width="15%"><sp an datafld="Locati on"></span></td>
<td width="15%"><sp an datafld="Phone" ></span></td>
<td width="15%"><sp an datafld="Extn"> </span></td>
<td width="20%"><sp an datafld="Desig" ></span></td>
<td width="20%"><sp an datafld="DeptCC "></span></td>
</tr>
</table>

<script language=javasc ript>
function SetAndFilter (sourceXML, destXML, XPathFormula) {
alert(XPathForm ula);
sourceXML.setPr operty("Selecti onLanguage", "XPath");
var dummy = destXML.XMLDocu ment.loadXML(so urceXML.xml);
vNodesToRemove = destXML.selectN odes(XPathFormu la) ;
vNodesToRemove. removeAll();
}
</script>

</body>
</html>

So, whatever the user types in should check for the initial characters
of both firstname and last name.

If a user enters "cla" then it should bring back "Michael clark" as
well as "clark michael"

Hope my question is understandable. I learnt a way to program to
display xml like html tables using data islands...

--Phani

Jul 20 '05 #4


Phani wrote:

I have tried your suggestion and it didn't worked out. It is popping up
an error message saying :

Unknown method.
/UserInfo/Contacts/Name[-->contains(.<--,"Apple")]
Are you using IE 6? Only IE 6 comes with MSXML 3 which supports XPath
1.0, earlier versions of IE come with an MSXML version that doesn't
support XPath 1.0. So you either need to install IE 6 or you need to
install MSXML 3 in so called replace mode.

<script language=javasc ript>
function SetAndFilter (sourceXML, destXML, XPathFormula) {
alert(XPathForm ula);
sourceXML.setPr operty("Selecti onLanguage", "XPath");
var dummy = destXML.XMLDocu ment.loadXML(so urceXML.xml);
vNodesToRemove = destXML.selectN odes(XPathFormu la) ;

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #5
I have installed IE6 installed Martin.

Can you tell me on any other ways to do this type of things.

I wanted to load all xml in single shot(when page loads) and then use
the xml (or data islands) to search /filter.
Please let me know on this...

--Phani.

Jul 20 '05 #6


Phani wrote:
I have installed IE6


Looking at your code again I think the problem is here:

sourceXML.setPr operty("Selecti onLanguage", "XPath");
var dummy = destXML.XMLDocu ment.loadXML(so urceXML.xml);
vNodesToRemove = destXML.selectN odes(XPathFormu la) ;

You need to set the SelectionLangua ge on destXML e.g.
destXML.setProp erty("Selection Lanuage", "XPath")

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #7
Yep Martin, i have tried it and this time i didn't got any error.

The javascript written in the code is wrong. It is working only if the
xpath expression contains "!".

like if name!="Apple" then destXML contains only the documents which
have Apple in them.

I need to change it. Can you help me on this. I think vNodesToRemove is
where the problem is .
Can we use "not" expression in XPATH.

--Phani

Jul 20 '05 #8


Phani wrote:

Can we use "not" expression in XPATH.


You might want to read the XPath specification
http://www.w3.org/TR/xpath
http://www.w3.org/TR/xpath#section-Boolean-Functions
And there are tutorials on XPath such as this one:
http://www.w3schools.com/xpath/default.asp

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #9
On Thu, 09 Dec 2004 12:30:48 GMT, "Joris Gillis" <ro**@pandora.b e> wrote:
Ceterum censeo XML omnibus esse utendum

What's the latin translate to? 'XML is for us all to enjoy'?
Thanks
Jeff Kish
Jul 20 '05 #10

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

Similar topics

1
6826
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for elements, attributes, ".", and "..", plus also the "" predicate format is supported - however, only one predicate per path step is supported, and expr must be a relative path. 2. Poor performance
0
1930
by: gael.pegliasco | last post by:
Hi, How are you dear and nice helper :) ? I'm trying to test xpath with this simple program : import xml.dom.minidom from xml.xpath.Context import Context import xml.xpath
4
21210
by: Son KwonNam | last post by:
In XSLT, is this possible to get value from xml using XPath which is in XSLT variable? I mean XPath strings can be dynamic while XSL Transforming. If possible, How?? Because I'm not a native English speaker, it's quite hard to make the problem clear. Please see the following example.
5
4212
by: laks | last post by:
Hi I have the following xsl stmt. <xsl:for-each select="JOB_POSTINGS/JOB_POSTING \"> <xsl:sort select="JOB_TITLE" order="ascending"/> This works fine when I use it. But when using multiple values in the where clause as below
18
7739
by: jacksu | last post by:
I have a simple program to run xpath with xerces 1_2_7 XPathFactory factory = XPathFactory.newInstance(); XPath xPath = factory.newXPath(); XPathExpression xp = xPath.compile(strXpr); System.out.println(xp.evaluate(new InputSource(new FileInputStream("a.xml"))));
9
2155
by: David Thielen | last post by:
Hi; I am sure I am missing something here but I cannot figure it out. Below I have a program and I cannot figure out why the xpath selects that throw an exception fail. From what I know they should work. Also the second nav.OuterXml appears to also be wrong to me. Can someone explain to me why this does not work? (This is an example from a program we have where xpath can be entered in two parts so we have to be able
5
7932
by: Gnic | last post by:
Hi , I have an XmlDocument instance, I want to find a node in the xml, but I don't know it's path until runtime, for example <aaa> <bbb name="x"/> <aaa attr="y"> <ccc>sometext</ccc> </aaa>
3
2212
by: werD | last post by:
Hello I have an xml document that im currently using a forward only .net repeater on and using some xpath queries to display the data The xml is quite simple <?xml version="1.0" encoding="utf-8" ?> <data> <supervisors>
3
4980
by: Jason Mobarak | last post by:
Hello -- I'm attempting to get a handle on how to do xpath queries with System.Xml -- so far the biggest hurdle has been how to deal with a default namespace. If I use the test xml: <?xml version="1.0" encoding="utf-8" ?> <thing xmlns="urn:thing-schema-v1"> <foo>foo thing</foo> <bar>bar thing</bar>
0
9481
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10095
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9954
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7502
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5383
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2881
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.