如何解决无效的字符常量

时间:2014-10-15 06:45:12

标签: xml string

String xmldata ='<?xml version="1.0" encoding="utf-8"?>'
            + "<String type ='basic_registration_mobile'"
                    + " Terminal_Number ='10'"
                            + " Terminal_Name='PayQwik'>"
        <Machine_Id>ertiueoirtueo</Machine_Id>
        <Mobile_num>9980066466</Mobile_num>
        <Password>dklgfjkld</Password>
        <Email_Id>rututhipse@g.com</Email_Id>
        <Date>2014-09-25 11:34:45</Date>
        <Gender>M</Gender>
        <Photo></Photo>
        <Address>45456tgdfg</Address>
    </String>";

此String显示无效的字符常量。如何解决它

1 个答案:

答案 0 :(得分:0)

您在<Machine_Id>之前缺少字符串连接。如果它允许多行字符串而不是地方+操作符和<Machine_Id>之前的双重引号

String xmldata ='<?xml version="1.0" encoding="utf-8"?>'
        + "<String type ='basic_registration_mobile'"
                + " Terminal_Number ='10'"
                        + " Terminal_Name='PayQwik'>"
    + "<Machine_Id>ertiueoirtueo</Machine_Id>
    <Mobile_num>9980066466</Mobile_num>
    <Password>dklgfjkld</Password>
    <Email_Id>rututhipse@g.com</Email_Id>
    <Date>2014-09-25 11:34:45</Date>
    <Gender>M</Gender>
    <Photo></Photo>
    <Address>45456tgdfg</Address>
</String>";

修改

替换此块

String xmldata ='<?xml version="1.0" encoding="utf-8"?>'
        + "<String type ='basic_registration_mobile'"
                + " Terminal_Number ='10'"
                        + " Terminal_Name='PayQwik'>"

String xmldata ="<?xml version=\"1.0\" encoding=\"utf-8\"?>"
        + "<String type =\"basic_registration_mobile\""
                + " Terminal_Number =\"10\""
                        + " Terminal_Name=\"PayQwik\">"