473,386 Members | 1,748 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,386 software developers and data experts.

Substring XPath

This is probably so simple. I am doing a SelectSingleNode to get the value
from an XPath statement, and I simply want the 3 leftmost characters. I
cannot get the syntax to work:

//Client/Names/Name[@nameaddresssource_id='3']/@display_name

So I have tried:

substring(//Client/Names/Name[@nameaddresssource_id='3']/@display_name,1,3)

What is the correct syntax?
Jun 17 '06 #1
2 3486
* Derek Hart wrote in microsoft.public.dotnet.xml:
This is probably so simple. I am doing a SelectSingleNode to get the value
from an XPath statement, and I simply want the 3 leftmost characters.


SelectSingleNode selects a single node; a 3 character string is not a
node, so you cannot do this using SelectSingleNode. You would need a
different method that supports this kind of query, I am not sure your
version of the .NET Framework has one. It might be easier to select
the attribute node and retrieve the 3 characters using native String
operations.
--
Björn Höhrmann · mailto:bj****@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
Jun 17 '06 #2


Derek Hart wrote:
This is probably so simple. I am doing a SelectSingleNode to get the value
from an XPath statement, and I simply want the 3 leftmost characters. I
cannot get the syntax to work:

//Client/Names/Name[@nameaddresssource_id='3']/@display_name

So I have tried:

substring(//Client/Names/Name[@nameaddresssource_id='3']/@display_name,1,3)

What is the correct syntax?


The problem is that SelectSingleNode and SelectNodes needs an XPath
expression that selects a node set while your XPath returns a string so
you need to use a different API, you could use the Evaluate method on an
XPathNavigator, see
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemXmlXPathXPathNavigatorClassEvaluateTopi c1.asp>

Or use SelectSingleNode and then use .NET string operations on the
attribute's Value property.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 17 '06 #3

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

Similar topics

0
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
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...
5
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...
18
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);...
9
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...
5
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>
2
by: aidy | last post by:
Hi, I am using XPath and XSLT and I have a string containing something like this: "gbahes75\Projects\AddressService\Datapool\EnterAddress.sdd" I want to get'EnterAddress.sdd', and I am...
0
by: ghena | last post by:
I'm trying to use an xpath expression in an asp page: set prezzo_andata = xmlDoc.selectNodes("//Outward/Price") the error is: Tipo di errore: msxml3.dll (0x80004005) Unknown method....
1
rhitam30111985
by: rhitam30111985 | last post by:
Hi all , i need some validation I have an xml like this : <root> <url newurl="aTom Bomb" /> <url newurl ="tOm and Jerry" /> <url newurl ="TomBoy" /> <url newurl ="Random...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
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
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.