douzhi4830 2016-11-08 05:56
浏览 28

如何从解析的XML中获取价值

This is my XML with name test.xml:

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:test="http://www.test.com/rss/2.0">
<positionfeed>
    <test:import user="accounts@test.com" site="www.test.com" />
    <job>
        <id>83762455</id>
        <employer>Mount Ida College</employer>
        <title>Assistant Professor, Dental Hygiene</title>
        <description>As a faculty member, you will provide instruction in didactic courses, clinics, and/or labs in the Dental Hygiene Program.</description>
        <postingdate>2016-10-21</postingdate>
        <joburl>http://url.com</joburl>
        <location>Newton, MA</location>
        <category>Education</category>
    </job>
    <job>
        <id>83762405</id>
        <employer>Veterinary Orthopedic &amp; Sports Medicine Group</employer>
        <title>Overnight Recovery Technician</title>
        <description>As a faculty member, you will provide instruction in didactic courses, clinics, and/or labs in the Dental Hygiene Program.</description>
        <postingdate>2016-10-25</postingdate>
        <joburl>http://url.com</joburl>
        <location>Annapolis Junction, MD</location>
        <category>Installer/Technician</category>
    </job>
</positionfeed>
</rss>

This is my PHP page where I'm parsing it:

<?php
    $languages = simplexml_load_file("test.xml");
    print_r($languages);

    foreach ($languages->job as $job) {
        echo $job->title;
        echo "<br>";
    }
?>

I want:

job->id
job->title

and so on

=============================

print_r($languages) gives:

SimpleXMLElement Object ( [@attributes] => Array ( [version] => 2.0 ) [positionfeed] => SimpleXMLElement Object ( [job] => Array ( [0] => SimpleXMLElement Object ( [id] => 83762455 [employer] => Mount Ida College [title] => Assistant Professor, Dental Hygiene [description] => As a faculty member, you will provide instruction in didactic courses, clinics, and/or labs in the Dental Hygiene Program. [postingdate] => 2016-10-21 [joburl] => http://url.com [location] => Newton, MA [category] => Education ) [1] => SimpleXMLElement Object ( [id] => 83762405 [employer] => Veterinary Orthopedic & Sports Medicine Group [title] => Overnight Recovery Technician [description] => As a faculty member, you will provide instruction in didactic courses, clinics, and/or labs in the Dental Hygiene Program. [postingdate] => 2016-10-25 [joburl] => http://url.com [location] => Annapolis Junction, MD [category] => Installer/Technician ) ) ) )

============================

I tried researching a lot.

If I remove below three lines manually the PHP code works fine and displays values as needed, but I am unable to remove them dynamically.

<rss version="2.0" xmlns:test="http://www.test.com/rss/2.0">
    <test:import user="accounts@test.com" site="www.test.com" />
</rss>

So either of the way will work, if anyone can help, either help me to remove these three lines dynamically on load on PHP page else able to get values of the required nodes.

Again as description is long, I want:

job->id
job->title

and so on

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?