tags:

views:

21

answers:

1

Hi,

I am getting an [object HTMLUnknownElement] when going through XML.

<?xml version="1.0" encoding="utf-8"?>
<blamatrixrix>
<name></name>
<columns number="2">
 <column id="title" num="0">Title</column>
 <column id="content" num="1">Content</column>
</columns>
<rows number="7"></rows>
<b>Description</b>
<b>Description text here</b>
<b>Some title 1</b>
<b>Some text blabla for Some title 1</b>
<b>Some title 2</b>
<b>Some text blabla for Some title 2</b>
<b>Some title 3</b>
<b>Some text blabla for Some title 3</b>
<b>Some title 4</b>
<b>Some text blabla for Some title 4</b>
<b>Some title 5</b>
<b>Some text blabla for Some title 5</b>
<b>Some title 6</b>
<b>Some text blabla for Some title 6</b>
</blamatrixrix>

That's the XML. I trying to get the content from inside of the <c>..</c> with this code:

$(data).children().each(function(c ,ss) {
var content = $(ss).find('c').children();
console.log(content);
$("#table").append('<tr><td>' + ss + '</td></tr>');*/
});

What exactly am I doing wrong? I also tried get the text with

var content = $(ss).find('c').children().text();

but same result.

Thanks!

+1  A: 

Well first of all, the element <c> is not inside the XML file you've provided.

Secondly and more importantly, you should use $(this) inside your .each loop.

Finally, inside your append() method, you're specifying (in your case) an object, instead of any of it's properties. The closest match I could possibly think of from the code you provided would look something like

$(data).find("b").each(function(index) {
    $("#table").append('<tr><td>' + $(this).text() + '</td></tr>');
});

What's data anyway?

Marko
Data is the content of that XML you see above. And yes, I mean <b></b>, I just miss wrote here that I want <c>s. Sorry about that. I'll try that and try to figure it out with your provided example. Thank you!
samuelblok
It works atleast somehow. Thanks Marko!
samuelblok
Try using `find()` instead, see my update.
Marko
Thanks, works like a charm. Only thing is that I dont actually need to put all the content in <td> but some (the titles) should go into <tr> and the text under of those titles as <td>. Basically own ros for titles and text. How can I get that content into a array? I tried this: featuresArray=$(this).text(); but it gets the last thing only I believe?
samuelblok
@samuelblok: I don't quite understand what you mean. The best thing to do is provide your input XML file and your expected HTML output. I should be able to understand from that.
Marko