简体   繁体   English

从XML解析数据并在HTML上显示

[英]Parsing data from XML and display it on HTML

Currently I have this: 目前我有这个:

Notice the two boxes displayed are hard coded in, start from line 18 to line 70 in my HTML section. 注意,显示的两个框是硬编码的,从我的HTML部分的第18行到第70行。 Now that I have a .XML file: 现在,我有了一个.XML文件:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<collection>
 <beanRepresentation>
 <beanRepId>222</beanRepId>
 <beanRepName>Bean 1</beanRepName>
 <topY>0</topY>
 <leftX>0</leftX>
 <height>0</height>
 <width>0</width>
 </beanRepresentation>

 <beanRepresentation>
 <beanRepId>223</beanRepId>
 <beanRepName>Bean 2</beanRepName>
 <topY>0</topY>
 <leftX>0</leftX>
 <height>0</height>
 <width>0</width>
</beanRepresentation>

</collection>

I want to be able to parse this information and then display the boxes based on this .XML file, what should I use? 我希望能够解析此信息,然后基于此.XML文件显示框,我应该使用什么? jQuery? jQuery的? or just plain Javascript? 还是只是纯Javascript? Can someone help me with the example I posted here. 有人可以帮我解决我在此处发布的示例吗?

the topY is the top , and leftX is left for the HTML field respectively. topYtop ,并leftXleft分别为HTML场。 beanRepName should be the name displayed on the box, beanRepId is the integer in jsPlumb.draggable(id) in my Jacascript file. beanRepName应该是框中显示的名称,beanRepId是Jacascript文件中jsPlumb.draggable(id)中的整数。 So the four fields I need are topY, leftX, and beanRepId, and beanRepName. 因此,我需要的四个字段是topY,leftX,beanRepId和beanRepName。

as you already use jsPlumb you can use jQuery.parseXML() to parse the xml data in a searchable structure, iterate over it via $.each and create and insert new elements into the html page eg via 由于您已经使用过jsPlumb ,因此可以使用jQuery.parseXML()解析可搜索结构中的xml数据,通过$.each对其进行迭代,并创建新元素并将其插入html页面,例如通过

$('<div>')
.css({
    top:$currentxmlnode.find('topY').value()+'px'},
    ...
})
.appendTo(...);

Check the manual to learn how to retrieve the values from xml tree and this to learn how to create new nodes 检查手册 ,以了解如何检索XML树的价值和学习如何创建新节点

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

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