相关疑难解决方法(0)

简单的XML - 处理节点中的冒号

我正在尝试从Flickr读取RSS提要,但它有一些不能被Simple XML(media:thumbnail,flickr:profile等等)读取的节点.

我怎么绕这个?当我查看DOM的文档时,我的头疼.所以我想避免它,因为我不想学习.

顺便说一句,我正试图获取缩略图.

php xml simplexml

17
推荐指数
2
解决办法
1万
查看次数

因冒号而没有获取xml节点

我有一个XML文档,它使用斜杠:注释.当我使用php尝试检索这些节点中的内容时,它只是不起作用.

这是我的代码:

    <?php
$rss = new DOMDocument();
$rss->load('http://terrodactyl.netau.net/wordpress/?feed=rss2');
$feed = array();
foreach ($rss->getElementsByTagName('item') as $node) {
    $item = array ( 
        'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
        'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
        'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
        'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
                    'commentcount' => $node->getElementsByTagName('slash:comments')->item(0)->nodeValue,
                    'creator' => $node->getElementsByTagName('dc:creator')->item(0)->nodeValue,
        );
    array_push($feed, $item);
}
$limit = 5;
for($x=0;$x<$limit;$x++) {
    $title = str_replace(' & ', ' &amp; ', $feed[$x]['title']);
    $link = $feed[$x]['link'];
    $description = $feed[$x]['desc'];
    $date = date('l F d, Y', strtotime($feed[$x]['date']));
            $creator = $feed[$x]['creator'];
            $comments = $feed[$x]['commentcount'];
    echo "<div class=’blogpost primary_wide4’><h2>";
            echo …
Run Code Online (Sandbox Code Playgroud)

php xml simplexml

3
推荐指数
1
解决办法
2028
查看次数

如何解析具有 ns2 元素的 xml

$xml_data = '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<ns2:orders xmlns:ns2="http://skt.tmall.business.openapi.spring.service.client.domain">
<ns2:order>
<ordNo>201303285538019</ordNo>
<ordPrdSeq>1</ordPrdSeq>
<addPrdNo>0</addPrdNo>
<addPrdYn>N</addPrdYn>
<ordEmail>test@11street.my</ordEmail>
<clearanceEmail>test@11street.my</clearanceEmail >
<dlvCstType>03</dlvCstType>
<dlvNo>140065055</dlvNo>
<lstDlvCst>0</lstDlvCst>
<lstSellerDscPrc>0</lstSellerDscPrc>
<lstTmallDscPrc>0</lstTmallDscPrc>
<memID>test@11street.my</memID>
<memNo>25879997</memNo>
<ordAmt>0</ordAmt>
<ordCnQty>0</ordCnQty>
<ordDt>04-03-2014 10:40:32</ordDt>
<ordNm>Kil Jun Jeong</ordNm>
<ordOptWonStl>300000</ordOptWonStl>
<ordPayAmt>0</ordPayAmt>
<ordPrtblTel>010-2988-6401</ordPrtblTel>
<ordPrdStat>901</ordPrdStat>
<ordQty>0</ordQty>
<ordTlphnNo>070-7400-3141</ordTlphnNo>
<prdNm>test product name</prdNm>
<prdNo>233607759</prdNo>
<prdStckNo>1532843428</prdStckNo>
<rcvrBaseAddr>50929, Kuala Lumpur, Wilayah Persekutuan Kuala Lumpur
</rcvrBaseAddr>
<rcvrDtlsAddr>jl setia budi </rcvrDtlsAddr>
<rcvrMailNo>156010</rcvrMailNo>
<rcvrNm>Kil Jun Jeong</rcvrNm>
<rcvrTlphn>070-7400-3141</rcvrTlphn>
<selPrc>100000</selPrc>
<sellerDscPrc>0</sellerDscPrc>
<tmallDscPrc>0</tmallDscPrc>
</ns2:order>
</ns2:orders>            
';
Run Code Online (Sandbox Code Playgroud)

这是我的 xml,我想解析整个 xml,我尝试使用以下代码

$xml = simplexml_load_string($xml_data);
print_r($xml);
Run Code Online (Sandbox Code Playgroud)

但它返回空对象。

SimpleXMLElement 对象 ( )

我尝试使用childrenxml …

php xml rest simplexml xml-parsing

2
推荐指数
1
解决办法
1236
查看次数

PHP使用子项在标记名称中使用冒号分析XML

我有以下PHP代码:

$xml=simplexml_load_file("http://openclipart.org/api/search/?query=dog&page=1");
echo "<ul>";
foreach ($xml->channel->item as $clipinfo):
  $title=$clipinfo->title;
  $full=$clipinfo->enclosure['url'];
  $thumb=$clipartinfo->children('media', true)->thumbnail['url'];

  echo "<div style=\"width:160px;height:120px;float:left;margin:5px;margin-top:10px;\">    
  <a href=\"{$full}\" target='_blank' class=\"thumbnail\">
  <img alt=\"{$title}\" style=\"width: 160px; height: 120px;\" src=\"{$thumb}\">
  </a>
  </div>";
endforeach;
Run Code Online (Sandbox Code Playgroud)

这是由以下XML文件提供的:

<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:cc="http://web.resource.org/cc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:media="http://search.yahoo.com/mrss/" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>OpenClipart.org</title>
    <atom:link rel="self" href="http://openclipart.org/api/search/?query=dog&amp;page=1" type="application/rss+xml"/>
    <link>http://openclipart.org</link>
    <description>Download, Sample, Cut-up, Share.</description>
    <language>en-US</language>
    <image>
    <url>http://openclipart.org/assets/images/images/logo-no-text.jpg</url>
    <link>http://openclipart.org</link>
    <title>OpenClipart.org</title>
    <height>93</height>
    <width>114</width>
    </image>
    <item>
      <title>walking dog</title>
      <link>http://openclipart.org/detail/720/walking-dog-by-johnny_automatic</link>
      <pubDate>Tue, 17 Oct 2006 21:23:37 -0400</pubDate>
      <dc:creator>johnny_automatic</dc:creator>
      <description>cartoon of a girl walking a dog from  http://www.usda.gov/cnpp/KidsPyra/National Agricultural Library, Agricultural …
Run Code Online (Sandbox Code Playgroud)

php xml

1
推荐指数
1
解决办法
4140
查看次数

标签 统计

php ×4

xml ×4

simplexml ×3

rest ×1

xml-parsing ×1