javascript - 如何将xml字段调用到html中

标签 javascript xml web-services

我有返回一些 xml 数据的 Web 服务的 URL。我需要加载此 xml 数据并仅包含我网站上的日期标记的值。如何才能做到这一点?

这是返回 xml 的 url:

http://www.islamicfinder.org/prayer_service.php?country=usa&city=new_york&state=NY&zipcode=10006&latitude=40.7092&longitude=-74.0128&timezone=-5&HanfiShafi=1&pmethod=5&fajrTwilight1=10&fajrTwilight2=10&ishaTwilight=10&ishaInterval=30&dhuhrInterval=1&maghribInterval=1&dayLight=1&simpleFormat=xml

<?xml version="1.0"?>
<prayer>
    <fajr>4:12</fajr>
    <sunrise>5:43</sunrise>
    <dhuhr>1:03</dhuhr>
    <asr>5:00</asr>
    <maghrib>8:22</maghrib>
    <isha>9:54</isha>
    <date>July 21, 2012</date>
    <hijri>2 Ramadan 1433</hijri>
    <city>New York</city>
    <country>Usa</country>
    <website>www.IslamicFinder.org</website>
</prayer> 

最佳答案

尝试使用 PHP 的 SimpleXMLElement

<?php
  $url = 'http://www.islamicfinder.org/prayer_service.php?country=usa&city=new_york&state=NY&zipcode=10006&latitude=40.7092&longitude=-74.0128&timezone=-5&HanfiShafi=1&pmethod=5&fajrTwilight1=10&fajrTwilight2=10&ishaTwilight=10&ishaInterval=30&dhuhrInterval=1&maghribInterval=1&dayLight=1&simpleFormat=xml';
  $result = new SimpleXMLElement($url, NULL, true);
  echo $result->date;
?>

NULL 意味着我们没有传递任何选项。 True 表示我们正在从 URL 获取数据。查看参数 here .

关于javascript - 如何将xml字段调用到html中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11595931/

相关文章:

java - Android - style.xml 不起作用

python - XML 文件偏移量和 XPath 插入元素

java - 使用 Java 建立 REST 服务的最快方法是什么?

javascript - 如何在 Controller 中捕获组合框 itemclick 事件

javascript - 变量不包含函数

javascript - 从 yui 数据表获取数据

Java:从 wsdl 获取示例请求 XML

javascript - 什么方法最适合在 JavaScript 中实例化其他函数的函数?

xml - Android 扩展 View 并从 XML 空指针异常创建

asp.net - 作为单例的 Web 服务是否会导致不同用户出现问题?