Sign In/My Account | View Cart  
advertisement

Article:
 Pull Parsing in C# and Java
Subject: XML to HTML
Date: 2003-01-22 08:17:59
From: CJ Varghese

I tried to use the code for C# in converting XML to HTML I get an error. On this line--> string url = args[0];
error = Additional information: Index was outside the bounds of the array.


it maybe something simple i'm forgetting.. also if you can tell me what would i chagne if i'm getting the xml from file rather than a URL.
Thank you,
cj


Previous Message Previous Message   Next Message Next Message


Titles Only Titles Only Newest First
  • XML to HTML
    2003-01-22 08:39:35 Niel Bornstein [Reply]

    I guess I should have made it clearer that the program takes as an argument the URL of the file to parse. The error you got indicates that there were no arguments passed to the Main method. To invoke the program to read the XML at the URL http://xmlhack.com/rss.php, you should enter the following on the command line: "RSSReader http://xmlhack.com/rss.php".


    As to your second question, to take the input from a file instead of an HTTP URL, you would need to change some of the code inside the try/catch block of the Main method. It would need to look something like this:


    string url = args[0];
    XmlTextWriter writer = new XmlTextWriter(Console.Out);
    writer.Formatting = Formatting.Indented;
    XmlTextReader reader = new XmlTextReader(url);
    reader.XmlResolver = null; // ignore the DTD
    reader.WhitespaceHandling = WhitespaceHandling.None;
    rssreader.RSSToHtml(reader, writer);


    Invoke the program, passing in the filename as the argument. This would also work for HTTP URLs without a web proxy, by the way, as the XmlTextReader knows how to read a file directly from an HTTP URL as well as a local filename.


Sponsored By: