如何从DB中获取php中的有效XML表示法

时间:2015-12-17 13:37:22

标签: php sql-server xml

我在表格(MS-SQL DB)中存储了以下XML。

<CUSTOMER>
    <CUSTOMERDATA>
    <USERID>12691</USERID>
    <USERCODE>FFRD991</USERCODE>
    <MOBILENO>5645353443</MOBILENO>
    <EMAILID>jhfghfghgf@sdf.fh</EMAILID>
    <FIRSTNAME>ggdg</FIRSTNAME>
    <MIDDLENAME>dfgdfgdf</MIDDLENAME>
    <LASTNAME>gdfgdf</LASTNAME>   
    <ADDRESS></ADDRESS>
    <CITY></CITY>
    <PINCODE></PINCODE>
    <STATENAME></STATENAME>
    <SOURCE>Others</SOURCE>
    <CREATEDATE>2015-12-01</CREATEDATE>   
    <STATUS></STATUS>
    </CUSTOMERDATA>
</CUSTOMER>

现在我想使用以下代码通过php获取此记录:

$query = "Select xml_rec from tbl_node where  UserId = 12691";
$result = sqlsrv_query($this->db->conn_id, $query);
$row = sqlsrv_fetch_object($result);
//// OR
$row = sqlsrv_fetch_array($result , SQLSRV_FETCH_ASSOC);        
echo $row['xml_rec'];

我收到以下错误的XML。请注意空白标签。

<CUSTOMER>
    <CUSTOMERDATA>
    <USERID>12691</USERID>
    <USERCODE>FFRD991</USERCODE>
    <MOBILENO>5645353443</MOBILENO>
    <EMAILID>jhfghfghgf@sdf.fh</EMAILID>
    <FIRSTNAME>ggdg</FIRSTNAME>
    <MIDDLENAME>dfgdfgdf</MIDDLENAME>
    <LASTNAME>gdfgdf</LASTNAME>   
    <ADDRESS/>
    <CITY/>
    <PINCODE/>
    <STATENAME/>
    <SOURCE>Others</SOURCE>
    <CREATEDATE>2015-12-01</CREATEDATE>
    <STATUS/>
    </CUSTOMERDATA>
</CUSTOMER>

如何修复此问题以显示正确的XML?感谢您宝贵的时间。

0 个答案:

没有答案