在不使用 GXmlHttp 的情况下从 XML 文档中解析标记
Parsing markers from XML document without use of GXmlHttp
我已经将 Google 地图演示的大部分从 API 的 v2 升级到 v3。
我有一个工作 Handler.ashx,returns 来自 SQL 服务器数据的 XML 文件,其中的一个片段如下:
<root>
<marker INSTITUTION_KEY="100433" Latitude="40.735772366619301" Longitude="-73.994402766599904" INSTITUTION="New School, The" STREET="65 5th Avenue, Room M107A" CITY="New York" STATE="New York" ZIP="10011" ZIP4="????" WEBSITE="www.newschool.edu">
<Awards AreaID="12" AWARD="N71131B511" WORLDAREA="Western Europe"/>
<Awards AreaID="12" AWARD="N71131B511" WORLDAREA="Western Europe"/>
</marker>
<marker INSTITUTION_KEY="1022" Latitude="25.760174462957600" Longitude="-80.371959517777100" INSTITUTION="Florida International University" STREET="11220 SW 8TH ST" CITY="MIAMI" STATE="FL" ZIP="33184" ZIP4="0000" WEBSITE="www.fiu.edu">
<Awards AreaID="7" AWARD="F91131B511" WORLDAREA="Latin America"/>
<Awards AreaID="7" AWARD="F91131B511" WORLDAREA="Latin America"/>
</marker>
</root>
我读到 GXmlHttp 不再存在,我正在努力尝试转换此代码片段:
var request = GXmlHttp.create();
request.open("GET", urlRequest, true);
request.onreadystatechange = function() {
if (request.readyState == 4) {
var xmlDoc = request.responseXML;
var markers = xmlDoc.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
这是我到目前为止所得到的,但我被卡住了:
// Load the xml file using ajax
$.ajax({
type: "GET",
async: true,
url: urlRequest,
dataType: "xml",
success:
function (xml) {
// Parse the xml file and get data
var xmlDoc = $.parseXML(xml);
var markers = xmlDoc.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
希望获得有关如何进行此转换的提示。我收到一个错误:
Uncaught TypeError: Cannot read property 'documentElement' of null
同时尝试从具有 marker.
节点的行创建名为 markers 的数组
当您设置 dataType: xml
时,您不需要对 $.ajax
调用的结果调用 $.parseXML
"xml": Returns a XML document that can be processed via jQuery.
// Read the data
$.ajax({
type: "GET",
async: true,
url: urlRequest,
dataType: "xml",
success:
function (xml) {
// Parse the xml file and get data
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
我已经将 Google 地图演示的大部分从 API 的 v2 升级到 v3。
我有一个工作 Handler.ashx,returns 来自 SQL 服务器数据的 XML 文件,其中的一个片段如下:
<root>
<marker INSTITUTION_KEY="100433" Latitude="40.735772366619301" Longitude="-73.994402766599904" INSTITUTION="New School, The" STREET="65 5th Avenue, Room M107A" CITY="New York" STATE="New York" ZIP="10011" ZIP4="????" WEBSITE="www.newschool.edu">
<Awards AreaID="12" AWARD="N71131B511" WORLDAREA="Western Europe"/>
<Awards AreaID="12" AWARD="N71131B511" WORLDAREA="Western Europe"/>
</marker>
<marker INSTITUTION_KEY="1022" Latitude="25.760174462957600" Longitude="-80.371959517777100" INSTITUTION="Florida International University" STREET="11220 SW 8TH ST" CITY="MIAMI" STATE="FL" ZIP="33184" ZIP4="0000" WEBSITE="www.fiu.edu">
<Awards AreaID="7" AWARD="F91131B511" WORLDAREA="Latin America"/>
<Awards AreaID="7" AWARD="F91131B511" WORLDAREA="Latin America"/>
</marker>
</root>
我读到 GXmlHttp 不再存在,我正在努力尝试转换此代码片段:
var request = GXmlHttp.create();
request.open("GET", urlRequest, true);
request.onreadystatechange = function() {
if (request.readyState == 4) {
var xmlDoc = request.responseXML;
var markers = xmlDoc.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
这是我到目前为止所得到的,但我被卡住了:
// Load the xml file using ajax
$.ajax({
type: "GET",
async: true,
url: urlRequest,
dataType: "xml",
success:
function (xml) {
// Parse the xml file and get data
var xmlDoc = $.parseXML(xml);
var markers = xmlDoc.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
希望获得有关如何进行此转换的提示。我收到一个错误:
Uncaught TypeError: Cannot read property 'documentElement' of null
同时尝试从具有 marker.
节点的行创建名为 markers 的数组当您设置 dataType: xml
$.ajax
调用的结果调用 $.parseXML
"xml": Returns a XML document that can be processed via jQuery.
// Read the data
$.ajax({
type: "GET",
async: true,
url: urlRequest,
dataType: "xml",
success:
function (xml) {
// Parse the xml file and get data
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {