Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   .NET-Sprachen (https://www.delphipraxis.net/82-net-sprachen/)
-   -   C# XPathException (https://www.delphipraxis.net/165525-xpathexception.html)

Cogito 4. Jan 2012 09:11

XPathException
 
Hallo zusammen,

ich bekomme an einer Stelle meines Programms eine XPathException mit folgendem Text:

Code:
************** Exception Text **************
System.Xml.XPath.XPathException: 'companies/company[displayName=Monterey Holdings I Sàrl]' has an invalid token.
   at MS.Internal.Xml.XPath.XPathParser.CheckToken(LexKind t)
   at MS.Internal.Xml.XPath.XPathParser.ParsePredicate(AstNode qyInput)
   at MS.Internal.Xml.XPath.XPathParser.ParseStep(AstNode qyInput)
   at MS.Internal.Xml.XPath.XPathParser.ParseRelativeLocationPath(AstNode qyInput)
   at MS.Internal.Xml.XPath.XPathParser.ParseRelativeLocationPath(AstNode qyInput)
   at MS.Internal.Xml.XPath.XPathParser.ParseLocationPath(AstNode qyInput)
   at MS.Internal.Xml.XPath.XPathParser.ParsePathExpr(AstNode qyInput)
   at MS.Internal.Xml.XPath.XPathParser.ParseUnionExpr(AstNode qyInput)
   at MS.Internal.Xml.XPath.XPathParser.ParseUnaryExpr(AstNode qyInput)
   at MS.Internal.Xml.XPath.XPathParser.ParseMultiplicativeExpr(AstNode qyInput)
   at MS.Internal.Xml.XPath.XPathParser.ParseAdditiveExpr(AstNode qyInput)
   at MS.Internal.Xml.XPath.XPathParser.ParseRelationalExpr(AstNode qyInput)
   at MS.Internal.Xml.XPath.XPathParser.ParseEqualityExpr(AstNode qyInput)
   at MS.Internal.Xml.XPath.XPathParser.ParseAndExpr(AstNode qyInput)
   at MS.Internal.Xml.XPath.XPathParser.ParseOrExpr(AstNode qyInput)
   at MS.Internal.Xml.XPath.XPathParser.ParseXPathExpresion(String xpathExpresion)
   at MS.Internal.Xml.XPath.QueryBuilder.Build(String query, Boolean allowVar, Boolean allowKey)
   at MS.Internal.Xml.XPath.QueryBuilder.Build(String query, Boolean& needContext)
   at System.Xml.XPath.XPathExpression.Compile(String xpath, IXmlNamespaceResolver nsResolver)
   at System.Xml.XPath.XPathNavigator.Compile(String xpath)
   at PDFViewer.FormSaveAs.cb_action_Click(Object sender, EventArgs e)
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Kann einer von euch mir sagen welches Token hier ungültig ist (ich vermute mal das es das Zeichen à ist) ?

Phoenix 4. Jan 2012 10:19

AW: XPathException
 
Versuch mal:
Code:
companies/company[displayName=Monterey Holdings I Sàrl]

Cogito 5. Jan 2012 13:27

AW: XPathException
 
Der Kunde sagte mir gerade, dass sie in den XML Dateien nichts ändern können. Ausserdem wird diese XML Datei automatisiert erzeugt und auch noch in anderen Programmen weiterverwendet. Und nu?

Cogito 9. Jan 2012 08:57

AW: XPathException
 
Sagt mal, es müsste doch meines Erachtens eine Funktion oder API oder sonstwas geben, die einen String in einen gültigen XPath Ausdruck umwandelt. Ansonsten hätten doch alle Franzosen oder Chinesen Probleme. Kennt einer von euch so eine Funktion?

himitsu 9. Jan 2012 09:10

AW: XPathException
 
Ich vergeß immer wie die heißt, aber ja, gibt es.

Scheu mal beim HTML, wie dort diese Sonderzeichen kodiert werden. :angle2:

Cogito 9. Jan 2012 09:45

AW: XPathException
 
Zitat:

Zitat von himitsu (Beitrag 1144996)
Ich vergeß immer wie die heißt, aber ja, gibt es.

Scheu mal beim HTML, wie dort diese Sonderzeichen kodiert werden. :angle2:

Das Kodieren einzelner Zeichen nützt mir aber nicht viel, da ich unmöglich alle möglichen Zeichen umwandeln kann. Ich bräuchte also eine Funktion die einen string auf diese Zeichen abklopft und mir dann einen xpath gültigen String zurückliefert. Kannst du versuchen dich an den Namen der Funktion zu erinnern?

DeddyH 9. Jan 2012 09:51

AW: XPathException
 
In PHP gibt es htmlentities, vielleicht existiert eine Funktion mit ähnlichem Namen?

[edit] Oder hilft Dir vielleicht HTTPUtil.HTMLEscape weiter? [/edit]

[edit2] *Oops*, es geht ja gar nicht um Delphi :oops: [/edit2]

Phoenix 9. Jan 2012 10:01

AW: XPathException
 
HttpUtility.EncodeHtml() im System.Web assembly dürfte da helfen.
Du darfst das aber nicht über das komplette XML laufen lassen sondern nur über die XPath-Ausdrücke.


Alle Zeitangaben in WEZ +1. Es ist jetzt 13:06 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz