2016-07-20 6 views
2

Parsen habe ich einen String wie untenJsoup Unicode entites Umwandlung Einheiten html während

String input="<div class="prov2Txt">(2)&#x00a0;&#x00a0;Notwithstanding anything in any other written law and notwithstanding the making of an oath or declaration of secrecy, a person shall not be guilty of an offence by reason of anything done by him for the purposes of section&#x00a0;6.</div>"; 

Und ich bin Parsen mit JSOUP dann Jsoup Alle Unicode-Einheiten (&#x00a0) entfernt Entität in HTML.

Document d = Jsoup.parse(input); 
d.outputSettings(new Document.OutputSettings().prettyPrint(false)); 

Dieser Code konvertiert &#x00a0 seiner equvailent HTML-Entität.

Jetzt möchte ich alle Unicode-Entitäten beibehalten, wie es nach dem Parsen der Eingabezeichenfolge ist.

Antwort

1

Der xhtml Escape Modus kann Ihre Bedürfnisse anzupassen:

d.outputSettings(new Document.OutputSettings().escapeMode(EscapeMode.xhtml).prettyPrint(false)); 

Es &#x00a0 in &#xa0; verwandelt.

+0

Ich habe alles versucht.Dont für mich 'document.outputSettings (new Document.OutputSettings(). PrettyPrint (false)); document.outputSettings (neues Document.OutputSettings()); // Escape-Modus anpassen document.outputSettings(). EscapeMode(); ' –

+0

@vinaykaushik Ich sehe den Beispielcode in der Antwort nicht. Hast Du es versucht? – Stephan

+0

Ja, ich habe es versucht. –