Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

Get excited for the Samsung Galaxy S5! Find everything you need and discuss it in our Galaxy S5 Forum!

test: Reply
 
LinkBack Thread Tools
Old July 15th, 2013, 10:27 AM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Jul 2013
Posts: 2
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default can't transform xml+xsl(with exslt) to html

Hi guys, I am developing an app which loads a xml and a xsl and loads the resulting html, displaying it on the screen. It works perfectly when the xsl does not have exslt functions. However, when it does contain exslt functions, it doesn't work.

The code is rather small, so I'm posting it here:

Code:
public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        
        super.onCreate(savedInstanceState);
        WebView webview = new WebView(this);
        setContentView(webview);

        Source xmlSource = new StreamSource(this.getResources().openRawResource(R.raw.xml2));
        Source xsltSource = new StreamSource(this.getResources().openRawResource(R.raw.xsl2));
        
        TransformerFactory tFactory = TransformerFactory.newInstance();
        Transformer transformer = null;
        ByteArrayOutputStream output = null;
        StreamResult result;
        
        try 
        {
            transformer = tFactory.newTransformer(xsltSource);
            output = new ByteArrayOutputStream();
            result = new StreamResult(output);
            transformer.transform(xmlSource, result);
            
        } catch (TransformerException e) 
        {
            e.printStackTrace();
        }
        
        ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
        
        
        String html = new Scanner(input,"UTF-8").useDelimiter("\\A").next();
        
        webview.loadData(html, "text/html", "UTF-8");
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}
I have attached a zip file containing 5 files: xml,xsl, xml2,xsl2, logcat.
I get the errors with xml2 and xsl2.

Please help me, I've been trying to make it work for hours...I've tried many stuff, different codes...but it doesn't seem to have anything to do with my code.

Thank you for your time.
Attached Files
File Type: zip files.zip (3.2 KB, 3 views)

aforum is offline  
Last edited by aforum; July 15th, 2013 at 02:37 PM.
Reply With Quote
sponsored links
Old July 15th, 2013, 10:52 AM   #2 (permalink)
New Member
Thread Author (OP)
 
Join Date: Jul 2013
Posts: 2
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

I forgot to mention 2 things: I'm using the eclipse IDE, ADT bundle thing. In addition, I have tried an equivalent code in netbeans:

Code:
public class JavaApplication4 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws TransformerConfigurationException, TransformerException, FileNotFoundException {
       Source xmlSource = new StreamSource("xml2.xml");
       Source xsltSource = new StreamSource("xsl2.xsl");
       
       TransformerFactory tFactory = TransformerFactory.newInstance();
       Transformer transformer = tFactory.newTransformer(xsltSource);
       
       ByteArrayOutputStream output = new ByteArrayOutputStream();
       StreamResult result = new StreamResult(output);
       transformer.transform(xmlSource, result);
       
       ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
       String html = new Scanner(input,"UTF-8").useDelimiter("\\A").next();
       
       System.out.println(html);
    }
}
which, to my surprise, works for both xml and xsl.
aforum is offline  
Reply With Quote
Reply


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 03:03 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.