Parse XML from an online source - asp.net

I'm attempting to parse the xml located at view-source:http://www.parkrun.com.au/wp-content/themes/parkrun/xml/geo.xml. This is my first attempt at doing this type of thing so my knowledge is limited. I've parsed plenty of websites but not xml.
I've attempted the following code but keep getting an error:
Dim xdoc As New XmlDocument
xdoc.LoadXml("http://www.parkrun.com.au/wp-content/themes/parkrun/xml/geo.xml")
Error: {"Data at the root level is invalid. Line 1, position 1."}
What I'm attempting to do is parse the xml and then loop through the records to build an array based on each location and state (eg from below it would be ipswichqld, Queensland). For example below ipswichqld belongs to Queensland (r="4" joins with id="4").
Any help on this would be really appreciated, thanks in advance.

Instead of LoadXml() method, you should've used XmlDocument.Load() method to load XML from local or online source file :
Dim xdoc As New XmlDocument
xdoc.Load("http://www.parkrun.com.au/wp-content/themes/parkrun/xml/geo.xml")
Unfortunately, particular website you're trying to load XML from doesn't allow this operation (not even if you open that XML URL from browser). I got this exception when trying above code :
WebException
The remote server returned an error: (403) Forbidden.

Related

ASP.NET Webforms Nreco PDF Generator - Exit with code 1, due to unknown error

I have a web-application built in ASP.NET Webforms VB.NET. I am creating a method for exporting the pages via urls utilising the WKHTMLTOPDF and NReco PDF Generator libraries.
During my local development, everything seems to work ok, other than the odd "Process is already in use" when i have rebooted my PC and not even performed anything prior.
When I have uploaded the site to our server, the PDF library seems to never work and I am faced with a not so obvious error. When I attempt to export any page to anything, or even text to a pdf, I get this within our logs:
Inner Exception Type: NReco.PdfGenerator.WkHtmlToPdfException
Inner Exception: Exit with code 1, due to unknown error. (exit code: 1)
Inner Source: NReco.PdfGenerator
Inner Stack Trace:
at NReco.PdfGenerator.HtmlToPdfConverter.CheckExitCode(Int32 exitCode, String lastErrLine, Boolean outputNotEmpty)
at NReco.PdfGenerator.HtmlToPdfConverter.InvokeWkHtmlToPdf(PdfSettings pdfSettings, String inputContent, Stream outputStream)
at NReco.PdfGenerator.HtmlToPdfConverter.GeneratePdfInternal(WkHtmlInput[] htmlFiles, String inputContent, String coverHtml, String outputPdfFilePath, Stream outputStream)
Exception Type: System.Exception
Exception: Cannot generate PDF: Exit with code 1, due to unknown error. (exit code: 1)
Source: Exporting
Stack Trace:
at NReco.PdfGenerator.HtmlToPdfConverter.GeneratePdfInternal(WkHtmlInput[] htmlFiles, String inputContent, String coverHtml, String outputPdfFilePath, Stream outputStream)
at NReco.PdfGenerator.HtmlToPdfConverter.GeneratePdf(String htmlContent, String coverHtml, String outputPdfFilePath)
at PROJECT.Export.DownloadFiles(List`1 list) in C:\Users\NAME\source\repos\PROJECT\Export.aspx.vb:line 252.
I have ensured the project contains all the relevant files, I have even installed WKHTMLTOPDF on both server and development machine. Utilising the CMD I can generate ANY PDF but within my application, it seems to always fail on our live production server.
My code for generating the PDF is quite simplistic:
If check = True Then
Try
'Generate PDF
'htmlToPdf.GeneratePdfFromFile(exp.URL, Nothing, "..\" & pathURL)
htmlToPdf.GeneratePdf("<h3> TEST PDF </h3> ", Nothing, "..\" & pathURL)
'Set download
download = True
'Catch exception, log it
Catch ex As Exception
ExceptionUtility.LogException(ex, "Exporting")
End Try
End If
Can anyone offer any insight as to how I can overcome this? I spent all day yesterday searching through forums and not coming to a solution!
Any help is highly appreciated.
Exit code 1 means that wkhtmltopdf was unable to render your HTML input for some reason.
To get more details (full wkhtmltopdf's console log output) you may handle LogReceived event.
PdfGenerator executes wkhtmltopdf with System.Diagnostics.Process API, so it should work exactly like if you run it (on the same server) in the command line. Differences may occur if this is ASP.NET app hosted in IIS, and in some cases app pool may be configured to use rather restrictive credentials.

You have requested a non-existent service "projet_rating.manager.rating"

I am getting the following error message: "You have requested a non-existent service "projet_rating.manager.rating" - Help please.
Two possibilities come to mind:
1) Somewhere in your application you have a controller that includes $this->container->get("projet_rating.manager.rating")
2) Somewhere in a config file you create a service that includes as an argument %"projet_rating.manager.rating"%.
If you're using an IDE that allows searching multiple files for a string, try searching for "projet_rating.manager.rating" in ...src/ or ...app/config

Reading this site Rss

I'm trying read this site's Rss using following code:
WebRequest request = WebRequest.Create("http://alef.ir/rssew.skj1zjyss1rhx2k4m..9ji9b7.jbgjzqg.xml")
Stream stream = request.GetResponse().GetResponseStream();
XmlDocument rss = new XmlDocument();
rss.Load(stream);
XmlNodeList items = rss.SelectNodes("rss/channel/item");
.
.
.
But VS shows this problem:
The remote server returned an error: (403) Forbidden.
It may have been temporary. Any time you have a problem getting a remote document programmatically you should go to the url in the browser and check if you can get it outside VS. I visited the url just now and had no problem getting the feed in my browser. You should not have problems to get that feed with VS now.

Reading XML file from Client machine - getting - Access to the path is denied

I'm currently trying to READ XML file from the client machine where the user can open from any location (there is no specific location). However, i browse to the folder and select the xml file and when it execute this line (below) it throw an error complaining about access to the path is denied any idea how should i approach?
error: System.UnauthorizedAccessException: Access to the path is Denied
Dim reader As New XmlTextReader(System.IO.Path.GetFullPath(File1.PostedFile.FileName))
Dim m_xmlr As XmlTextReader
'Create the XML Reader
m_xmlr = New XmlTextReader(System.IO.Path.GetFullPath(File1.PostedFile.FileName.ToString()))
'Disable whitespace so that you don't have to read over whitespaces
m_xmlr.WhitespaceHandling = WhitespaceHandling.None
'read the xml declaration and advance to family tag
m_xmlr.Read() **<<<<<ERROR**
'read the family tag
m_xmlr.Read()
'Load the Loop
While Not m_xmlr.EOF
..............
.............
Your code is running on the server. You can't just read from the client's local drive like that. You should use the InputStream of the file to get the data. For example:
Dim m_xmlr As XmlReader = XmlReader.Create(File1.PostedFile.InputStream)

Reading a remote URL in Domino LotusScript

I have a remote RSS feed which has to be transformed into Notes documents using LotusScript.
I've looked through the documentation, but I can't find how to open a remote URL in order to retrieve its contents. In other words, some sort of wget- or curl-like functionality. Can anyone shed some light on how to do this? Using Java is not an option.
Thanks.
Check out the NotesDOMParser class - available in LotusScript - which lets you (indirectly) pull XML from a remote URL and process in a an XML DOM object.
You can pull the XML into a string using the MSXMLHTTP COM object, then use NotesStream to send the XML to the NotesDOMParser.
I have not tested, but the code would look something like this:
...
Set objXML = CreateObject("Microsoft.XMLHTTP")
objXML.open "GET", sURL, False, "", ""
objXML.send("")
sXMLAsText = Trim$(objXML.responseText)
Set inputStream = session.CreateStream
inputStream.Open (sXMLAsText)
Set domParser=session.CreateDOMParser(inputStream, outputStream)
domParser.Process
...
Documentation: http://publib.boulder.ibm.com/infocenter/domhelp/v8r0/index.jsp?topic=/com.ibm.designer.domino.main.doc/H_NOTESDOMPARSER_CLASS.html
You can't open a remote URL (whether it's HTTP or some other protocol) using native Lotusscript: the object library simply doesn't support it. If you're running on a Windows server, you should be able to use the MS XMLHttp DLLs to get a handle on your remote file via a URL, as specified by the previous answer. (Alternatively, this link specifies how to parse and open a UNC path with Lotusscript—again, Windows only).
All that said, if I understand you correctly, you're not using HTTP to access the remote file at all. If the RSS file is just on a simple path, why can't you open the file for parsing in the normal way with Lotusscript?

Resources