简体   繁体   English

使用javascript从预先创建的XML文件导入数据

[英]Using javascript to import data from pre-created XML file

I think its my first post here! 我认为这是我的第一篇文章! Used stackoverflow a lot, its a great website! 二手stackoverflow很多,它是一个很棒的网站!

I have an XML file that contains amongst other things, a field that contains a file path to a particular file, a field that provides a created date, and fields that provide the latitude, degrees and seconds, and the longitude, minutes and seconds of images from a phone. 我有一个XML文件,其中包含一个包含特定文件的文件路径的字段,一个提供创建日期的字段,以及提供纬度,度和秒以及经度,分钟和秒的字段。手机中的图像。

Part of the XML file is shown belows: (NB I have changed data in the file so it doesn't reflect "true" data.) 部分XML文件如下所示:(注意,我已更改文件中的数据,因此它不会反映“真实”数据。)

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<OFSExport Version="4">
    <MobileDevice Name="785421076249232-01-01-2015 10-40-45">
        <Sections>
            <Section Name="FILE_BROWSER">
            <Item Type="ATTR_FB_TYPE_FOLDER">
                <Field Type="FLD_FB_FILE_PATH">/private/var/mobile/Media/DCIM/101APPLE/</Field>
                <Field Type="FLD_FB_MODIFIED" UTC_Offset="0"></Field>
                <Field Type="FLD_FB_LAST_ACCESSED" UTC_Offset="0"></Field>
                <Field Type="FLD_FB_CREATED" UTC_Offset="0"></Field>
                <Field Type="FLD_ITEM_HASH" Hash_Method="ATTR_HASH_SHA-2"></Field>

            </Item>
            <Item Type="ATTR_FB_TYPE_FILE" Deleted="ATTR_FB_DEL_ACTUAL">
                <Field Type="FLD_FB_FILE_NAME">IMG_1230.JPG</Field>
                <Field Type="FLD_FB_FILE_SIZE">716102</Field>
                <Field Type="FLD_FB_FILE_PATH">/private/var/mobile/Media/DCIM/101APPLE/IMG_1230.JPG</Field>
                <Field Type="FLD_FB_MODIFIED" Date="17.01.2015" Time="18:16:09" UTC_Offset="0"></Field>
                <Field Type="FLD_FB_LAST_ACCESSED" Date="01.05.2015" Time="22:42:00" UTC_Offset="0"></Field>
                <Field Type="FLD_FB_CREATED" Date="17.01.2015" Time="18:16:08" UTC_Offset="0"></Field>
                <Field Type="FLD_ITEM_HASH" Hash_Method="ATTR_HASH_SHA-2">90e939f5bb4bad0ac53be9ad34db5bd98c4bc6628058ee9b5c3bcf4704f547bc</Field>
                <ExifInfo>
                    <ExifItem Type="FLD_FB_EXIF_ApertureValue" Eng_Title="Aperture value">2.27500712455432</ExifItem>
                    <ExifItem Type="FLD_FB_EXIF_BrightnessValue" Eng_Title="Brightness value">4.49876684478372</ExifItem>
                    <ExifItem Type="FLD_FB_EXIF_ColorSpace" Eng_Title="ColorSpace">1</ExifItem>
                    <ExifItem Type="FLD_FB_EXIF_DateTime" Eng_Title="Timestamp" Date="17.01.2015" Time="19:16:08" UTC_Offset="Device Time"></ExifItem>
                    <ExifItem Type="FLD_FB_EXIF_DateTimeDigitized" Eng_Title="Digitized timestamp" Date="17.01.2015" Time="19:16:08" UTC_Offset="Device Time"></ExifItem>
                    <ExifItem Type="FLD_FB_EXIF_DateTimeOriginal" Eng_Title="Original timestamp" Date="17.01.2015" Time="19:16:08" UTC_Offset="Device Time"></ExifItem>
                    <ExifItem Type="FLD_FB_ExifImageHeight" Eng_Title="Height">1920</ExifItem>
                    <ExifItem Type="FLD_FB_ExifImageWidth" Eng_Title="Width">3412</ExifItem>
                    <ExifItem Type="FLD_FB_EXIF_ExifVersion" Eng_Title="Exif version">0221</ExifItem>
                    <ExifItem Type="FLD_FB_EXIF_ExposureProgram" Eng_Title="Exposure program">2</ExifItem>
                    <ExifItem Type="FLD_FB_EXIF_ExposureTime" Eng_Title="Exposure time">11:01:48 AM</ExifItem>
                    <ExifItem Type="FLD_FB_EXIF_Flash" Eng_Title="Flash">16</ExifItem>
                    <ExifItem Type="FLD_FB_EXIF_FlashPixVersion" Eng_Title="Flash pix version">0100</ExifItem>
                    <ExifItem Type="FLD_FB_EXIF_FNumber" Eng_Title="Focal number">2.2</ExifItem>
                    <ExifItem Type="FLD_FB_EXIF_FocalLength" Eng_Title="Focal length">4.15</ExifItem>
                    <ExifItem Type="FLD_FB_EXIF_FocalLengthIn35mmFilm" Eng_Title="Focal length in 35mm film">74</ExifItem>
                    <ExifItem Type="FLD_FB_EXIF_GPSAltitude" Eng_Title="GPS altitude">124.118556701031</ExifItem>
                    <ExifItem Type="FLD_FB_EXIF_GPSAltitudeRef" Eng_Title="GPS altitude ref">0</ExifItem>
                    <ExifItem Type="FLD_FB_EXIF_GPSDateStamp" Eng_Title="GPS timestamp" Date="17.10.2016" Time="00:00:00" UTC_Offset="Device Time"></ExifItem>
                    <ExifItem Type="FLD_FB_EXIF_GPSDestLatitudeRef" Eng_Title="GPS dest latitude ref">E</ExifItem>
                    <ExifItem Type="FLD_FB_EXIF_GPSLatitudeDegrees" Eng_Title="GPS latitude degrees">40</ExifItem>
                    <ExifItem Type="FLD_FB_EXIF_GPSLatitudeMinutes" Eng_Title="GPS latitude minutes">30</ExifItem>
                    <ExifItem Type="FLD_FB_EXIF_GPSLatitudeSeconds" Eng_Title="GPS latitude seconds">10.00000000001</ExifItem>
                    <ExifItem Type="FLD_FB_EXIF_GPSLatitudeRef" Eng_Title="GPS latitude ref">N</ExifItem>
                    <ExifItem Type="FLD_FB_EXIF_GPSLongitudeMinutes" Eng_Title="GPS longitude minutes">15</ExifItem>
                    <ExifItem Type="FLD_FB_EXIF_GPSLongitudeSeconds" Eng_Title="GPS longitude seconds">31.0000000000001</ExifItem>
                    <ExifItem Type="FLD_FB_EXIF_GPSLongitudeRef" Eng_Title="GPS longitude ref">W</ExifItem>

I am a digital forensic examiner and I am trying to plot where pictures have been taken on a googlemap. 我是一名数字取证审查员,我正在尝试绘制在googlemap上拍摄照片的地方。 the XML file is output provided by forensic software, and although it plots the data to a map in a very nice way, there doesn't seem to be a method to let others view it. XML文件是由取证软件提供的输出,虽然它以非常好的方式将数据绘制到地图上,但似乎没有一种方法可以让其他人查看它。 So I am trying to create my own map with markers on it showing the location of where pictures are taken. 因此,我正在尝试创建自己的地图,上面有标记,显示拍摄照片的位置。 I am using Google streetmap via HTML5 and javascript to do this. 我通过HTML5和javascript使用Google街道地图来执行此操作。

The current plan is to loop through this XML file, pull out part of the file path, and the latitude and longitude data, add this data as a js object (fp:..., lat:..., lon: ....), and add this JS object to a JS array, and repeat till all the data is added. 目前的计划是循环遍历此XML文件,拉出部分文件路径以及纬度和经度数据,将此数据添加为js对象(fp:...,lat:...,lon:.. ..),并将此JS对象添加到JS数组中,并重复直到添加所有数据。 I will then loop through the array and create markers for each photograph on a map. 然后,我将遍历数组并为地图上的每张照片创建标记。 (A future thought is changing markers for thumbnails of the image, and noting numbers of pictures in a particular location.) (未来的想法是改变图像缩略图的标记,并注意特定位置的图片数量。)

For now I am trying to import the XML file and reference the bits I need, but I am struggling! 现在我正在尝试导入XML文件并引用我需要的位,但我很挣扎! I have tried xhttp.open , (the map will be a locally saved file that I will give to the customer afterwards, not saved to a server so this command doesn't work.) $.parseXML provides an error message of: 我试过xhttp.open ,(这个地图将是一个本地保存的文件,我将在之后提供给客户,而不是保存到服务器,因此该命令不起作用。) $ .parseXML提供了以下错误消息:

jquery.min.js:2 Uncaught Error: Invalid XML: geolocation.xml at Function.error (jquery.min.js:2) at Function.parseXML (jquery.min.js:2) at test.js:50 jquery.min.js:2未捕获的错误:无效的XML:位于test.js的Function.parseXML(jquery.min.js:2)的Function.error(jquery.min.js:2)中的geolocation.xml:50

Does anyone know of a way to loop through an already created xml file that resides in the same folder as the HTML file using javascript? 有没有人知道如何使用javascript循环遍历已创建的xml文件,该文件与HTML文件位于同一文件夹中?

Cheers 干杯

Bob 短发

parseXML use string for input, try next solution: parseXML 使用字符串输入,尝试下一个解决方案:

$.ajax({
    type: "GET",
    url: "geolocation.xml",
    dataType: "xml",
    success: function (xml) {
        // dataType do the job of $.parseXML(xml);
        console.log(xml);
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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