By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,813 Members | 1,253 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,813 IT Pros & Developers. It's quick & easy.

"this is an unexpected token" error

P: n/a
I have an XML file that starts like this:

<?xml version="1.0" encoding="ISO-8859-1"
xmlns:fn="http://www.w3.org/2005/xpath-functions"?>
<Authors>
<Author>
<ID>2</ID>
<UserName>Whoever</UserName>
<Title>Whatever</Title>
<Internet>email</Internet>
<Office>email</Office>
</Author>

It has multiple "<Author>" nodes.

I have VB.NET code that looks like this:

Dim doc As new XPathDocument(_fileName)
Dim nav As XPathNavigator = doc.CreateNavigator()

'set selection criteria
Dim crit As String
crit = "fn:distinct-values(descendant::Author/Office)"

'select and sort
Dim expr As XPathExpression
expr = nav.Compile(crit)
expr.AddSort("Office", XmlSortOrder.Ascending,
XmlCaseOrder.None, _
"", XmlDataType.Text)

'store results in collection
Dim iter As XPathNodeIterator
Try
iter = nav.Select(expr)
Catch ex As Exception
MsgBox(ex.Message)
End Try

And that's where I get the error. I found the functions at
http://www.w3schools.com/xpath/xpath_functions.asp and put the fn
namespace into the XML file so that I can use them. But the error
message that comes up when I try to select that expression is:

This is an unexpected token. The expected token is 'NAME'. Line 1,
position 43.

The 43rd character on the 1st line is the "x" in "xmlns:fn". What kind
of token is the parser looking for?

Thanks,
Lisa

May 23 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
We need to see all of the XML to determine the error.
<li**@starways.net> wrote in message
news:11**********************@j33g2000cwa.googlegr oups.com...
I have an XML file that starts like this:

<?xml version="1.0" encoding="ISO-8859-1"
xmlns:fn="http://www.w3.org/2005/xpath-functions"?>
<Authors>
<Author>
<ID>2</ID>
<UserName>Whoever</UserName>
<Title>Whatever</Title>
<Internet>email</Internet>
<Office>email</Office>
</Author>

It has multiple "<Author>" nodes.

I have VB.NET code that looks like this:

Dim doc As new XPathDocument(_fileName)
Dim nav As XPathNavigator = doc.CreateNavigator()

'set selection criteria
Dim crit As String
crit = "fn:distinct-values(descendant::Author/Office)"

'select and sort
Dim expr As XPathExpression
expr = nav.Compile(crit)
expr.AddSort("Office", XmlSortOrder.Ascending,
XmlCaseOrder.None, _
"", XmlDataType.Text)

'store results in collection
Dim iter As XPathNodeIterator
Try
iter = nav.Select(expr)
Catch ex As Exception
MsgBox(ex.Message)
End Try

And that's where I get the error. I found the functions at
http://www.w3schools.com/xpath/xpath_functions.asp and put the fn
namespace into the XML file so that I can use them. But the error
message that comes up when I try to select that expression is:

This is an unexpected token. The expected token is 'NAME'. Line 1,
position 43.

The 43rd character on the 1st line is the "x" in "xmlns:fn". What kind
of token is the parser looking for?

Thanks,
Lisa

May 24 '06 #2

P: n/a


li**@starways.net wrote:
I have an XML file that starts like this:

<?xml version="1.0" encoding="ISO-8859-1"
xmlns:fn="http://www.w3.org/2005/xpath-functions"?> crit = "fn:distinct-values(descendant::Author/Office)"


Note that .NET 1.x and .NET 2.x support XPath 1.0 and some extension
functions while the function distinct-values is XPath 2.0 and not
supported in the .NET framework provided by Microsoft.

You would need to install Saxon 8 .NET to have XSLT/XPath 2.0 support.

Or you can use EXSLT.NET <http://www.xmlmvp.org/exslt/index.html> which
has its own distinct function
<http://exslt.org/set/functions/distinct/index.html>

--

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

P: n/a
Ah. That explains it. Thanks.

Lisa
Martin Honnen wrote:
li**@starways.net wrote:
I have an XML file that starts like this:

<?xml version="1.0" encoding="ISO-8859-1"
xmlns:fn="http://www.w3.org/2005/xpath-functions"?>

crit = "fn:distinct-values(descendant::Author/Office)"


Note that .NET 1.x and .NET 2.x support XPath 1.0 and some extension
functions while the function distinct-values is XPath 2.0 and not
supported in the .NET framework provided by Microsoft.

You would need to install Saxon 8 .NET to have XSLT/XPath 2.0 support.

Or you can use EXSLT.NET <http://www.xmlmvp.org/exslt/index.html> which
has its own distinct function
<http://exslt.org/set/functions/distinct/index.html>

--

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


May 24 '06 #4

P: n/a
li**@starways.net wrote:
I have an XML file that starts like this:

<?xml version="1.0" encoding="ISO-8859-1"
xmlns:fn="http://www.w3.org/2005/xpath-functions"?>


Syntax error in XML declaration. XML declaration can't contain namespace
declarations.

--
Oleg Tkachenko [XML MVP, MCAD]
http://www.XmlLab.Net | http://www.XLinq.Net | http://blog.tkachenko.com
May 24 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.