all groups > dotnet xml > may 2006 >
You're in the

dotnet xml

group:

"this is an unexpected token" error


"this is an unexpected token" error lisa NO[at]SPAM starways.net
5/23/2006 1:08:46 PM
dotnet xml:
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
Re: "this is an unexpected token" error Scott M.
5/23/2006 8:14:36 PM
We need to see all of the XML to determine the error.


[quoted text, click to view]

Re: "this is an unexpected token" error lisa NO[at]SPAM starways.net
5/24/2006 7:09:28 AM
Ah. That explains it. Thanks.

Lisa


[quoted text, click to view]
Re: "this is an unexpected token" error Martin Honnen
5/24/2006 2:32:23 PM


[quoted text, click to view]

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
Re: "this is an unexpected token" error Oleg Tkachenko [MVP]
5/24/2006 5:44:09 PM
[quoted text, click to view]

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

--
Oleg Tkachenko [XML MVP, MCAD]
AddThis Social Bookmark Button