How to encode XML on Android?

I need to encode an XML document in a format that will pass through an XML parser as a string (i.e. delimiter tags). Then I need to decode it again, and I need to do it on Android. What is the library / class in the Android API I'm looking for?

thank

+3
source share
4 answers

I ended up using URLEncoder / URLDecoder, which seems to work well.

String encoded = URLEncoder.encode(xml);
+2
source

XmlSerializer - , , , . "" XML-; text(...) XML-, . DOM API, setTextContent, DOM, XML. , , , XML .

XML- , Apache commons-lang StringEscapeUtils. , XML Android API.

:

XmlSerializer xs = Xml.newSerializer();
StringWriter sw = new StringWriter();
xs.setOutput(sw);
xs.startDocument(null, null);
xs.startTag(null, "foo");
xs.text("<bar>this is some complete XML document you had around before</bar>");
xs.endTag(null, "foo");
xs.endDocument();
Log.v("XMLTest", "Generated XML = " + sw.toString());
+4

Generic Java XML Parser is the way to go.

and if you need to create it manually, you can use XmlSerializer

edit:

Here 's an article about working with xml on android, but it also uses the XmlSerializer to write

0
source

this question is one of the first results when I was looking for a solution to this problem, so I answer here

Html.fromHtml (string)

0
source

Source: https://habr.com/ru/post/1758957/


All Articles