Xml response is like , but in one tag , the text is this:
<Description>
<center><strong><span>Warehouse / Building Maintenance</span></strong></center><br />
<br />
<strong><span>I</span></strong><span>mmediate openings available in the local Perris area for warehouse/building building maintenance positions. <br />
<br />
<strong>Job Description:</strong><br />
</span>
<ul>
<li><span>Associates will be responsible to define pieces of equipment that will paralyze operations if they fail, and plan whatever level of preventative maintenance necessary. <br />
</span></li>
<li><span>
......
similar text
......
</Description>
I can't able to parse it in proper way.
I tried using Jsoup.parse((nodeValue))
and Html.fromHtml(String) also URLEncoder.encode(String)
but its returning simple & symbol thats it.
How to parse this type of response?
A temporary solution could be applying replaceAll("<", "<").replaceAll(">", ">") if API methods aren't working, but arent you supposed to use Html.toHtml(string) when you have stuff encoded and want it to become real html ?
Actually its returning only & symbol , that's because the nodelist item returns only single value.
After using like this:
NodeList fstNm = fstNmElmnt.getChildNodes();
System.out.println("nodefstnm"+fstNm.getLength());
for(int j=0;j<fstNm.getLength();j++) {
String val = ((Node) fstNm.item(j)).getNodeValue();
nodeValue=nodeValue.concat(val);
}
and then parsing with Jsoup., returns what I want.
Related
As you can see here, the phone number here is starting from the right to the left.
However, I want it to display it like this (Image here is edited):
This is the TextView displaying this message:
<TextView
android:text="#string/smsSentTo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/smsSentTo"
android:textColor="#color/mdtp_white"
android:textSize="18sp"
android:layout_above="#+id/chooseUsernameAndPickProfilePicture"
android:layout_centerHorizontal="true"
android:layout_marginBottom="24dp"/>
#string/smsSentTo (Arabic locale): (looks like StackOverflow is displaying the {0} wrong, ignore that.)
<string name="smsSentTo">تم إرسال رسالة SMS إلى {0}</string>
#string/smsSentTo (English locale):
<string name="smsSentTo">An SMS has been sent to {0}</string>
As you can see, I'm formatting the text using MessageFormat:
String smsSentTo = MessageFormat.format(smsSentToTV.getText().toString(), phone);
smsSentToTV.setText(smsSentTo);
How can I get it to display these properly?
There is a solution with a downside
String html = "<p>تم إرسال رسالة SMS إلي</p>" + "+961 01 234 567";
textView.setText(Html.fromHtml(html));
The downside is that the HTML p tag prints a line afterwards separating the number into the next line. I tried to remove it with some HTML attributes or using tags other than p tag, but that didn't work
Hope this satisfies your need, or can give you even a clue.
In my android app, i have webview and showing some html data in it.
In HTML data,there are some img tags also.
I have puta check for internet connectivity like this::
String html = this.gn.renderHTML( sXMLDef, iScreenWidth, density);
ConnectivityManager cm =
(ConnectivityManager)this.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean isConnected = cm.getActiveNetworkInfo() != null
&& cm.getActiveNetworkInfo().isAvailable()
&& cm.getActiveNetworkInfo().isConnected();
String offlineimg = "<img src=\"file:///android_asset/offline.png\"/>";
if(!isConnected){
String str[] = html.split("\n");
for(int i=0; i<str.length; i++){
if(str[i].startsWith("<img")){
html = html.replace(str[i], offlineimg);
wvBrowser.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
}
}
}
wvBrowser.loadDataWithBaseURL( sBanner, html, this.mimeType,
this.encoding, null );
before adding internetc check, images were coming even if user is offline.
once i put internet check it just shows offline.png, if no internet avaliable. Ideally it shold show the cacheded images, if no internet and offline png, if imge is not cached or page has not loaded yet.
Below is generated html::
<img onclick="javascript:location.href = 'pic://' + this.src;" class="picture" align="MIDDLE" src="http://s3.amazonaws.com/iphonecde/_PNYCOOL.GIF"/></div><br />
<br />
<div class='captiontitle'><b>Built Into a Graphics Card</b></div><br />
<div class='caption'>This PNY graphics card comes with its own cooling system that also cools the CPU. The radiator and fan (left) cool the water coming from the card, and the center unit is placed over the CPU. <i>(Image courtesy of PNY Technologies, www.pny.com)</i></div><br />
<br />
<br />
<br />
<div align="center">
<img onclick="javascript:location.href = 'pic://' + this.src;" class="picture" align="MIDDLE" src="http://s3.amazonaws.com/iphonecde/_COOLR3.JPG"/></div><br />
<br />
You are assuming lot of things in your code:
HTML has a line feed (\n) for every line !
In most cases this is not the case
tag is always at the beginning of a new line !
Once again the assumption is most not true
Atleast, trim() the text before this search
You are managing your own caching, setting cache parameters for the webview is immaterial
My guess the error is (1) or (2) above. Paste your regenerated HTML to give your more information.
I have a TAG getinng the whole description is getting difficult in SimpleXML what property should i give to get whole description.
SimpleXML is parssing the p tag also .
<description>
<p>
Bar In Inconel</p> <ul> <li>600</li> <li>601</li> <li>617</li> <li>625</li> <li>718/718 NACE MRO</li> <li>725</li> <li>800</li> <li>825</li> <li>925</li> <li>K500</li> <li>MP35N</li> <li>X750</li> <li>C276</li></ul> <p>Aluminum Tubing, Aluminum Pipe, Aluminum Sheet, Aluminum Bar, Aluminum Plate In Aluminum</p> <ul> <li>2219</li> <li>2024</li> <li>2124</li> <li>3003</li> <li>5052</li> <li>6061</li> <li>7075</li> <li>7050</li></ul> <p>Stainless Steel In Tube, Pipe, Plate, Sheet &
</p>
</description>
When getting final response just enclose the CDATA tag and make the data=true for that element
str = str.replaceAll("<description>","<description><![CDATA[");
str = str.replace("</description>", "]]></description>");
:D :D
:D
I have one rails application where I have one model posts. Post model having two attributes - "title" & "content". I am using ckeditor for my content. Here is my ckditor snapshot
When I save something eg- "hi how r u" with bold, itallic, underline etc. Then it save posts content like this <b><i><u>hi how r u</u><i></b>. I know the solution in rails. I am using <%= raw(#posts.content) %> to solve this problem. But Now my problem is different. I want to fetch all the posts content from the database by using json. I am doing like this..
def index
#posts = Post.all
respond_with(#posts) do |format|
format.json { render json: #post_names = {:post => #posts.as_json(:only=> :content)} }
end
end
Now when i go through http://localhost:3000/posts.json then it showing like this
{"post":[{"content":"hi"},{"content":"hi"},{"content":"<img src=\"https://www.ginfy.com/img/logo.png\">"},{"content":"hi"},{"content":"my health is not good. Please pray for me..<br>"},{"content":"my health is not good. Please pray for me<br>"},{"content":"hello"},{"content":"<img src=\"http://www.ibettertechnologies.com/img/logo.png\">"},{"content":"<u><i><b>hi how r u?</b></i></u><br>"},{"content":"sdfsd"},{"content":"i am going to home. Please pray for my safe jouney"},{"content":"job"},{"content":"dsfdfs"},{"content":"fddf"},{"content":"jd dsbdsj djhj dsjhdfjks"},{"content":"ddd gd fgdfdg"},{"content":"dfslkdfskldfskl dskljdfskldf dskljdfskldfjslk"},{"content":"please pray for me"},{"content":"dfdf"},{"content":"cvxvxdfs"},{"content":"hdbhjds dsjks"},{"content":"s"},{"content":"hi"},{"content":"hu"}]}
I want to fetch this json in android. How can I use <%= raw() %> function in json to get correct formatted value.
You have to use Html.fromHtml() function to escape HTML tags. You can do like this ..
<TextView
android:id="#+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_margin="5dp"
android:textColor="#android:color/black"
android:textSize="20sp"
android:textStyle="bold" />
text2.setText(Html.fromHtml(app.getTitle()).toString());
Let's go to the point..
I make an Android application which target is Google APIs (Platform 2.2).
I want to parse the XML File which comes from the REST API.
The XML file likes this:
<title>EARTH WIND & FIRE Live in Concert</title>
I store that output in my String variable, which I can use later and since the output is in XML, I use XML Parser class of course.
And as you can see, since the rule of XML format doesn't allow the naked character, in this case my '&' character, it will show:
<title>EARTH WIND & FIRE Live in Concert</title>
So I change that character with this method: xml.replaceAll("&", "<![CDATA[&]]>");
xml is String and I replace my & with <![CDATA[&]]> tag.
And I follow this: Android how to parse CDATA TAG?
It says that I must use dbf.setCoalescing(true);
Everything goes fine and in my TextView shows the words EARTH WIND & FIRE Live in Concert. The ampersand character (&) is shown in my emulator (Platform 2.2).
But, when I try it in the device (Platform 2.1), it will show only EARTH WIND.
And I make the new emulator Google APIs (Platform 2.1), it shows EARTH WIND too.
Does anyone here face the same problem with me??
Is there any compatibility issue with the XML Parser or the <![CDATA[]]> tag in Android??
Thanks in advance...
In String.xml in resouces folder
<string name="my_string"><![CDATA[Please put Your long text here ]]></string>
if you want to access this string for textview:
<TextView
android:id="#+id/my_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="#string/my_string"
android:textColor="#android:color/white"
android:textSize="14sp"
android:textStyle="bold" />