开发者

How to parsing a error customized template in PHPDom? or Other solutions?

everybody I have a question in PHPDom. I want to made a parer in php code, but I take a trouble.

Now, it have a HTML tmplate (tmpl.html), like following:

<html xmln开发者_运维百科s="http://www.w3.org/ns" xmlns:oth="http://some.com/ns">
    <title>Some Page</title>
    <body>
        <oth:items>
            <oth:item>
            <div>my name is :<input type="text" name="name" value="{name}" /></div>
            <div>this is my photo <img src="{photo}"> </div>
            </oth:item>
        </oth:items>
    </body>
</html>

and , a PHP code (test.php), like following:

<?php
$informations = array(  //someone information
      '12000647300118' => array(
          'name' => 'Charles'
        , 'photo' => './img/X$FWEFjjfjf.png'
    )
    , '12000647300117' => array(
          'name' => 'Alise'
        , 'photo' => './img/CFG%Jddlsjf.png'
    )
);

$doc = new DOMDocument;
$doc->loadXML(file_get_contents('./tmpl.html', true));
?>

BUT.......... it show a error

Warning: DOMDocument::loadXML() [domdocument.loadxml]: Opening and ending tag mismatch: img line 8 and a in Entity, line: 8 in C:\Apache2.2\htdocs\test.php on line 12

becouse, the tag of img is not a ending tag

Error:<img src="{photo}">

Correct:<img src="{photo}" / >


I want made a parer to paring tmpl.html become:

<html xmlns="http://www.w3.org/ns" xmlns:oth="http://some.com/ns">
    <title>Some Page</title>
    <body>
        <items>
            <item>
            <div>my name is :<input type="text" name="name" value="Charles" /></div>
            <div>this is my photo <img src="./img/X$FWEFjjfjf.png"> </div>
            </item>
            <item>
            <div>my name is :<input type="text" name="name" value="Alise" /></div>
            <div>this is my photo <img src="./img/CFG%Jddlsjf.png"> </div>
            </item>
        </items>
    </body>
</html>

Who can showing me the solution. thanks. ^_^

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜