Display xml data into html page - html

i want to get data from xml file and display it into html.
Which is the best and easiest method to display xml data in html page ?

You should use XSLT for this job. XSLT is a language that is designed to transform documents from xml to xml. This is very usefull, because xhtml is an xml language. That means that you can convert xml to xhtml using XSLT.
XSLT can be used both serverside and clientside, but beware of the clientside solution. Some browers does not support it, and some only supports older versions wihch might lead to different results.
You can check out this tutorial: http://www.w3schools.com/xsl/

<?php
$xml = $your_xml_string;
try { //try to make it formated. DOMDocument class must be available.
$doc = new DOMDocument();
$doc->loadXML($xml);
$doc->formatOutput = true;
$xml = $doc->saveXML();
} catch (Exception $exc) { }
// parese as html
echo htmlspecialchars($xml);
?>

I would use JQuery. You can easily parse XML files and display the content where you wish.
Have a look here > jQuery.parseXML
and here > Example

Related

how to convert string into html and loop through it in windows phone 8

I am using the following code
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
string site = "http://www.nokia.com
webBrowserControl.Navigate(new Uri(site, UriKind.Absolute));
webBrowserControl.LoadCompleted += webBrowserControl_LoadCompleted;
});
private void webBrowserControl_LoadCompleted(object sender, NavigationEventArgs e)
{
string s = webBrowserControl.SaveToString();
}
How do I loop through this result string to find out elements like s and all
<div class="result-wrapper">
Tried to convert this string to XMLDocument but getting the error.
Please help me... thanks
You should not use XML document parser to pase html, because html schema is different than Html. you can use Agility Pack to parse html below is link on how you can use agility Pak
HTML Agility Pack - Windows Phone 8
Hope this helps.
It will throw you an exception when it is not a perfect XML document. It should have proper opening and closing tag. Check your html document with some online XML Validator and then proceed with that.
If you are going to parse only few tags, then identify the substring from your html document using "string.IndexOf()" and use that substring to load your XML Document.
Else, you have to do it manually or by using HTML Agility pack. But Html Agility pack needs some libraries from Silverlight 4.0 which is not recommended by microcoft.
So, doing manually is my choice.

Is it possible to embed a HTML into a PDF?

I like to embed a HTML site into a PDF document. Are there any libraries or PDF creator that make that possible?
Update:
I am not looking for ways to convert a HTML to PDF. I actually want to use the HMTL as it is inside the PDF. So I am looking for something like iframe for PDF.
There are a few out there, depends if you need to build using PHP or another language. I have used MPDF before: http://www.mpdf1.com/mpdf/
Yes, its possible using xmlworker5.4.1.jar. The XML worker object allows you to embed html in your document. xmlString object below is your HTML content as HTMLWorker is deprecated so use XMLWorker only.
XMLWorkerHelper worker = XMLWorkerHelper.getInstance();
String currentLine = "";
StringBuffer xmlString = new StringBuffer();
xmlString.append("<html><body>");
String str = htmlPages[i];
xmlString.append(htmlPages[i]);
xmlString.append("</body></html>");
worker.parseXHtml(pdfWriter, pdfDocument, new StringReader(xmlString.toString()));
Inorder to incorporate fonts mentioned in font face tag u need to register fonts using
FontFanctory.redisterDirectory("path of font files");
because itext doesnt scan system for fonts. u need to register it yourself this way

Scala XML parsing with real-world HTML (with unmatched tag)

My application is trying to embed an html document into an XML document.
val xml =
<document>
<id> { getId } </id>
<content>
{ getContent }
</content>
</document>
getId is a simple function to return a new sequence number.
The issue is on getContent:
def getContent = {
val wrapped = "<wrap>"+article.content+"</wrap>"
XML.loadString(wrapped).child
}
As you may see, article.content return a String that stored the real-world HTML document.
The Scala.xml.XML.loadString function would parse it into XML and return a list of child and embeded into the xml val correctly.
However, this is working when only the html is valid, e.g. <body>Hello world</body>
In some of the article, it may appear: <body><strong>Hello world</body>
which lacking a closing tag of <strong> elem. (Yes, I can't just blame the user!)
In this case, it will throw an exception on this parsing and stop the application.
Is there any way I can either bypass the validation or simply embed the HTML as string within the XML document without parsing?
Please shed some light on this situation. Any suggestions are welcomed.
Both JSoup and TagSoup (amongst others) are suitable for passing HTML that isn't also well-formatted XML.
You'll have to decide which is best for your own use-case.

NSXMLDocumentTidyHTML doesn't tidy some XHTML validation errors

I want to grab text from a list of web pages. I've done a bit of experimenting and found that the best way for my needs is via WebKit.
Once the source of the page has been grabbed, I want to strip out all the HTML tags, by using the technique in this comment.
Here's my code:
- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame {
if(frame == [sender mainFrame]) {
NSString *content = [[[[sender mainFrame] dataSource] representation] documentSource];
NSXMLDocument *theDocument = [[NSXMLDocument alloc] initWithXMLString:content options:NSXMLDocumentTidyHTML error:&theError];
NSString *theXSLTString = #"<?xml version='1.0' encoding='utf-8'?>\n<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xmlns:xhtml='http://www.w3.org/1999/xhtml'>\n<xsl:output method='text'/>\n<xsl:template match='xhtml:head'></xsl:template>\n<xsl:template match='xhtml:script'></xsl:template>\n</xsl:stylesheet>";
NSData *theData = [theDocument objectByApplyingXSLTString:theXSLTString arguments:nil error:&theError];
NSString *theString = [[NSString alloc] initWithData:theData encoding:NSUTF8StringEncoding];
}
}
This works fine on most pages. However, if a page doesn't validate correctly as XHTML, I sometimes get an error from my initWithXMLString: method.
That's fair enough - I'm asking it to tidy up the XHTML, so I'd expect it to report what problems it's encountered. But if there's a problem with the validation, it returns nil and an error rather than actually tidying up the XHTML.
One specific page that's causing the problem is the Ruby class documentation.
I've found that the excellent third party HTML tidy application can clean up this XHTML fine, but I'd expect NSXMLDocumentTidyHTML to be able to just add some quotes around cellpadding values. It's a fairly basic cleanup operation. And I'm not keen to add another dependency into my code base.
Is there something I'm missing with the way Cocoa cleans up XHTML? Or do I just need to bite the bullet and use HTML Tidy instead in my code?
XHTML documents are treated as XML, so you may have better luck with the NSXMLDocumentTidyXML flag.

How to display xml response already formatted in html (IE won't show anything after the xml table)

How to display xml response already formatted in html (IE won't show anything after the xml table)
If you visit this page in IE you'll see that nothing displays after the chart:
http://www.ratecatcher.com/prototype.htm
Here is the main php code:
$xml = file_get_contents($request);
echo html_entity_decode($xml);
Then the html that is giving me problems:
the user in IE won't see anything after this.
Is there a better way to display the html than html_entity_decode? I've heard about simplexml but I don't know if it works with html.
Thanks for helping!
You can try to use DOMDocument.
$dom = new DOMDocument('1.0', 'utf-8');
$dom->loadXML(file_get_contents($request));
echo $dom->saveXML(); // or saveHTML()