473,325 Members | 2,308 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,325 software developers and data experts.

Error message when retriving a string from my xml file in C#.net a

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, variable or user defined function.
Can someone see what I'm doing wrong? Thanks, Alpha

private XPathDocument unityMessages = new XPathDocument("UnityMessages.xml");

unityMsgNavigator = unityMessages.CreateNavigator();

string query = @"/trans-unit[@id=""m1""]/target[@xml:lang=""fr""]";

XPathExpression queryM1 = unityMsgNavigator.Compile(query);

m1 = (string)unityMsgNavigator.Evaluate(queryM1);

Here is part of the content from my xml file:
<?xml version="1.0" encoding="utf-8" ?>
<xliff version="1.1">
<trans-unit id="m1">
<source xml:lang="en-us">Error populating the children nodes of the
selected node.</source>
<target xml:lang="fr">Translation of "Vous le vou coucher avec moi
sesua?"</target>
</trans-unit>
</xliff>

Jan 12 '06 #1
8 3745


Alpha wrote:
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, variable or user defined function.
string query = @"/trans-unit[@id=""m1""]/target[@xml:lang=""fr""]";


You are using the prefix xml in the attribute name xml:lang without
using a namespace manager.
Either use a namespace manager or simply do
string query = @"/trans-unit[@id=""m1""]/target[lang(""fr"")]"

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jan 13 '06 #2
This is what I have in the code but it's still not diaplaying any messages.
However, I did get rid of that Name Sapce Manager Error message though.
Thank you. Can you please have a look again at my code and tell me what I'm
doing wrong here. Thanks a million. I'm trying to set up a XML file for
capturing all messages string for futuer localization usages.
Thanks, Alpha
try
{
unityMessages = new
XPathDocument(@"C:\PROJECTS\PPGLOBAL\UnityMessages .xml");
unityMsgNavigator = unityMessages.CreateNavigator();

string query =
@"/trans-unit[@id=""m1""]/target[lang(""fr"")]";
XPathExpression queryM1 = unityMsgNavigator.Compile(query);
XPathNodeIterator ni =
(XPathNodeIterator)unityMsgNavigator.Evaluate(quer yM1);
while (ni.MoveNext())
{
MessageBox.Show(ni.Current.ToString());
}
This is what I have in the xml file:
<?xml version="1.0" encoding="utf-8" ?>
<xliff version="1.1">
<trans-unit id="m1">
<source xml:lang="en-us">Error populating the children nodes of the
selected node.</source>
<target xml:lang="fr">Translation of "Vous le vou coucher avec moi
sesua?"</target>
</trans-unit>
</xliff>
"Martin Honnen" wrote:


Alpha wrote:
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, variable or user defined function.


string query = @"/trans-unit[@id=""m1""]/target[@xml:lang=""fr""]";


You are using the prefix xml in the attribute name xml:lang without
using a namespace manager.
Either use a namespace manager or simply do
string query = @"/trans-unit[@id=""m1""]/target[lang(""fr"")]"

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Jan 13 '06 #3


Alpha wrote:

string query =
@"/trans-unit[@id=""m1""]/target[lang(""fr"")]";
<xliff version="1.1">
<trans-unit id="m1">
<source xml:lang="en-us">Error populating the children nodes of the
selected node.</source>
<target xml:lang="fr">Translation of "Vous le vou coucher avec moi
sesua?"</target>
</trans-unit>
</xliff>


You want this XPath expression (well C# string literal with an XPath
expression) then
@"/xliff/trans-unit[@id=""m1""]/target[lang(""fr"")]"

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jan 13 '06 #4
Yes, thank you so very much. It is working now. I just have one more
question. Why doesn't this line of code worked?
string m1 = (string)unityMsgNavigator.Evaluate(queryM1);
I thought the Evalute method returns the typed result but I'm getting
messages about it can't cast the type XPathNodeIterator to string.

Thanks, Alpha

"Martin Honnen" wrote:


Alpha wrote:

string query =
@"/trans-unit[@id=""m1""]/target[lang(""fr"")]";


<xliff version="1.1">
<trans-unit id="m1">
<source xml:lang="en-us">Error populating the children nodes of the
selected node.</source>
<target xml:lang="fr">Translation of "Vous le vou coucher avec moi
sesua?"</target>
</trans-unit>
</xliff>


You want this XPath expression (well C# string literal with an XPath
expression) then
@"/xliff/trans-unit[@id=""m1""]/target[lang(""fr"")]"

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Jan 13 '06 #5


Alpha wrote:
I just have one more
question. Why doesn't this line of code worked?
string m1 = (string)unityMsgNavigator.Evaluate(queryM1);
I thought the Evalute method returns the typed result but I'm getting
messages about it can't cast the type XPathNodeIterator to string.


XPath expressions can be of four types, a string or a boolean or a
number or a node set. Most XPath expressions used evaluate to a node set
and will be treated as an XPathNodeIterator then in .NET code outside of
XPath.
If you have an XPath expression explictly returning e.g. a number for
instance
double count = (double)navigator.Evaluate("count(//*)")
then such a cast works.
To explicity return a string you could do e.g.
string name = (string)navigator.Evaluate("local-name(/*)")
or
string someValue = (string)navigator.Evaluate("string(/root/element)")

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jan 14 '06 #6
Martin

"XPath expressions can be of four types, a string or a boolean or a
number or a node set."
Is that only for Xpath 1.0.
2.0 introduces support for the XML Schema primitive types, which immediately gives the user access to 19 simple types, including dates, years, months, URIs and others?

Aaron
"Martin Honnen" <ma*******@yahoo.de> wrote in message news:uE**************@TK2MSFTNGP09.phx.gbl...


Alpha wrote:
I just have one more
question. Why doesn't this line of code worked?
string m1 = (string)unityMsgNavigator.Evaluate(queryM1);
I thought the Evalute method returns the typed result but I'm getting
messages about it can't cast the type XPathNodeIterator to string.


XPath expressions can be of four types, a string or a boolean or a
number or a node set. Most XPath expressions used evaluate to a node set
and will be treated as an XPathNodeIterator then in .NET code outside of
XPath.
If you have an XPath expression explictly returning e.g. a number for
instance
double count = (double)navigator.Evaluate("count(//*)")
then such a cast works.
To explicity return a string you could do e.g.
string name = (string)navigator.Evaluate("local-name(/*)")
or
string someValue = (string)navigator.Evaluate("string(/root/element)")

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Jan 14 '06 #7


Aaron wrote:

"XPath expressions can be of four types, a string or a boolean or a
number or a node set."
Is that only for Xpath 1.0.
Yes, and my answer was in a post about a specific problem with using
XPath from .NET code where .NET only supports XPath 1.0 so I don't see
why it should have been more generic.
2.0 introduces support for the XML Schema primitive types, which
immediately gives the user access to 19 simple types, including dates,
years, months, URIs and others?


XPath 2.0 and its data model indeed tries to (re)use the W3C schema data
types but that does not help when using the XPath API in current .NET
versions.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jan 14 '06 #8
Hi Martin,

I tried the following code but I got an error message about illegal token in
the string. I also tried the 2nd string type you suggested and got the same
error. Can you have a look and let me know how I should correct this?

Thank you, Alpha

string query =
@"xliff/trans-unit[@id=""m1""]/target[lang(""fr"")](/root/element)";

string query = @"xliff/trans-unit[@id=""m1""]/target[lang(""fr"")](/*)";

XPathExpression queryM1 = unityMsgNavigator.Compile(query);
m1 = (string)unityMsgNavigator.Evaluate(queryM1);
"Martin Honnen" wrote:


Alpha wrote:
I just have one more
question. Why doesn't this line of code worked?
string m1 = (string)unityMsgNavigator.Evaluate(queryM1);
I thought the Evalute method returns the typed result but I'm getting
messages about it can't cast the type XPathNodeIterator to string.


XPath expressions can be of four types, a string or a boolean or a
number or a node set. Most XPath expressions used evaluate to a node set
and will be treated as an XPathNodeIterator then in .NET code outside of
XPath.
If you have an XPath expression explictly returning e.g. a number for
instance
double count = (double)navigator.Evaluate("count(//*)")
then such a cast works.
To explicity return a string you could do e.g.
string name = (string)navigator.Evaluate("local-name(/*)")
or
string someValue = (string)navigator.Evaluate("string(/root/element)")

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Jan 17 '06 #9

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

Similar topics

1
by: Wayno | last post by:
My php logs are coming up empty. I have done all I can think of, and all that made sense to me. Can someone take a look at my php.ini please and tell me what you think may be the problem. I...
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
1
by: Bryan Masephol | last post by:
Hi All I have a OleDbConnection as the "connection" below. I'm retriving a dataset from an access 2002 db and displaying it in a DataGrid. I'm making the connection to my access db file with...
9
by: Tim D | last post by:
Hi, I originally posted this as a reply to a rather old thread in dotnet.framework.general and didn't get any response. I thought it might be more relevant here; anyone got any ideas? My...
8
by: jcrouse | last post by:
I am using the following code to trap errors in a sub routine: Try Executable code Catch ex As Exception Dim strInputE As String = Application.StartupPath & "\Error.txt" Dim srE As...
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
8
by: mohit | last post by:
Hi, I am creating a web application in Web Matrix on the .NET framework. I have two directories :AddUser and FormAuth in a Directory P. AddUser contains a file AddUser.aspx FormAuth contains :...
5
by: snicks | last post by:
I'm trying to exec a program external to my ASP.NET app using the following code. The external app is a VB.NET application. Dim sPPTOut As String sPPTOut = MDEPDirStr + sID + ".ppt" Dim p As...
1
by: Kunal Nandi | last post by:
can any one give me the code for uploading and retriving image using Blob, with jsp at front end and oracle8i at the back end ??????? i have tried this using long raw datatype i was able to upload...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.