LAJ
12-14-2007, 09:28 AM
Hello,
I've thus far been able to create basic XML to HTML conversions with Javascript, using Xpath in Firefox to pluck 'para' elements in the file and assign them to 'p' elements in HTML, for example. I'm using the document.createElement method, i.e:
articleHeading = document.createElement('h2');
articleHeading.appendChild(document.createTextNode(articleTitle));
document.getElementById('article').appendChild(articleHeading);
What I'm currently struggling with though is inline XML elements, so:
<article>
<para>This is a <link to='link location'>link</link> in a paragraph</para>
</article>
How would I separate each part of the para element's contents to append them one at a time to a paragraph? i.e. how would I pluck 'This is a ' by itself so that I can append it to a paragraph, then process the contents of the <link> element and append that to the paragraph, then finally add 'in a paragraph' at the end? As it is, the word 'link' appears in the paragraph but the <link></link> tags are ignored.
The XML file will contain different 'articles' that can link to one another, so I'd eventually I'd like a dynamic linking system in place so that if <link type='article'><article_id>4</article_id></link> appears then javascript generates an HTML link to the article with an ID of 4.
Thanks.
I've thus far been able to create basic XML to HTML conversions with Javascript, using Xpath in Firefox to pluck 'para' elements in the file and assign them to 'p' elements in HTML, for example. I'm using the document.createElement method, i.e:
articleHeading = document.createElement('h2');
articleHeading.appendChild(document.createTextNode(articleTitle));
document.getElementById('article').appendChild(articleHeading);
What I'm currently struggling with though is inline XML elements, so:
<article>
<para>This is a <link to='link location'>link</link> in a paragraph</para>
</article>
How would I separate each part of the para element's contents to append them one at a time to a paragraph? i.e. how would I pluck 'This is a ' by itself so that I can append it to a paragraph, then process the contents of the <link> element and append that to the paragraph, then finally add 'in a paragraph' at the end? As it is, the word 'link' appears in the paragraph but the <link></link> tags are ignored.
The XML file will contain different 'articles' that can link to one another, so I'd eventually I'd like a dynamic linking system in place so that if <link type='article'><article_id>4</article_id></link> appears then javascript generates an HTML link to the article with an ID of 4.
Thanks.