JAVA開發定義固定報文之轉義字元
阿新 • • 發佈:2019-01-07
在做專案開發,難免會遇到一些報文的定義,除錯報文中可能需要先定義固定的報文測試介面,
"<PACKET type=\"REQUEST\" version=\"1.0\">\n" +
" <HEAD>\n" +
" <REQUEST_TYPE>01</REQUEST_TYPE>\n" +
" <USER>AICS3200</USER>\n" +
" <PASSWORD>215640</PASSWORD>\n" +
" </HEAD>\n" +
" <BODY>\n" +
" <BASE_PART>\n" +
" <QUERY_SEQUENCE_NO></QUERY_SEQUENCE_NO>\n" +
" <FUEL_TYPE>0</FUEL_TYPE>\n" +
" </BASE_PART>\n" +
" <DRIVER_LIST>\n" +
" </DRIVER_LIST>\n" +
" <COVERAGE_LIST>\n" +
" <COVERAGE>\n" +
" <COVERAGE_TYPE>1</COVERAGE_TYPE>\n" +
" <BILL_DATE>20151021</BILL_DATE>\n" +
" <AREA_FLAG>321000</AREA_FLAG>\n" +
" </COVERAGE>\n" +
" </COVERAGE_LIST>\n" +
" <COMMISSION_AGENT>\n" +
" <CERTIFICATE_NO></CERTIFICATE_NO>\n" +
" <INDIVIDUAL_PRODUCER_CODE></INDIVIDUAL_PRODUCER_CODE>\n" +
" </COMMISSION_AGENT>\n" +
" </BODY>\n" +
"</PACKET>";
這就需要我們使用String字串的形式定義,轉義字元寫法如下:
String queryQrySendXML =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +"<PACKET type=\"REQUEST\" version=\"1.0\">\n" +
" <HEAD>\n" +
" <REQUEST_TYPE>01</REQUEST_TYPE>\n" +
" <USER>AICS3200</USER>\n" +
" <PASSWORD>215640</PASSWORD>\n" +
" </HEAD>\n" +
" <BODY>\n" +
" <BASE_PART>\n" +
" <QUERY_SEQUENCE_NO></QUERY_SEQUENCE_NO>\n" +
" <FUEL_TYPE>0</FUEL_TYPE>\n" +
" </BASE_PART>\n" +
" <DRIVER_LIST>\n" +
" </DRIVER_LIST>\n" +
" <COVERAGE_LIST>\n" +
" <COVERAGE>\n" +
" <COVERAGE_TYPE>1</COVERAGE_TYPE>\n" +
" <BILL_DATE>20151021</BILL_DATE>\n" +
" <AREA_FLAG>321000</AREA_FLAG>\n" +
" </COVERAGE>\n" +
" </COVERAGE_LIST>\n" +
" <COMMISSION_AGENT>\n" +
" <CERTIFICATE_NO></CERTIFICATE_NO>\n" +
" <INDIVIDUAL_PRODUCER_CODE></INDIVIDUAL_PRODUCER_CODE>\n" +
" </COMMISSION_AGENT>\n" +
" </BODY>\n" +
"</PACKET>";