English 中文(简体)
利用Javascript To Parse XML 并制造从受损害的物品
原标题:Using Javascript To Parse XML and Create Objects From The Retrieved Values

我正试图用XML文件,但我对如何做到这一点感到困惑不解。 举例来说,下文是我的XML文件。

<document>
    <object name="Customer" type="class" x="137" y="63">
        <attributes>
        </attributes>
        <methods>
        </methods>
    </object>
    <object name="Item" type="class" x="539" y="275">
        <attributes>
        </attributes>
        <methods>
        </methods>
    </object>
    <link start="Customer" end="Item" type="generalization" />
</document>

在我看来,需要通过每一件“物体”并制造一个物体:objectArray.push(new uml_Class(name));

现在,如何通过每一条<代码>和>;object>,然后将其名称价值插入一个阵列?

一、导 言

alert(documentXML);
var root = documentXML.getElementsByTagName( Object );

It does alert my XML in the documentXML variable but then firebug tells me the following: documentXML.getElementsByTagName is not a function

如何通过XML文件反复制造物体?

问题回答

http://papermashup.com/parse-xml-with-jquery/“rel=”nofollow” XML教导能力。

例(从链接中转):

$(document).ready(function () {
    $.ajax({
        type: "GET",
        url: "books.xml",
        dataType: "xml",
        success: xmlParser
    });
});

function xmlParser(xml) {

    $( #load ).fadeOut();

    $(xml).find("Book").each(function () {

        $(".main").append( <div class="book"><div class="title">  + $(this).find("Title").text() +  </div><div class="description">  + $(this).find("Description").text() +  </div><div class="date">Published   + $(this).find("Date").text() +  </div></div> );
        $(".book").fadeIn(1000);

    });

}

由于其是XML文件,标签名称为not case invariant。

var objects = documentXML.getElementsByTagName( object );

should work. document.getElementsByTagName() is available on all Document object, I fear you missed to parse the string with a DOMParser.





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签