How to Make a New Line or Tab in <String> Xml (Eclipse/Android)

How to make a new line or tab in string XML (eclipse/android)?

Add \t for tab and \n for new line.

Line Break in XML formatting?

Use \n for a line break and \t if you want to insert a tab.

You can also use some XML tags for basic formatting: <b> for bold text, <i> for italics, and <u> for underlined text.

Other formatting options are shown in this article on the Android Developers' site:

https://developer.android.com/guide/topics/resources/string-resource.html#FormattingAndStyling

Adding a new line/break tag in XML

The solution to this question is:

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="dummy.xsl"?>
<item>
<summary>
<![CDATA[Tootsie roll tiramisu macaroon wafer carrot cake. <br />
Danish topping sugar plum tart bonbon caramels cake.]]>
</summary>
</item>

by adding the <br /> inside the the <![CDATA]]> this allows the line to break, thus creating a new line!

add new line charater to xml file in android and preserver it after parsing

First, you should replace output.append(s) with output.append(s + \n), it will read from stream with new line symbols. And yes, you do not parse, you only read. If you want to parse, I odder to create two classes:

public class XmlResponseParser{

public static Response parse(String s){
Response response = new Response();

//as <SSID> and <Key> are inner parameters of <WiFi>, they should be
//looked for inside <WiFi> tag
String wifiString = findTagValue(s, "WiFi");
response.wifi.ssid = findTagValue(wifiString, "SSID");
response.wifi.key = findTagValue(wifiString, "Key");
response.contact = findTagValue(s, "Contact");

return response;
}
//finds and returns value of tag in substring
private static String findTagValue(String s, String tag){

int startTagValueIndex = s.indexOf("<" + tag + ">") + tag.length() + 2;
int endTagValueIndex = s.indexOf("</" + tag + ">");

return s.substring(startTagValueIndex, endTagValueIndex);
}

}

and

public class Response{
WiFi wifi;
String contact;

public Response(){
wifi = new WiFi();
}


public class WiFi{
String ssid;
String key;
}
}

Then you can call XmlResponseParser.parse(mScanXMLStr) in your code and it will return you and instance of Response class.

EDIT

Also, take a look at SimpleXml library to parse XML

How to do new line in (I don't know what language)

XML is a data format that gets its meaning from other applications and standards that use it. Your question cannot be answered with satisfying detail because it does not specify the application or standard that defines what the Task element or its Talk attribute means.

For an application-independent treatment of how to get newlines to work in XML, see

  • How to add a newline (line break) in XML file?

but be aware that identifying the application or standard associated with the XML is preferable.

how can I enter character in strings.xml?

If you are using eclipse then right click on strings.xml & open it with "Android Common XML Editor" & add from there it will handle escaping for you.

How to make Eclipse break String literal with + operator in next line?

Finally I found this is one missing feature of Eclipse.

Currently this issue is tracked under Eclipse's issue tracker :
https://bugs.eclipse.org/bugs/show_bug.cgi?id=48433


Update: I am now using Eclipse 4.3, and found that this feature is now available. Position of + operator when you are manually breaking a long String will now follows your code formatter setting.



Related Topics



Leave a reply



Submit