Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/367.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 有人能帮我处理这个XML代码吗?_Javascript_Xml_Ajax - Fatal编程技术网

Javascript 有人能帮我处理这个XML代码吗?

Javascript 有人能帮我处理这个XML代码吗?,javascript,xml,ajax,Javascript,Xml,Ajax,考虑到下面的HTML、JavaScript和XML,您会怎么做 tempText.innerHTML = allImages[i].textContent 你的意思是什么,它的价值是什么 allImages[i].textContent HTML标记 我的第二个Ajax脚本 JavaScript代码 window.onload=initAll; var xhr=false; 函数initAll(){ if(window.XMLHttpRequest){ xhr=new

考虑到下面的HTML、JavaScript和XML,您会怎么做

    tempText.innerHTML = allImages[i].textContent 
你的意思是什么,它的价值是什么

    allImages[i].textContent

HTML标记

我的第二个Ajax脚本
JavaScript代码
window.onload=initAll;
var xhr=false;
函数initAll(){
if(window.XMLHttpRequest){
xhr=newXMLHttpRequest();
}
否则{
if(window.ActiveXObject){
试一试{
xhr=新的ActiveXObject(“Microsoft.XMLHTTP”);
}
捕获(e){}
}
}
if(xhr){
xhr.onreadystatechange=showPictures;
open(“GET”,“C:\wamp\www\flickrfeed.xml”,true);
xhr.send(空);
}
否则{
警报(“抱歉,我无法创建XMLHttpRequest”);
}
}
函数showPictures(){
var tempDiv=document.createElement(“div”);
var testext=document.createElement(“div”);
if(xhr.readyState==4){
如果(xhr.status==200){
var allImages=xhr.responseXML.getElementsByTagName(“内容”);

for(var i=0;i包含(suprize!)节点的文本内容,例如,它的内容中去掉了所有标记。

。innerHTML表示目标元素中的HTML

比如说

你好,世界

元素的.innerHTML是“Hello World!”

不过,我不明白你其余的问题


尽管我相信.textContent可能意味着XML节点的文本内容,但考虑到这是直接从JavaScript和Ajax for the Web:Visual QuickStart Guide,第7版1得出的,您在第329-335页的(逐行)解释中遇到了什么特别的问题


1由我共同撰写,顺便说一句。

你能告诉我content.textContent的价值吗?pa href=“Smith/a发布了一张照片:/p pa href=“;title=“IMG_0045.JPG”IMG src=“;width=“240”height=“180”alt=“IMG_0045.JPG”"//a/p为什么不使用js调试器呢?每个现代浏览器中都有一个。遗憾的是,stackoverflow并没有过度引用惩罚。这个问题的代码取自JavaScript&Ajax for The Web,Visual QuickStart Guide,第7版。我是这本书的主要作者。因为这本书逐行清楚地解释了代码,所以我假设你是一个要求别人为你做家庭作业的学生。这充其量只是学术上的懒惰,至少不是很酷。我进一步注意到,在这个特定的例子中,你复制了包含我的合著者姓名的代码,这非常笨拙,很容易引起我的注意。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>My Second Ajax Script</title>
    <link type="text/css" rel="stylesheet" href="script02.css" />
    <script type="text/javascript" src="script02.js"></script>
</head>
<body>
    <div id="pictureBar"> </div>
</body>
</html>
window.onload = initAll;
var xhr = false;

function initAll() {
    if (window.XMLHttpRequest) {
        xhr = new XMLHttpRequest();
    }
    else {
        if (window.ActiveXObject) {
            try {
                xhr = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e) { }
        }
    }

    if (xhr) {
        xhr.onreadystatechange = showPictures;
        xhr.open("GET", "C:\wamp\www\flickrfeed.xml", true);
        xhr.send(null);
    }
    else {
        alert("Sorry, but I couldn't create an XMLHttpRequest");
    }
}

function showPictures() {
    var tempDiv = document.createElement("div");
    var tempText = document.createElement("div");
            
    if (xhr.readyState == 4) {
        if (xhr.status == 200) {
            var allImages = xhr.responseXML.getElementsByTagName("content");

            for (var i=0; i<allImages.length; i++) {
                tempText.innerHTML = allImages[i].textContent;
                tempDiv = tempText.getElementsByTagName("p");

                var theText = tempDiv[1].innerHTML;
                theText = theText.replace(/240/g,"75");
                theText = theText.replace(/180/g,"75");
                theText = theText.replace(/_m/g,"_s");
                document.getElementById("pictureBar").innerHTML += theText;
            }
        }
        else {
            alert("There was a problem with the request " + xhr.status);
        }
    }
}
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<feed xmlns="http://www.w3.org/2005/Atom"
      xmlns:dc="http://purl.org/dc/elements/1.1/"  xmlns:flickr="urn:flickr:" xmlns:media="http://search.yahoo.com/mrss/">    
    <title>Content from Paradise Ridge Sculpture Grove</title>
    <link rel="self" href="http://api.flickr.com/services/feeds/photoset.gne?set=72157600976524175&amp;nsid=23922109@N00&amp;lang=en-us" />
    <link rel="alternate" type="text/html" href="http://www.flickr.com/photos/dorismith/sets/72157600976524175"/>
    <id>tag:flickr.com,2005:http://www.flickr.com/photos/23922109@N00/sets/72157600976524175</id>
    <icon>http://farm2.static.flickr.com/1335/882568164_72eee9b41f_s.jpg</icon>
    <subtitle>The &lt;a href=&quot;http://www.paradiseridgewinery.com/&quot;&gt;Paradise Ridge Winery&lt;/a&gt; not only has great wines, but they also have a sculpture garden. We visited on 22 July 2007.</subtitle>
    <updated>2007-07-24T05:19:08Z</updated>
    <generator uri="http://www.flickr.com/">Flickr</generator>        
    <entry>
        <title>IMG_0045.JPG</title>
        <link rel="alternate" type="text/html" href="http://www.flickr.com/photos/dorismith/882590644/in/set-72157600976524175/"/>
        <id>tag:flickr.com,2005:/photo/882590644/in/set-72157600976524175</id>
        <published>2007-07-24T05:19:08Z</published>
        <updated>2007-07-24T05:19:08Z</updated>
        <dc:date.Taken>2007-07-22T13:42:49-08:00</dc:date.Taken>
        <content type="html">
            &lt;p&gt;&lt;a href=&quot;http://www.flickr.com/people/dorismith/&quot;&gt;Dori Smith&lt;/a&gt; posted a photo:&lt;/p&gt;
            &lt;p&gt;&lt;a href=&quot;http://www.flickr.com/photos/dorismith/882590644/&quot; title=&quot;IMG_0045.JPG&quot;&gt;&lt;img src=&quot;http://farm2.static.flickr.com/1063/882590644_5a4a0d89f3_m.jpg&quot; width=&quot;240&quot; height=&quot;180&quot; alt=&quot;IMG_0045.JPG&quot; /&gt;&lt;/a&gt;&lt;/p&gt;          
        </content>
        <author>
            <name>Dori Smith</name>
            <uri>http://www.flickr.com/people/dorismith/</uri>
        </author>
        <link rel="enclosure" type="image/jpeg" href="http://farm2.static.flickr.com/1063/882590644_5a4a0d89f3_m.jpg" />    
        <category term="winery" scheme="http://www.flickr.com/photos/tags/" />
        <category term="sonomacounty" scheme="http://www.flickr.com/photos/tags/" />
        <category term="sculptures" scheme="http://www.flickr.com/photos/tags/" />
        <category term="dorismith" scheme="http://www.flickr.com/photos/tags/" />
        <category term="paradiseridge" scheme="http://www.flickr.com/photos/tags/" />
        <category term="paradiseridgesculptures" scheme="http://www.flickr.com/photos/tags/" />
    </entry>
    <entry>
        <title>IMG_0043.JPG</title>
        <link rel="alternate" type="text/html" href="http://www.flickr.com/photos/dorismith/882589162/in/set-72157600976524175/"/>
        <id>tag:flickr.com,2005:/photo/882589162/in/set-72157600976524175</id>
        <published>2007-07-24T05:19:08Z</published>
        <updated>2007-07-24T05:19:08Z</updated>
        <dc:date.Taken>2007-07-22T13:41:55-08:00</dc:date.Taken>
        <content type="html">
            &lt;p&gt;&lt;a href=&quot;http://www.flickr.com/people/dorismith/&quot;&gt;Dori Smith&lt;/a&gt; posted a photo:&lt;/p&gt;
            &lt;p&gt;&lt;a href=&quot;http://www.flickr.com/photos/dorismith/882589162/&quot; title=&quot;IMG_0043.JPG&quot;&gt;&lt;img src=&quot;http://farm2.static.flickr.com/1179/882589162_25b4d6bcbe_m.jpg&quot; width=&quot;180&quot; height=&quot;240&quot; alt=&quot;IMG_0043.JPG&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
        </content>
        <author>
            <name>Dori Smith</name>
            <uri>http://www.flickr.com/people/dorismith/</uri>
        </author>
        <link rel="enclosure" type="image/jpeg" href="http://farm2.static.flickr.com/1179/882589162_25b4d6bcbe_m.jpg" />    
        <category term="winery" scheme="http://www.flickr.com/photos/tags/" />
        <category term="sonomacounty" scheme="http://www.flickr.com/photos/tags/" />
        <category term="sculptures" scheme="http://www.flickr.com/photos/tags/" />
        <category term="dorismith" scheme="http://www.flickr.com/photos/tags/" />
        <category term="paradiseridge" scheme="http://www.flickr.com/photos/tags/" />
        <category term="paradiseridgesculptures" scheme="http://www.flickr.com/photos/tags/" />
    </entry>
    <entry>
        <title>IMG_0042.JPG</title>
        <link rel="alternate" type="text/html" href="http://www.flickr.com/photos/dorismith/882587910/in/set-72157600976524175/"/>
        <id>tag:flickr.com,2005:/photo/882587910/in/set-72157600976524175</id>
        <published>2007-07-24T05:19:08Z</published>
        <updated>2007-07-24T05:19:08Z</updated>
        <dc:date.Taken>2007-07-22T13:40:36-08:00</dc:date.Taken>
        <content type="html">
            &lt;p&gt;&lt;a href=&quot;http://www.flickr.com/people/dorismith/&quot;&gt;Dori Smith&lt;/a&gt; posted a photo:&lt;/p&gt;
            &lt;p&gt;&lt;a href=&quot;http://www.flickr.com/photos/dorismith/882587910/&quot; title=&quot;IMG_0042.JPG&quot;&gt;&lt;img src=&quot;http://farm2.static.flickr.com/1073/882587910_39ffde28e6_m.jpg&quot; width=&quot;240&quot; height=&quot;180&quot; alt=&quot;IMG_0042.JPG&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
        </content>
        <author>
            <name>Dori Smith</name>
            <uri>http://www.flickr.com/people/dorismith/</uri>
        </author>
        <link rel="enclosure" type="image/jpeg" href="http://farm2.static.flickr.com/1073/882587910_39ffde28e6_m.jpg" />    
        <category term="winery" scheme="http://www.flickr.com/photos/tags/" />
        <category term="sonomacounty" scheme="http://www.flickr.com/photos/tags/" />
        <category term="sculptures" scheme="http://www.flickr.com/photos/tags/" />
        <category term="dorismith" scheme="http://www.flickr.com/photos/tags/" />
        <category term="paradiseridge" scheme="http://www.flickr.com/photos/tags/" />
        <category term="paradiseridgesculptures" scheme="http://www.flickr.com/photos/tags/" />
    </entry>
    <entry>
        <title>IMG_0041.JPG</title>
        <link rel="alternate" type="text/html" href="http://www.flickr.com/photos/dorismith/882586288/in/set-72157600976524175/"/>
        <id>tag:flickr.com,2005:/photo/882586288/in/set-72157600976524175</id>
        <published>2007-07-24T05:19:08Z</published>
        <updated>2007-07-24T05:19:08Z</updated>
        <dc:date.Taken>2007-07-22T13:40:18-08:00</dc:date.Taken>
        <content type="html">
            &lt;p&gt;&lt;a href=&quot;http://www.flickr.com/people/dorismith/&quot;&gt;Dori Smith&lt;/a&gt; posted a photo:&lt;/p&gt;
            &lt;p&gt;&lt;a href=&quot;http://www.flickr.com/photos/dorismith/882586288/&quot; title=&quot;IMG_0041.JPG&quot;&gt;&lt;img src=&quot;http://farm2.static.flickr.com/1334/882586288_6de3304bbb_m.jpg&quot; width=&quot;240&quot; height=&quot;180&quot; alt=&quot;IMG_0041.JPG&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
        </content>
        <author>
            <name>Dori Smith</name>
            <uri>http://www.flickr.com/people/dorismith/</uri>
        </author>
        <link rel="enclosure" type="image/jpeg" href="http://farm2.static.flickr.com/1334/882586288_6de3304bbb_m.jpg" />    
        <category term="winery" scheme="http://www.flickr.com/photos/tags/" />
        <category term="sonomacounty" scheme="http://www.flickr.com/photos/tags/" />
        <category term="sculptures" scheme="http://www.flickr.com/photos/tags/" />
        <category term="dorismith" scheme="http://www.flickr.com/photos/tags/" />
        <category term="paradiseridge" scheme="http://www.flickr.com/photos/tags/" />
        <category term="paradiseridgesculptures" scheme="http://www.flickr.com/photos/tags/" />
    </entry>
    <entry>
        <title>IMG_0040.JPG</title>
        <link rel="alternate" type="text/html" href="http://www.flickr.com/photos/dorismith/882583896/in/set-72157600976524175/"/>
        <id>tag:flickr.com,2005:/photo/882583896/in/set-72157600976524175</id>
        <published>2007-07-24T05:19:08Z</published>
        <updated>2007-07-24T05:19:08Z</updated>
        <dc:date.Taken>2007-07-22T13:39:49-08:00</dc:date.Taken>
        <content type="html">
            &lt;p&gt;&lt;a href=&quot;http://www.flickr.com/people/dorismith/&quot;&gt;Dori Smith&lt;/a&gt; posted a photo:&lt;/p&gt;
            &lt;p&gt;&lt;a href=&quot;http://www.flickr.com/photos/dorismith/882583896/&quot; title=&quot;IMG_0040.JPG&quot;&gt;&lt;img src=&quot;http://farm2.static.flickr.com/1233/882583896_90fad7b9ea_m.jpg&quot; width=&quot;180&quot; height=&quot;240&quot; alt=&quot;IMG_0040.JPG&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
        </content>
        <author>
            <name>Dori Smith</name>
            <uri>http://www.flickr.com/people/dorismith/</uri>
        </author>
        <link rel="enclosure" type="image/jpeg" href="http://farm2.static.flickr.com/1233/882583896_90fad7b9ea_m.jpg" />  
        <category term="winery" scheme="http://www.flickr.com/photos/tags/" />
        <category term="sonomacounty" scheme="http://www.flickr.com/photos/tags/" />
        <category term="sculptures" scheme="http://www.flickr.com/photos/tags/" />
        <category term="dorismith" scheme="http://www.flickr.com/photos/tags/" />
        <category term="paradiseridge" scheme="http://www.flickr.com/photos/tags/" />
        <category term="paradiseridgesculptures" scheme="http://www.flickr.com/photos/tags/" />
    </entry>
</feed>