java - I have an error in reading the XML data of a given URL -


i use following code read xml data of given url have error , don't know how fix that. want read contents of given url on xml not in html. appreciated.

the code :

package search;  import java.io.bufferedreader; import java.io.filereader; import java.io.ioexception; import java.io.inputstream; import java.net.malformedurlexception; import java.net.url;  import javax.xml.parsers.documentbuilder; import javax.xml.parsers.documentbuilderfactory;  import org.w3c.dom.document;   public class process{     public static void main ( string [] args ) throws ioexception{          url xmlurl = new url("http://www.yahoo.com");         inputstream in = xmlurl.openstream();         document doc = parse(in);      }      public static document parse (inputstream is) {         document ret = null;         documentbuilderfactory domfactory;         documentbuilder builder;          try {             domfactory = documentbuilderfactory.newinstance();             domfactory.setvalidating(false);             domfactory.setnamespaceaware(false);             builder = domfactory.newdocumentbuilder();              ret = builder.parse(is);         }         catch (exception ex) {             system.err.println("unable load xml: " + ex);         }         return ret;     } } 

the error

[fatal error] :7:17: entity "lrm" referenced, not declared.   unable load xml: org.xml.sax.saxparseexception; linenumber: 7; columnnumber: 17;    entity "lrm" referenced, not declared. 

one of tenets of xml parsing input data should xml. however, example url, yahoo.com appears html5, isn't xml , isn't direct descendant of sgml (unlike html , xml) , not parsable xml commonly found parser. http can used return content type (html, xml, json, binary etc.) example given html. if rigged example url returned content type of xml, parsing errors go away.

if using xhtml, you'd ok html conforms xml structure rules then, it's easy break xhtml without realising it.

even regular html, although descendant of sgml won't parse xml can have non terminated tags etc.

in general, html parsers far more tolerant xml ones of deviations specifications, if limited usage xhtml sites, you'd still lot of parser failures.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -