XML to HTML
- Started
- Last post
- 15 Responses
- jonatne
Looking for some help here..
Trying to take info from an XML file and display it in an html file.
I've got the xml file loaded but when it comes time to insert information into an object in the DOM I am getting stumped. Very lost in the loops and appendChilds and all that.If you know of any resources out there or want any more info (source) let me know.
Thanks for your help..
- 7point340
do a search for xslt... i think thats what you want
- jonatne0
I may not understand xslt enough but I had the idea that it took an xml doc and formatted it to look/feel more like an xhtml document..
I have an html document that I want to insert some info in fed by xml.
I dont want xml that looks like html.I've found this http://www.w3schools.com/xml/xml…
Which works fine except it's limited to 1 entry if your using the .innerHTML method (Display XML Data in any HTML Element on the page).
I'm just not educated enough to make it show more than one entry.
- fugged0
Cool. Actually quite easy to do.
get a reference to the parent object, where you want to insert the create object. So let's say you want to add a paragraph to a div with the id of "bob".
var parentObj = document.getElementById("bob");
var newParagraph = document.createElement("p");
var paragraphText = "This is my text";
newParagraph.appendChild(paragra...
parentObj.appendChild(newParagra...That would insert a paragraph with the text of "This is my text" into the div "bob".
That's a super simple and bad example, in fact I didn't even check the syntax :)
- jonatne0
This is it working > http://floydandrob.tminus6.com/
Now it's document.write to make that so its putting it above the document..
I want it to write to a specific object (a div with an id)..
So this is pretty much turned into a question about dom manipulation..
Have a look at the script here > http://floydandrob.tminus6.com/a…
- document.write is old sk00l. use proper dom manipulation if you can.fugged
- fugged0
doh.. just noticed an error. heh. should be
var paragraphText = document.createTextNode("This is my text");
- jonatne0
fugged,
thanks, i, with the help of you here, understand that stuff..
however, the info i want to insert a little more complicated.. how do i make a variable or string out of the info in http://floydandrob.tminus6.com/a… thats after all of the document.write's
??
- fugged0
var myDiv = document.createElement("div");
myDiv.className = "entry";var p1 = document.createElement("p");
p1.className = "date";
p1.appendChild(document.createTe...var h3 = document.createElement("h3");
h3.appendChild(document.createTe...var p2 = document.createElement("p");
p1.appendChild(document.createTe...
var a = document.createElement("a");
a.setAttribute("href", x[i].getElementsByTagName("MOREL...
a.appendChild(document.createTex...
p2.appendChild(a);myDiv.appendChild(p1);
myDiv.appendChild(h3);
myDiv.appendChild(p2);you'll have to append myDiv to the document somewhere, but that should give you a start!
- jonatne0
I've created a loop that creates and "populates" html ( a couple of paragraphs and an anchor in a div ) for each xml entry.
You can see what it creates here > http://floydandrob.tminus6.com/How can I write the javascript so that instead of writing it to document.write it writes it to a parent object?
I can create objects and insert text nodes in them for all of this but I guess what I'm failing to grasp is how to make a loop to do that. So that it creates childs for each entry in the xml file.
- 7point340
you picked a poor time to ask a real question....
haha the sole legit thread amongst the fuckery
- jonatne0
Yeah, I know..
It's all good.. I have programmers on staff, just wanted to give this one a shot myself.. Seemed easy enough..
Thanks for your help fugged.
- fugged0
Sorry, got busy and can't finish helpin' ya right now. If you're still stuck later, I can help ya more. Trying to get a release out the door :)