从PHP中的XML中检索多个选项中的特定标记值

时间:2016-02-07 13:21:35

标签: php xml

$xmlDoc = new DOMDocument();
    $path_to_dir = '/var/www/html/imgdone/'.$character.'/Annotation/'.$var_new.'';
    $xmlDoc->load($path_to_dir);
    $elements = $xmlDoc->getElementsByTagName('surface');
    $elements1 = $xmlDoc->getElementsByTagName('text');
    foreach($elements1 as $node)
    {
        foreach($node->childNodes as $child) 
        {
           if($child->nodeName=='p')
           {
            $path=$child->getAttribute();
            echo $path;
        //   $path_new=str_replace("\\", "/", $path);
        //   echo "<br>";
        //   $path_new1 = str_replace("Z:/home/ashutosh/Desktop/", "", $path_new);
        //   echo "<br>";
        //   echo '<img src="'.$path_new1.'"  height="150" width="200" />';

           }
        }
    }

我有一个XML文件,我正在用PHP加载XML文件。我想从XML值中检索<p>标记值。但是,您可以在下面的XML代码中看到2个<p>标记名称。我希望得到&#34; p&#34;标记名包含&#34;卡通Sketch_Non FrontalFace_Thoughtful_Young_Male_No Beard_No Glass&#34;值。

如何将该值传递给变量。

我正在尝试但没有得到任何价值。我是PHP的新手。 PHP代码发布在上面。

<TEI version="5.0" xml:id="_0001">
<teiHeader>
<fileDesc>
<titleStmt>
<title/>
</titleStmt>
<publicationStmt>
<p/>
</publicationStmt>
<sourceDesc>
**<p>194 x 260</p>**
</sourceDesc>
</fileDesc>
<label>
Image Markup Tool
</label>
<ref type="appURI" target="http://hcmc.uvic.ca/~mholmes/image_markup/">
</ref>
</teiHeader>
</surface>
</facsimile>
<text>
<body>
<div xml:id="imtImageAnnotations">
<div corresp="#imtArea_0" type="imtAnnotation"> 
<head>
Attributes
</head>
<div>
    **<p>Cartoon Sketch_Non Frontal Face_Thoughtful_Young_Male_No Beard_No Glass**
</p>
</div>
</div>
</div>
</body>
</text>
</TEI>

0 个答案:

没有答案