473,472 Members | 2,155 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Prepare String for XPath

Does someone have the routine (preferablly in C#) that takes a string
(i.e. "3995 Joseph, Smith "Joe") and prepares it for use in an XPath
query ( i.e. SelectSingleNode(/member[@name=concat("3995 Joseph, Smith
", '"', "Joe"]) ) so that all escape characters are taken care of and
the issue with not having single and double quotes in the string is also
taken care of? I'm sure many people must have hit this issue; I don't
want to re-invent the wheel if I don't have to.
thanks!

Nov 11 '05 #1
2 3745
Wouldn't it be even cooler if the item worked like SqlParameters where you
could define a parameter like @name and then add a parameters to the
SelectSingleNode.Parameters collection and let the CLR figure out the mess.
:)

I don't have a function but i run across the same problems.

It also seems dependent on if you use single ' or double " to enclose the
text.

if you use " you don't need to encode the '....

It is very frustrating to have to debug.

My two cents.

Joe Feser

"Matthew Wieder" <De*********@SatoriGroupInc.com> wrote in message
news:3F**************@SatoriGroupInc.com...
Does someone have the routine (preferablly in C#) that takes a string
(i.e. "3995 Joseph, Smith "Joe") and prepares it for use in an XPath
query ( i.e. SelectSingleNode(/member[@name=concat("3995 Joseph, Smith
", '"', "Joe"]) ) so that all escape characters are taken care of and
the issue with not having single and double quotes in the string is also
taken care of? I'm sure many people must have hit this issue; I don't
want to re-invent the wheel if I don't have to.
thanks!

Nov 11 '05 #2
To save someone else the trouble, here's the code (in C#):
//this method takes a string used as an attribute of and XPath query and
handles quotation marks as neccesary
private string PrepXPathString(string strInput)
{
string[] saParts;
string strOutput;

saParts = strInput.Split("\"".ToCharArray());

//string contains no quotes so only need to wrap in quotes
if (saParts.Length == 1)
{
strOutput = "\"" + strInput + "\"";;
}
else
{
strOutput = "concat(";
strOutput+= "\"" + saParts[0] + "\"";

for (int i=1; i<saParts.Length; i++)
{
strOutput+= ",'\"',";
strOutput+= "\"" + saParts[i] + "\"";
}

strOutput+= ")";
}

return strOutput;
}

Joe Feser wrote:
Wouldn't it be even cooler if the item worked like SqlParameters where you
could define a parameter like @name and then add a parameters to the
SelectSingleNode.Parameters collection and let the CLR figure out the mess.
:)

I don't have a function but i run across the same problems.

It also seems dependent on if you use single ' or double " to enclose the
text.

if you use " you don't need to encode the '....

It is very frustrating to have to debug.

My two cents.

Joe Feser

"Matthew Wieder" <De*********@SatoriGroupInc.com> wrote in message
news:3F**************@SatoriGroupInc.com...
Does someone have the routine (preferablly in C#) that takes a string
(i.e. "3995 Joseph, Smith "Joe") and prepares it for use in an XPath
query ( i.e. SelectSingleNode(/member[@name=concat("3995 Joseph, Smith
", '"', "Joe"]) ) so that all escape characters are taken care of and
the issue with not having single and double quotes in the string is also
taken care of? I'm sure many people must have hit this issue; I don't
want to re-invent the wheel if I don't have to.
thanks!



Nov 11 '05 #3

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

Similar topics

1
by: Alastair Cameron | last post by:
VB6, MSXML 3.2 installed: Q1. I am having a problem selecting nodes with XPATH expressions when an attribute values contain backslashes (\\) in as part of its value: For example the...
2
by: Robert Kattke | last post by:
I'm getting a TransformerException when running Tomcat and calling a Servlet that use XML to create DOM and XSL to create webpage. I'm posting just the snippet of XSL code and the Error here. ...
1
by: kurt hansen | last post by:
hi I thought that this would be easy, but maybe not so much. I want to: pass an xpath expression and a string value to a stylesheet and copy the source xml document, changing the value of...
1
by: Murtaza Tinwala | last post by:
Hi mates, I have the following problem in XSLT. I have following variables: ref-file = <path of XML document> eg "xmlDoc.xml" repeatpath = <a repeat path expressed in Xpath like /root/person >...
3
by: sshahin | last post by:
Is there a way to Convert a Node to a String using XPath 1.0? For example, consider the following xml doc: <?xml version="1.0" encoding="UTF-8"?> <FaultTo xmlns="http://blah.org"...
2
by: C# newbie | last post by:
Hi, I'm new to xml and sometimes gives me a hardtime. is there any xpah query that returns a particular string I'm looking for? I used: //*contains(text()="foo") the "foo" could be in any...
0
by: RG | last post by:
OleDbCommand.Prepare error: Size of parameter (VB.NET 2003) I need to do a SQL INSERT statement into an Access table, and I’d like to use the exact technique described in the Help file example...
2
by: Rajat Katyal | last post by:
Hi: I prepare the statement for execution as follows: PREPARE query(text) as SELECT count(*) FROM transform_customer_billing where inv_no = $1; The problem is Iam not able to execute this...
8
by: Alpha | last post by:
I created the following code in my C# program but it's giving me error message at run time of : XML.XPATH.XPATHEXCEPTION : Namespace Manager or XSLTContext needed. This query has a prefix,...
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
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
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...
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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...
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.