locked
Illegal characters in path RRS feed

  • Question

  • I am getting this error trying to transform some XML:

    XElement CategoryDetail = new XElement("root",
                  from categorylist in ps.reporttrees
                  where categorylist.category == categoryid
                  select new XElement("tree",
                    new XAttribute("name", categorylist.name.Trim()),
                    new XAttribute("menuid", categorylist.menuid),
                    new XAttribute("parentid", categorylist.parentid),
                    new XAttribute("category", categorylist.category)
                  )
              );
          XslCompiledTransform outXslTransform;
          outXslTransform = new XslCompiledTransform();
          // Create the writer.       
          XmlWriter writer = XmlWriter.Create(Console.Out, outXslTransform.OutputSettings);
    
          // Create a resolver and set the credentials to use.
          XmlSecureResolver resolver = new XmlSecureResolver(new XmlUrlResolver(), "http://localhost/ufdportal/");
          resolver.Credentials = CredentialCache.DefaultCredentials;
          outXslTransform.Load("http://localhost/ufdportal/sqlxmltree.xsl", null, resolver);
          outXslTransform.Transform(CategoryDetail.ToString(), writer);
    

    The error come out of the last line of code.

     

    Thanks

    Tuesday, May 10, 2011 9:52 PM

Answers

  • When you pass a string as first argument to the Transform method, it's supposed to be an URI, not the content of your xml. You can create an XmlReader onto a StringReader:
    outXslTransform.Transform(XmlReader.Create(new StringReader( CategoryDetail.ToString())), writer);
    
    • Proposed as answer by Tim Copenhaver Wednesday, May 11, 2011 2:14 PM
    • Marked as answer by markgoldin Wednesday, May 11, 2011 3:03 PM
    Wednesday, May 11, 2011 10:30 AM
  • Your sample doesn't contain any tree element without a parentid attribute. The for-each matches nothing.
    • Marked as answer by markgoldin Saturday, May 21, 2011 11:27 AM
    Monday, May 16, 2011 4:07 PM

All replies

  • Can we see the XSL too? That might help.
    Tuesday, May 10, 2011 9:55 PM
  • <?xml version="1.0"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="xml" indent="yes"/>
    
    <xsl:template match="/">
      <xsl:for-each select="root/tree[not(@parentid)]">
       <xsl:apply-templates select=".">
        </xsl:apply-templates>
      </xsl:for-each>
    </xsl:template>
    
    <xsl:template match="tree">
     <xsl:variable name="ID" select="@menuid"/>
      <menu>
      <xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>
      <xsl:attribute name="menuid"><xsl:value-of select="@menuid"/></xsl:attribute>
      <xsl:attribute name="parentid"><xsl:value-of select="@parentid"/></xsl:attribute>
      <xsl:attribute name="link"><xsl:value-of select="@link"/></xsl:attribute>
      <xsl:attribute name="line_id"><xsl:value-of select="@line_id"/></xsl:attribute>
      <xsl:attribute name="salesrepid"><xsl:value-of select="@salesrepid"/></xsl:attribute>
      <xsl:attribute name="category"><xsl:value-of select="@category"/></xsl:attribute>
      <xsl:attribute name="folder"><xsl:value-of select="@folder"/></xsl:attribute>
      <xsl:apply-templates select="//tree[@parentid=$ID]">
      </xsl:apply-templates>
      </menu>
    </xsl:template>
    </xsl:stylesheet>
    
    
    Tuesday, May 10, 2011 10:03 PM
  • When you pass a string as first argument to the Transform method, it's supposed to be an URI, not the content of your xml. You can create an XmlReader onto a StringReader:
    outXslTransform.Transform(XmlReader.Create(new StringReader( CategoryDetail.ToString())), writer);
    
    • Proposed as answer by Tim Copenhaver Wednesday, May 11, 2011 2:14 PM
    • Marked as answer by markgoldin Wednesday, May 11, 2011 3:03 PM
    Wednesday, May 11, 2011 10:30 AM
  • Well, I am not getting an error anymore nor I am getting transformed XML. Here is my source XML:

    <root>
     <tree name="Consunmer Products Division" menuid="2" parentid="1" category="1" />
     <tree name="Operations" menuid="3" parentid="2" category="1" />
     <tree name="Look Up Job" menuid="4" parentid="3" category="1" />
     <tree name="Daily Scanning Summary" menuid="12" parentid="3" category="1" />
     <tree name="Sewing Lines" menuid="13" parentid="12" category="1" />
     <tree name="Quilting Lines" menuid="14" parentid="12" category="1" />
     <tree name="Wagons" menuid="15" parentid="12" category="1" />
     <tree name="Cutting/Sewing" menuid="19" parentid="12" category="1" />
     <tree name="Time Tracking" menuid="56" parentid="3" category="1" />
     <tree name="Time Tracking Statistics" menuid="58" parentid="3" category="1" />
     <tree name="Attendance Report" menuid="63" parentid="3" category="1" />
     <tree name="Gaylords" menuid="70" parentid="12" category="1" />
     <tree name="Time Tracking Statistics" menuid="82" parentid="19" category="1" />
     <tree name="Golf Lines Statistics" menuid="85" parentid="3" category="1" />
     <tree name="Time Tracking Data Maintainance" menuid="86" parentid="3" category="1" />
     <tree name="Time Tracking Data Maintainance" menuid="90" parentid="19" category="1" />
     <tree name="Cutting/Sewing Statistics" menuid="87" parentid="3" category="1" />
     <tree name="Golf Departments Statistics" menuid="88" parentid="3" category="1" />
    </root>
    
    

    and here is xslt file:

    <?xml version="1.0"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="xml" indent="yes"/>
    
    <xsl:template match="/">
      <xsl:for-each select="root/tree[not(@parentid)]">
       <xsl:apply-templates select=".">
        </xsl:apply-templates>
      </xsl:for-each>
    </xsl:template>
    
    <xsl:template match="tree">
     <xsl:variable name="ID" select="@menuid"/>
      <menu>
      <xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>
      <xsl:attribute name="menuid"><xsl:value-of select="@menuid"/></xsl:attribute>
      <xsl:attribute name="parentid"><xsl:value-of select="@parentid"/></xsl:attribute>
      <xsl:attribute name="category"><xsl:value-of select="@category"/></xsl:attribute>
      <xsl:apply-templates select="//tree[@parentid=$ID]">
      </xsl:apply-templates>
      </menu>
    </xsl:template>
    </xsl:stylesheet>
    
    

    all I get is <?xml version="1.0" encoding="utf-16"?>

    Strangely the xslt file worked with other programming environment.

     

    Wednesday, May 11, 2011 3:55 PM
  • Your sample doesn't contain any tree element without a parentid attribute. The for-each matches nothing.
    • Marked as answer by markgoldin Saturday, May 21, 2011 11:27 AM
    Monday, May 16, 2011 4:07 PM