简体   繁体   中英

Parse XML file in Safari iOS in Javascript

How can I parse a xml file in iPad/iPod browser(is it called Safari iOS?) using Javascript?

I know this works for Opera but what about Safari?

xmlDoc = document.implementation.createDocument("","",null);
xmlDoc.load('myXMLFIle.xml');

Try the following:

var ParsedXMLDoc = ( new window.DOMParser() ).parseFromString( XMLContent, MIMEType );

The code above works for me in Safari on the Mac, I assume it is valid on iOS.

I think MIMEType may be optional, and you may need to ensure the XML prologue is present on your XML.

Given your example, you'll need to read the file you represent as "myXMLFIle.xml" into the XMLContent variable I show.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM