English 中文(简体)
利用简单的xml
原标题:Help navigating an XML file with multiple namespaces using simplexml

我正在实施一项方案,从XML档案中收集气象数据。 我尤其希望通过如下文中提及的档案,为特定地点提供风能统计数据。

位置在观察标的元数据中以名称表示“站-名称”。 风力数据载于观测和观测;元素。

多个名称空间的使用似乎使我对如何使用简单的xml文件的了解有限。

我正在尝试用一个Xml文档:

我已把测试削减到一个观察点(以下各点):

    <?xml version="1.0" encoding="UTF-8"?>
    <om:ObservationCollection xmlns:om="http://www.opengis.net/om/1.0" xmlns="http://dms.ec.gc.ca/schema/point-observation/2.0" xmlns:gml="http://www.opengis.net/gml" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<om:member>
    <om:Observation>
        <om:metadata>
            <set><general><author name="MSC-DMS-PG-WXO-HOURLY" version="1.5"/><dataset name="msc/observation/atmospheric/surface_weather/wxo-2.0-ascii"/><phase name="product-hourly_en-xml-2.0"/><id xlink:href="/data/msc/observation/atmospheric/surface_weather/wxo-2.0-ascii/product-hourly_en-xml-2.0/201105072356/mb"/><parent xlink:href="/data/msc/observation/atmospheric/surface_weather/cs-1.0-binary/decoded-xml-2.0/201105072300/cpgh"/></general>
            <identification-elements>
                <element name="station_name" uom="unitless" value="Gimli"/>
                <element name="latitude" uom="degree" value="50.63"/>
                <element name="longitude" uom="degree" value="-97.05"/>
                <element name="transport_canada_id" uom="unitless" value="PGH"/>
                <element name="observation_date_utc" uom="unitless" value="2011-05-07T23:00:00.000Z"/>
                <element name="observation_date_local_time" uom="unitless" value="2011-05-07T18:00:00.000 CDT"/>
                <element name="climate_station_number" uom="unitless" value="5031042"/>
                <element name="wmo_station_number" uom="unitless" value="71748"/>
            </identification-elements>
            </set>
        </om:metadata>
        <om:samplingTime><gml:TimeInstant><gml:timePosition>2011-05-07T23:00:00.000Z</gml:timePosition></gml:TimeInstant></om:samplingTime>
        <om:resultTime><gml:TimeInstant><gml:timePosition>2011-05-07T23:56:09.099Z</gml:timePosition></gml:TimeInstant></om:resultTime>
        <om:procedure xlink:href=""/>
        <om:observedProperty gml:remoteSchema="/schema/point-observation/2.0.xsd"/>
        <om:featureOfInterest>
            <gml:FeatureCollection>
                <gml:location><gml:Point><gml:pos>50.63333333333333 -97.05</gml:pos></gml:Point></gml:location>
            </gml:FeatureCollection>
        </om:featureOfInterest>
        <om:result>
        <orig-header/>
        <elements>
            <element name="present_weather" uom="code" value=""/>
            <element name="mean_sea_level" uom="kPa" value="100.89"/>
            <element name="tendency_amount" uom="kPa" value="0.07"/>
            <element name="tendency_characteristic" uom="code" value="rising"/>
            <element name="horizontal_visibility" uom="km" value=""/>
            <element name="air_temperature" uom="Celsius" value="11.4"/>
            <element name="dew_point" uom="Celsius" value="8.2"/>
            <element name="relative_humidity" uom="percent" value="81.0"/>
            <element name="wind_speed" uom="km/h" value="24.8"/>
            <element name="wind_direction" uom="code" value="SW"/>
            <element name="wind_gust_speed" uom="km/h" value="36.4"/>
            <element name="total_cloud_cover" uom="code" value=""/>
            <element name="wind_chill" uom="unitless" value=""/>
            <element name="humidex" uom="unitless" value=""/>
        </elements>
        </om:result>
    </om:Observation>
</om:member>
    </om:ObservationCollection>

这是我迄今为止所做的事情,它正正式让我看不到......。

    <?php
$xml = simplexml_load_file("weather.xml");
foreach($xml->item as $item){
    $collection = $item->children("http://www.opengis.net/om/1.0");
}

print_r($collection->member);

    ?>
问题回答

Try using XPath Language to query for their data with , 简单的XMLElement。

归根结底,我用了螺旋-replace来取代om:在原来的Xml体中。 这就否定了使用名称空间的必要性,并简单地用简单的xml来浏览xml。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签