簡體   English   中英

如何使用xml_parse_into_struct()

[英]How to use xml_parse_into_struct()

我正在嘗試使用xml_parse_into_struct() ,但返回的是false

我的代碼看起來像這樣

$p = xml_parser_create();
if (xml_parse_into_struct($p,$contenido,$vals, $index))
{
    print_r($vals);
}

變量的內容

$contenido看起來像這樣

<saltest31>
    <anuncio1>
        <id>12346</id>
        <titulo> BD authority</titulo>
        <descripcion>Preciosa casa en jardines de las animas, en xalapa veracruz. 550 m2 de terreno la mayoria jardin con arboles frutales, amplias recamaras, cocina, salon de juegos, terraza y palapa CVICA123</descripcion>
        <fecha>11/12/2014 10:27:15</fecha>
        <municipio>Chalchuapa</municipio>
        <moneda>Peso</moneda>
        <construccion>500</construccion>
        <terreno>550</terreno>
        <habitaciones>5</habitaciones>
        <banos>4</banos>
        <imagenes>
                <TOTAL>10</TOTAL>
                <IDIMAGE>5567</imagen_url>
                <IDIMAGE>5568</imagen_url>
                <IDIMAGE>5569</imagen_url>
                <IDIMAGE>5570</imagen_url>
                <IDIMAGE>5571</imagen_url>
        </imagenes>
    </anuncio>
</saltest3>

我的問題是if語句未返回true,我在哪里出錯了

提前致謝

這是因為您的XML中從<saltest31>...</saltest3>開始的頂部有太多不匹配的標簽。 這將導致返回0。

另外, xml_parse_into_struct()返回1或0,這不應誤認為是非。 文檔中

xml_parse_into_struct()對於失敗返回0,對於成功返回1。 這與FALSETRUE不同 ,請小心使用===之類的運算符。

鑒於此,您應該顯式執行測試:

$p = xml_parser_create();
if (xml_parse_into_struct($p,$contenido,$vals, $index) == 1)
{
    print_r($vals);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM