J
joe_doufu
Hi, old web developer, new to Ajax and XML here.
I'm developing an application that grabs an XML file from a (PHP) web
service. In fact, it's going to be an online game. When the user
clicks a map location it accesses a service that provides information
about that location in a form something like this:
<maplocation locID="###" picturesrc="image.jpg">
<name>...</name>
<breadcrumbs>...</breadcrumbs>
<description>...</description>
</maplocation>
The problem for me is the <description> element. If the writers give
me a plain text description, fine, I can insert it into my web page's
DOM with the innerHTML property of an existing <span> tag or whatever.
However, I want my descriptions to be able to contain HTML (thus the
<description> node may have an unknown number of child nodes) which
then gets inserted into the DOM. I can't figure out how to do it.
I've tried wrapping the description in a <div> tag, like this:
<maplocation>
<description>
<div>
this is the most <i>interesting</i> location in the game...
</div>
</description>
</maplocation>
I tried grabbing it with the firstChild property of my <description>
element, and using appendChild() to stick it in a <div> in the DOM,
but it doesn't work. I've checked the nodeName property and made sure
what I was grabbing was the "div", but nothing appears on my page.
How can I achieve this?
I'm developing an application that grabs an XML file from a (PHP) web
service. In fact, it's going to be an online game. When the user
clicks a map location it accesses a service that provides information
about that location in a form something like this:
<maplocation locID="###" picturesrc="image.jpg">
<name>...</name>
<breadcrumbs>...</breadcrumbs>
<description>...</description>
</maplocation>
The problem for me is the <description> element. If the writers give
me a plain text description, fine, I can insert it into my web page's
DOM with the innerHTML property of an existing <span> tag or whatever.
However, I want my descriptions to be able to contain HTML (thus the
<description> node may have an unknown number of child nodes) which
then gets inserted into the DOM. I can't figure out how to do it.
I've tried wrapping the description in a <div> tag, like this:
<maplocation>
<description>
<div>
this is the most <i>interesting</i> location in the game...
</div>
</description>
</maplocation>
I tried grabbing it with the firstChild property of my <description>
element, and using appendChild() to stick it in a <div> in the DOM,
but it doesn't work. I've checked the nodeName property and made sure
what I was grabbing was the "div", but nothing appears on my page.
How can I achieve this?