转换<<xml>标签

时间:2018-09-25 10:59:15

标签: java

我正在使用以下代码

public String readXmlData() {
    ArrayList<String > list = new ArrayList<String>();
    String strLine = null;
    String finalText="";
    try{
        // Open the file that is the first 
        // command line parameter
        FileInputStream fstream = new  FileInputStream(path);

        // Get the object of DataInputStream
        DataInputStream in = new DataInputStream(fstream);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        //Read File Line By Line
        while ((strLine = br.readLine()) != null)   {
            // Print the content on the console
            if(strLine.length()!=0){
                //list.add(strLine);
                finalText=finalText+strLine;
                System.out.println (finalText);

            }
        }
        System.out.println (finalText);
        //Close the input stream
        in.close();
    }catch (Exception e){//Catch exception if any
        System.err.println("Error: " + e.getMessage());
    }
    return finalText;
}

其给出的结果如下:

&lt;center&gt;&lt;table&gt;&lt;tr&gt;&lt;td bgcolor='#ffff00'&gt;Your Internet Order:&lt;/td&gt;&lt;td colspan='2' bgcolor='#ffff00' align='right'&gt;test/test/test8&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td bgcolor='#ffff00'&gt;Description:&lt;/td&gt;&lt;td&gt;EK Internet Booking Engine&lt;/td&gt;&lt;td align='right'&gt;1.00&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan='2'&gt;Subtotal:&lt;/td&gt;&lt;td align='right'&gt;935.65&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan='2' bgcolor='#c0c0c0'&gt;Total cost:&lt;/td&gt;&lt;td bgcolor='#c0c0c0' align='right'&gt;935.65&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan='3'&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td bgcolor='#ffff00' colspan='3'&gt;Your billing address:&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan='3'&gt;&lt;br&gt;Address Object contains :

我的要求是,我必须在文本框中按原样发布xml。

2 个答案:

答案 0 :(得分:0)

调用方法unescapeXml(finalText)。

public String unescapeXml(String escapedXml) {
    return escapedXml.replaceAll("&lt;", "<")
            .replaceAll("&gt;", ">");
}

答案 1 :(得分:0)

您可以使用var client = new System.Net.Http.HttpClient(); string response = string.Empty; string authHeader = string.Empty; string verb = string.Empty; string resourceType = string.Empty; string resourceId = string.Empty; string resourceLink = string.Empty; client.DefaultRequestHeaders.Add("x-ms-date", utc_date); client.DefaultRequestHeaders.Add("x-ms-version", "2017-02-22"); verb = "POST"; resourceType = "docs"; resourceLink = $"dbs/{databaseId}/colls/{collectionId}/docs"; resourceId = (idBased) ? $"dbs/{databaseId}/colls/{collectionId}" : collectionId.ToLowerInvariant(); authHeader = GenerateMasterKeyAuthorizationSignature(verb, resourceId, resourceType, masterKey, "master", "1.0"); client.DefaultRequestHeaders.Remove("authorization"); client.DefaultRequestHeaders.Add("authorization", authHeader); client.DefaultRequestHeaders.Add("x-ms-documentdb-isquery", "True"); client.DefaultRequestHeaders.Add("x-ms-documentdb-query-enablecrosspartition", "true"); client.DefaultRequestHeaders.Add("x-ms-partition-key", "[\"siteId\"]"); var qry = new SqlQuerySpec { query = "SELECT * FROM root WHERE (root[\"status\"] = 0)" }; var r = await client.PostWithNoCharSetAsync(new Uri(baseUri, resourceLink), qry); var s = await r.Content.ReadAsStringAsync();

https://commons.apache.org/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/StringEscapeUtils.html#unescapeHtml(java.lang.String)