Trouble getting file naming syntax correct

View: New views
5 Messages — Rating Filter:   Alert me  

Trouble getting file naming syntax correct

by Bryan Schnabel :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

I've built a little Java application that let's the user browse to an XML file, select it, then the XML file is transformed via a static XSL file. Everything has been working fine, until I needed to use XSLT 2.0. So I had to switch to Saxon 9, instead of the *standard* TransformerFactory XSLT processor. (Assuming my classpath is all good) It seems like Saxon does not care for my file naming syntax. Here's the portion that has the trouble:

--snip --
  if(result == JFileChooser.APPROVE_OPTION) {

    textXRTrip0.setText(jfilechooser.getSelectedFile().getPath());
    String xml_Input_File = (jfilechooser.getSelectedFile().getPath());
    textXRTrip1.setText(jfilechooser.getSelectedFile().getPath()+".xf");

      File InputFile = new File(xml_Input_File);
      File xfXSLTfile = new File("xml2xf.xsl");
      // just added this extra step 'x_i' to try to correct the
      // 'java.net.URISyntaxException:' - it seemed to do no harm, nor help
      File x_i = new File(InputFile.toURI());
      Source xmlIn = new StreamSource(x_i);
      Source xfRoundTripXSL = new StreamSource(xfXSLTfile);

      System.setProperty("javax.xml.transform.TransformerFactory",
       "net.sf.saxon.TransformerFactoryImpl");

      TransformerFactory transFact =
      TransformerFactory.newInstance()

      try { 
            Transformer trans = transFact.newTransformer(xfRoundTripXSL);
            trans.transform(xmlIn, new StreamResult(x_i + ".xf"));
          }
   catch(Exception ioe) { 
    System.err.println("Could not transform; malformed? ..." + x_i);
          }

      }
  }
--/snip --

I ran it in verbose mode, and got some telling errors (I'm just not experienced enough to know exactly what they are telling me). It clearly finds the files (making reference to actual elements in the source, "processing /rooty/p[1]" and actual code in the XSLT, "  at xsl:apply-templates (file:/C:/presentations/D-Europe-2009/presentation-and-demo/newD-XF-rt/xml2xf.xsl#11)"):

--snip --
Error at xsl:copy on line 10 of xml2xf.xsl:
  java.net.URISyntaxException: Illegal character in opaque part at index 2: C:\D
ocuments and
  Settings\JG\Desktop\try\my.xml.xf

[Loaded net.sf.saxon.trace.ContextStackIterator from file:/C:/presentations/D
-Europe-2009/presentation-and-demo/newD-XF-rt/saxon9.jar]
[Loaded net.sf.saxon.trace.ContextStackFrame from file:/C:/presentations/D-Eu
rope-2009/presentation-and-demo/newD-XF-rt/saxon9.jar]
[Loaded net.sf.saxon.trace.ContextStackFrame$ApplyTemplates from file:/C:/presen
tations/D-Europe-2009/presentation-and-demo/newD-XF-rt/saxon9.jar]

  at xsl:apply-templates (file:/C:/presentations/D-Europe-2009/presentation-a
nd-demo/newD-XF-rt/xml2xf.xsl#11)

[Loaded net.sf.saxon.tinytree.PrecedingSiblingEnumeration from file:/C:/presenta
tions/D-Europe-2009/presentation-and-demo/newD-XF-rt/saxon9.jar]

     processing /rooty/p[1]

[Loaded net.sf.saxon.trace.ContextStackFrame$BuiltInTemplateRule from file:/C:/p
resentations/D-Europe-2009/presentation-and-demo/newD-XF-rt/saxon9.jar]

  in built-in template rule

[Loaded net.sf.saxon.trace.ContextStackFrame$CallingApplication from file:/C:/pr
esentations/D-Europe-2009/presentation-and-demo/newD-XF-rt/saxon9.jar]

Could not transform; malformed? ...C:\Documents and Settings\JG\Desktop\try\
my.xml
--/snip --

I'll skip the plea of "couldn't find it in the FAQ" and "forgive me for being a newby," and just ask if anyone can tell what causes this misfire.

Thanks,

-jg-

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@...
https://lists.sourceforge.net/lists/listinfo/saxon-help 

Re: Trouble getting file naming syntax correct

by Martin Honnen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Bryan Schnabel wrote:

> I ran it in verbose mode, and got some telling errors (I'm just not
> experienced enough to know exactly what they are telling me). It clearly
> finds the files (making reference to actual elements in the source,
> "processing /rooty/p[1]" and actual code in the XSLT, "  at
> xsl:apply-templates
> (file:/C:/presentations/D-Europe-2009/presentation-and-demo/newD-XF-rt/xml2xf.xsl#11)"):
>
> --snip --
> Error at xsl:copy on line 10 of xml2xf.xsl:
>   java.net.URISyntaxException: Illegal character in opaque part at index
> 2: C:\D
> ocuments and
>   Settings\JG\Desktop\try\my.xml.xf

URIs use the slash '/' and not the backslash '\'. So instead of e.g.
C:\Documents and Settings
you need e.g.
file:///C:/Documents%20and%20Settings

How exactly do the lines of the stylesheet look that cause the error
(i.e. line 10 and some lines before and after that)?

--

        Martin Honnen
        http://msmvps.com/blogs/martin_honnen/

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@...
https://lists.sourceforge.net/lists/listinfo/saxon-help 

Re: Trouble getting file naming syntax correct

by Bryan Schnabel :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Martin,

Saxon likes the stylesheet just fine if I just run it from the command line.

I think the error falsely hints at a stylesheet error, and I also went down that path. But I'm nearly 100% sure it is not a stylesheet error. In fact, when I first started getting this error, I replaced my fancy stylesheet with one that does nothing more than an identity transform. And I still got the error. So here's the exact template that the error message calls out (don't laugh):

<xsl:template match="node()|@*">
 <xsl:copy> <!-- and this is line 10 -->
  <xsl:apply-templates select="@*|node()"/>
 </xsl:copy>
</xsl:template>

I thought maybe the answer was along the lines of changing:

File x_i = new File(InputFile.toURI());

to

File x_i = new File(InputFile.toURI().toURL());

(in hopes that this would solve what I perceive to be Saxon's dislike the the windows-y synax - fixing it to the correct file: and forward slash syntax) - But the .toURL() is not cool with Java, I think. I suppose I could do some manual string fixes, but I hoped for a more universal solution (i.e., OS agnostic), if this is even the problem.

Thanks,

Bryan

On Wed, Nov 11, 2009 at 10:58 AM, Martin Honnen <Martin.Honnen@...> wrote:
Bryan Schnabel wrote:

> I ran it in verbose mode, and got some telling errors (I'm just not
> experienced enough to know exactly what they are telling me). It clearly
> finds the files (making reference to actual elements in the source,
> "processing /rooty/p[1]" and actual code in the XSLT, "  at
> xsl:apply-templates
> (file:/C:/presentations/D-Europe-2009/presentation-and-demo/newD-XF-rt/xml2xf.xsl#11)"):
>
> --snip --
> Error at xsl:copy on line 10 of xml2xf.xsl:
>   java.net.URISyntaxException: Illegal character in opaque part at index
> 2: C:\D
> ocuments and
>   Settings\JG\Desktop\try\my.xml.xf

URIs use the slash '/' and not the backslash '\'. So instead of e.g.
C:\Documents and Settings
you need e.g.
file:///C:/Documents%20and%20Settings

How exactly do the lines of the stylesheet look that cause the error
(i.e. line 10 and some lines before and after that)?

--

       Martin Honnen
       http://msmvps.com/blogs/martin_honnen/

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@...

https://lists.sourceforge.net/lists/listinfo/saxon-help


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@...
https://lists.sourceforge.net/lists/listinfo/saxon-help 

Re: Trouble getting file naming syntax correct

by Michael Kay :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The rejected URI (or rather, non-URI)  is
 
C:\Documents and Settings\JG\Desktop\try\my.xml.xf
 
and since you are constructing the URI for the result file by adding ".xf" to something, my guess is that its the result URI that it's complaining about.
 
Try something like
 
new StreamResult(x_i .toURI().toString() + ".xf")
 
 
 
 2009 18:39
To: saxon-help@...
Subject: [saxon] Trouble getting file naming syntax correct

Hello,

I've built a little Java application that let's the user browse to an XML file, select it, then the XML file is transformed via a static XSL file. Everything has been working fine, until I needed to use XSLT 2.0. So I had to switch to Saxon 9, instead of the *standard* TransformerFactory XSLT processor. (Assuming my classpath is all good) It seems like Saxon does not care for my file naming syntax. Here's the portion that has the trouble:

--snip --
  if(result == JFileChooser.APPROVE_OPTION) {

    textXRTrip0.setText(jfilechooser.getSelectedFile().getPath());
    String xml_Input_File = (jfilechooser.getSelectedFile().getPath());
    textXRTrip1.setText(jfilechooser.getSelectedFile().getPath()+".xf");

      File InputFile = new File(xml_Input_File);
      File xfXSLTfile = new File("xml2xf.xsl");
      // just added this extra step 'x_i' to try to correct the
      // 'java.net.URISyntaxException:' - it seemed to do no harm, nor help
      File x_i = new File(InputFile.toURI());
      Source xmlIn = new StreamSource(x_i);
      Source xfRoundTripXSL = new StreamSource(xfXSLTfile);

      System.setProperty("javax.xml.transform.TransformerFactory",
       "net.sf.saxon.TransformerFactoryImpl");

      TransformerFactory transFact =
      TransformerFactory.newInstance()

      try { 
            Transformer trans = transFact.newTransformer(xfRoundTripXSL);
            trans.transform(xmlIn, new StreamResult(x_i + ".xf"));
          }
   catch(Exception ioe) { 
    System.err.println("Could not transform; malformed? ..." + x_i);
          }

      }
  }
--/snip --

I ran it in verbose mode, and got some telling errors (I'm just not experienced enough to know exactly what they are telling me). It clearly finds the files (making reference to actual elements in the source, "processing /rooty/p[1]" and actual code in the XSLT, "  at xsl:apply-templates (file:/C:/presentations/D-Europe-2009/presentation-and-demo/newD-XF-rt/xml2xf.xsl#11)"):

--snip --
Error at xsl:copy on line 10 of xml2xf.xsl:
  java.net.URISyntaxException: Illegal character in opaque part at index 2: C:\D
ocuments and
  Settings\JG\Desktop\try\my.xml.xf

[Loaded net.sf.saxon.trace.ContextStackIterator from file:/C:/presentations/D
-Europe-2009/presentation-and-demo/newD-XF-rt/saxon9.jar]
[Loaded net.sf.saxon.trace.ContextStackFrame from file:/C:/presentations/D-Eu
rope-2009/presentation-and-demo/newD-XF-rt/saxon9.jar]
[Loaded net.sf.saxon.trace.ContextStackFrame$ApplyTemplates from file:/C:/presen
tations/D-Europe-2009/presentation-and-demo/newD-XF-rt/saxon9.jar]

  at xsl:apply-templates (file:/C:/presentations/D-Europe-2009/presentation-a
nd-demo/newD-XF-rt/xml2xf.xsl#11)

[Loaded net.sf.saxon.tinytree.PrecedingSiblingEnumeration from file:/C:/presenta
tions/D-Europe-2009/presentation-and-demo/newD-XF-rt/saxon9.jar]

     processing /rooty/p[1]

[Loaded net.sf.saxon.trace.ContextStackFrame$BuiltInTemplateRule from file:/C:/p
resentations/D-Europe-2009/presentation-and-demo/newD-XF-rt/saxon9.jar]

  in built-in template rule

[Loaded net.sf.saxon.trace.ContextStackFrame$CallingApplication from file:/C:/pr
esentations/D-Europe-2009/presentation-and-demo/newD-XF-rt/saxon9.jar]

Could not transform; malformed? ...C:\Documents and Settings\JG\Desktop\try\
my.xml
--/snip --

I'll skip the plea of "couldn't find it in the FAQ" and "forgive me for being a newby," and just ask if anyone can tell what causes this misfire.

Thanks,

-jg-

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@...
https://lists.sourceforge.net/lists/listinfo/saxon-help 

Re: Trouble getting file naming syntax correct

by Bryan Schnabel :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Michael,

You probably get tired of hearing this, but I'll say it anyway. This worked like a charm. You are one of the wonders of the XML/Java world!

Thank you for this, and for your enduring support for our coding community all these years.

- Bryan

On Wed, Nov 11, 2009 at 3:10 PM, Michael Kay <mike@...> wrote:
The rejected URI (or rather, non-URI)  is
 
C:\Documents and Settings\JG\Desktop\try\my.xml.xf
 
and since you are constructing the URI for the result file by adding ".xf" to something, my guess is that its the result URI that it's complaining about.
 
Try something like
 
new StreamResult(x_i .toURI().toString() + ".xf")
 
 
 
 2009 18:39
To: saxon-help@...
Subject: [saxon] Trouble getting file naming syntax correct

Hello,

I've built a little Java application that let's the user browse to an XML file, select it, then the XML file is transformed via a static XSL file. Everything has been working fine, until I needed to use XSLT 2.0. So I had to switch to Saxon 9, instead of the *standard* TransformerFactory XSLT processor. (Assuming my classpath is all good) It seems like Saxon does not care for my file naming syntax. Here's the portion that has the trouble:

--snip --
  if(result == JFileChooser.APPROVE_OPTION) {

    textXRTrip0.setText(jfilechooser.getSelectedFile().getPath());
    String xml_Input_File = (jfilechooser.getSelectedFile().getPath());
    textXRTrip1.setText(jfilechooser.getSelectedFile().getPath()+".xf");

      File InputFile = new File(xml_Input_File);
      File xfXSLTfile = new File("xml2xf.xsl");
      // just added this extra step 'x_i' to try to correct the
      // 'java.net.URISyntaxException:' - it seemed to do no harm, nor help
      File x_i = new File(InputFile.toURI());
      Source xmlIn = new StreamSource(x_i);
      Source xfRoundTripXSL = new StreamSource(xfXSLTfile);

      System.setProperty("javax.xml.transform.TransformerFactory",
       "net.sf.saxon.TransformerFactoryImpl");

      TransformerFactory transFact =
      TransformerFactory.newInstance()

      try { 
            Transformer trans = transFact.newTransformer(xfRoundTripXSL);
            trans.transform(xmlIn, new StreamResult(x_i + ".xf"));
          }
   catch(Exception ioe) { 
    System.err.println("Could not transform; malformed? ..." + x_i);
          }

      }
  }
--/snip --

I ran it in verbose mode, and got some telling errors (I'm just not experienced enough to know exactly what they are telling me). It clearly finds the files (making reference to actual elements in the source, "processing /rooty/p[1]" and actual code in the XSLT, "  at xsl:apply-templates (file:/C:/presentations/D-Europe-2009/presentation-and-demo/newD-XF-rt/xml2xf.xsl#11)"):

--snip --
Error at xsl:copy on line 10 of xml2xf.xsl:
  java.net.URISyntaxException: Illegal character in opaque part at index 2: C:\D
ocuments and
  Settings\JG\Desktop\try\my.xml.xf

[Loaded net.sf.saxon.trace.ContextStackIterator from file:/C:/presentations/D
-Europe-2009/presentation-and-demo/newD-XF-rt/saxon9.jar]
[Loaded net.sf.saxon.trace.ContextStackFrame from file:/C:/presentations/D-Eu
rope-2009/presentation-and-demo/newD-XF-rt/saxon9.jar]
[Loaded net.sf.saxon.trace.ContextStackFrame$ApplyTemplates from file:/C:/presen
tations/D-Europe-2009/presentation-and-demo/newD-XF-rt/saxon9.jar]

  at xsl:apply-templates (file:/C:/presentations/D-Europe-2009/presentation-a
nd-demo/newD-XF-rt/xml2xf.xsl#11)

[Loaded net.sf.saxon.tinytree.PrecedingSiblingEnumeration from file:/C:/presenta
tions/D-Europe-2009/presentation-and-demo/newD-XF-rt/saxon9.jar]

     processing /rooty/p[1]

[Loaded net.sf.saxon.trace.ContextStackFrame$BuiltInTemplateRule from file:/C:/p
resentations/D-Europe-2009/presentation-and-demo/newD-XF-rt/saxon9.jar]

  in built-in template rule

[Loaded net.sf.saxon.trace.ContextStackFrame$CallingApplication from file:/C:/pr
esentations/D-Europe-2009/presentation-and-demo/newD-XF-rt/saxon9.jar]

Could not transform; malformed? ...C:\Documents and Settings\JG\Desktop\try\
my.xml
--/snip --

I'll skip the plea of "couldn't find it in the FAQ" and "forgive me for being a newby," and just ask if anyone can tell what causes this misfire.

Thanks,

-jg-

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@...

https://lists.sourceforge.net/lists/listinfo/saxon-help


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@...
https://lists.sourceforge.net/lists/listinfo/saxon-help