how to read XML and then convert/transform it to variable String, I have try with Jsop library, but not success, with JSoup I get html format.
I want to read link in below to String:
http://bowingdown.wordpress.com/feed/
And then put it to String, I want to as below, example;
String data = "<rss xmlns:content=blablabla><channel>blablbabla</channel></rss>";
And i have read in here HTTP request for XML file, but not success.
Thanks for help.
Use xml parsing techniques such as XmlPullParser ,SAX parser or DOM parser.
XML Pull parser is the parser recommended in the developer's site of android Here is a tutorial for Pull parser .
Related
I have never had to download an XML file in Java before and parse it after. I'm looking to download and parse this file http://api.irishrail.ie/realtime/realtime.asmx/getStationDataByNameXML?StationDesc=Bayside
All I want to do is read the train times. I've been reading about parsing XML but I'm not really getting anywhere with it. I just keep reading about parsers like stax, after that I'm a bit lost.
Can anyone give me some basic advice of what I need to do?
You can use JAXB for this and any other XML processing needs. Start here.
You can use DOM parser and new Java Architecture for XML Binding JAXB it will help you in marshalling (for converting an xml to Object) and unmarshalling(for converting an Object to xml)
link for the example
http://www.vogella.com/tutorials/JAXB/article.html
You can use the DOM Parser to create a Document object from the XML file.
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new File(filename));
The DOM Parser creates a traversable tree from your XML data.
You can then pick out the data you need from the DOM tree using XPath.
try this library
http://x-stream.github.io/download.html
it is simple and fast to use to write and read xml from java.
I have an xml file which I want to read and parse it into POJO.
I am using XStream for this.
I am not able to send the file as an input to the code for parsing(file is on my local drive).
How to read the xml file and parse it using fromXML() method ?
I would be gratefull if someone can give example for sending xml file as input and parsing it to POJO and printing it on the screen
Thanks...
Based on the provided comments, I can better understand the problem you are facing. I believe the answer you are looking for is implicit collections. Check out the XStream tutorial on aliasing: http://x-stream.github.io/alias-tutorial.html .
anyone knows how to parse a XML string into a XML?.
I have a String that is, in fact, a XML:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.huawei.com/schema/syncorder/v1-0/" xmlns:tns="http://www.huawei.com.cn/schema/common/v2_1"><SOAP-ENV:Header><tns:NotifySOAPHeader><tns:spId>35000001</tns:spId><tns:serviceId>35000001000001</tns:serviceId><tns:spRevId/><tns:spRevpassword/></tns:NotifySOAPHeader></SOAP-ENV:Header><SOAP-ENV:Body><ns1:SyncOrderRelationExt><ns1:userID><ns1:UserID><ns1:ID>12346579801234567890</ns1:ID><ns1:type>0</ns1:type></ns1:UserID></ns1:userID><ns1:SPID>35000001</ns1:SPID><ns1:productID>11111111111</ns1:productID><ns1:serviceID>35000001000001</ns1:serviceID><ns1:serviceList>44444444</ns1:serviceLis<ns1:updateType>1</ns1:updateType><ns1:updateTime>55555555555555</ns1:updateTime><ns1:updateDesc>222222</ns1:updateDesc><ns1:effectiveTime>1256192581666</ns1:effectiveTime><ns1:expiryTime>5555555</ns1:expiryTime><ns1:extensionInfo><ns1:NamedParameterList><ns1:NamedParameters><ns1:ArrayOfNameParameter><ns1:NamedParameter><ns1:key>notifyAddress</ns1:key><ns1:value>http://10.40.63.16:9999/syn</ns1:value></ns1:NamedParameter></ns1:ArrayOfNameParameter></ns1:NamedParameters></ns1:NamedParameterList></ns1:extensionInfo><ns1:notifyAddress/></ns1:SyncOrderRelationExt></SOAP-ENV:Body></SOAP-ENV:Envelope>
I want to convert that string into a XML file, I donĀ“t want to create a file and save it on my computer just form an XML and parse it, because it is easier parse a XML than the String.
You need SAAJ API or DOM SAX will do that too.
use a Library for that. For instance this one
StringEscapeUtils.escapeXml(yourXmlString);
In my Scala code, I am fetching a response from a server using the getInputStream method of HttpUrlConnection class. The response is XML data. However the data contains HTML entities like & and '.
Is there a way I can replace these characters with their text equivalent so that I can parse the XML properly?
It's necessary to encode those entities in xml so they don't interfere with its syntax. The <(<) and > (>) entities make this more obvious. It would be impossible to parse XML whose content was littered with < and > symbols.
Scala's scala.xml package should give you the tools you need to parse your xml. Here's some guidance from the library's author.
I have a Java String with SGML, something like this...
<misspell></misspell><plain>I</plain> <plain>know</plain> <plain>you</plain> <suggestion>ducky</suggestion> <plain>suck</plain> <plain>and</plain> <plain>I</plain> <plain>rocky</plain> <plain>rock</plain>
How do I parse it to get for instance say the text inside <suggestion> </suggestion>so as to get "ducky" out??
Will javax.swing.text.html.parser.Parse can be of any help? or I can only parse HTML docs with it?
The string you show is not HTML, but it could be parsed by an XML parser.
The SAX API is part of the JDK and AFAIK most XML parsers implement it.
try an html parser, they are (by necessity) quite forgiving of malformed markup and html is by nature based on SGML.
e.g. http://htmlparser.sourceforge.net/