Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • yumin 51 posts 243 karma points
    Dec 25, 2012 @ 03:44
    yumin
    0

    XPathException:has an invalid token

    I want to get paging record  from .NET usercontrol. This is my code but I get exception 

    System.Xml.XPath.XPathException: 'descendant::node()[@id='1349']/child::node()[position() >= 0 and position() <= 5]' has an invalid token.

     

    string xPath="descendant::node()[@id='1349']/child::node()[position() >= 0 and position() <= 5]";

    List<Node> nodes = new List<Node>();

    XPathNavigator xPathNavigator = umbraco.content.Instance.XmlContent.CreateNavigator();
    XPathNodeIterator xPathNodeIterator = xPathNavigator.Select(xPath);
    Node node;
    while (xPathNodeIterator.MoveNext())
    {
    node = UmbracoHelper.GetNode(xPathNodeIterator.Current.Evaluate("string(@id)").ToString());
    if (node != null) { nodes.Add(node); }
    }

  • yumin 51 posts 243 karma points
    Dec 25, 2012 @ 03:49
    yumin
    0

    I created a test.xslt in .net , The strange thing is there is no error with the same code

    <?xml version="1.0" encoding="utf-8"?>

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

        xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"

    >

        <xsl:output method="xml" indent="yes"/>

        <xsl:template match="/">

          <xsl:value-of select="descendant::node()[@id='1349']/child::* [position() &gt;= 0 and position() &lt;= 5]"/>

        </xsl:template>

    </xsl:stylesheet>

     I can't figure out what is wrong in my code, any ideas!  Thanks in advace
  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Dec 26, 2012 @ 16:11
    Jan Skovgaard
    0

    Hi Yumin

    What version of Umbraco are you using?

    /Jan

  • yumin 51 posts 243 karma points
    Dec 27, 2012 @ 03:43
    yumin
    0

    hi Jan Skovqaard

    Umbraco.4.10.0

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Dec 27, 2012 @ 10:35
    Dennis Aaen
    0

    Hi Yumin,

    Try something like this, I haven'ttest it myself.

     

    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
        <xsl:output method="xml" indent="yes"/>
        <xsl:template match="/">
          <xsl:value-of select="$currentPage/descendant::*[@isDoc and @id='1349' ]/child::* [position() &gt;= 0 and position() &lt;= 5]"/>
        </xsl:template>
    </xsl:stylesheet>

    I hope this can helps you further.

    /Dennis

  • yumin 51 posts 243 karma points
    Dec 28, 2012 @ 06:19
    yumin
    100

    hi all,

    thanks very much,I have solved the problem

    xpath expression can not use &gt; and &lt; in .net, Otherwise will get a invalid token exception

    use > and < instead

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies