简体   繁体   English

使用DOM和JavaScript将XML数据加载到HTML

[英]Loading xml data to html using DOM & javascript

I am trying load various xml data to an html. 我正在尝试将各种xml数据加载到html。 Among other data i have the path of a background image. 除其他数据外,我还有背景图片的路径。 The xml loads ok but i am getting a white space that separates my path to the bg image (d_onkey). xml加载正常,但是我得到一个空白,将我的路径分隔到bg图像(d_onkey)。 There is no space in the xml file. xml文件中没有空格。 Any ideas where that comes from? 任何想法从何而来?

xml example xml范例

  <event id="event104">
    <img>images\donkey_fest.jpg</img>
    <title>test</title>
    <type>Cultural</type>
    <date>Friday 25/5/16</date>
    <time>19:30-01:30</time>
    <place>Stadium</place>
    <area>Limassol</area>
    <description>some text</description>
    <url>http://www.thevillagexpress.com/cyprusvillage/profile/209&amp;lang=gr</url>
  </event> 

html code HTML代码

document.getElementById("event_banner").style.backgroundImage = "url("+
x[i].getElementsByTagName("img")[0].childNodes[0].nodeValue + ")" ;

html outcome HTML结果

<div style="background-image: url(&quot;images\d onkey_fest.jpg&quot;);" class="event_banner" id="event_banner">
      </div>

Thank you. 谢谢。

Haven't tested this myself, but could it be that the \\ in your path is interpreted as an escape charachter? 自己还没有测试过,但是可能是您路径中的\\被解释为逃逸字符吗?

Try replacing it with "images\\\\donkey_fest.jpg" 尝试将其替换为“ images \\\\ donkey_fest.jpg”

I found a way around by putting the "images\\" to javascript. 我通过将“ images \\”放到javascript中找到了解决方法。 Issue solved. 问题已解决。 Thank you! 谢谢!

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

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