leonardo
Posts: 0
Joined: Thu Mar 14, 2013 7:04 pm

Simple Things Tripping

I need to be able to iterate through the children of "Main.intro" for processing because the structure within it is more complicated than I represented here. Thanks.
Please look at my second post above, where I detailed what I'm trying to achieve.

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Simple Things Tripping

[quote:] the structure within it is more complicated than I represented here[/quote]Please provide us with the full structure. In Chrome developer console enter codeconsole.log( here is your variable with objects and arrays ); /code and find the generated tree in console.

leonardo
Posts: 0
Joined: Thu Mar 14, 2013 7:04 pm

Simple Things Tripping

It's actually simpler. Here is a true structure of the "intro" node as it is in the xml. So far, I'm getting the "title" as a collection, all the "p" as a collection, and all the "subtitle" as a collection. I want to get all the elements together or access each of them in the order that they appear under "Intro."
code
<Main>
<intro>
<title>Intro title<&#47;title>
<p>Paragraph 1<&#47;p>
<subtitle>intro subtitle 1<&#47;subtitle>
<p>Paragraph 2<&#47;p>
<p>Paragraph 3<&#47;p>
<p>Paragraph 4<&#47;p>
<subtitle>intro subtitle 2<&#47;subtitle>
<p>Paragraph 5<&#47;p>
<p>Paragraph 6<&#47;p>
<p>Paragraph 7<&#47;p>
<subtitle>intro subtitle 3<&#47;subtitle>
<p>Paragraph 8<&#47;p>
<p>Paragraph 9<&#47;p>
<p>Paragraph 10<&#47;p>
<p>Paragraph 11<&#47;p>
<&#47;intro>
<groups>
<group>
&#46;&#46;group 1 items&#46;&#46;&#46;
<&#47;group>
<group>
&#46;&#46;group 2 items&#46;&#46;&#46;
<&#47;group>
<&#47;groups>
<&#47;Main>
/code

leonardo
Posts: 0
Joined: Thu Mar 14, 2013 7:04 pm

Simple Things Tripping

Thanks, Marina. Very good. I'll give it a shot.

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Simple Things Tripping

Hello! On service success you'll get all data in to variable data. You can go through all intro like this:

codevar intro = data&#46;Main&#46;intro;
var allP = intro&#46;p;
var allSubTitle = intro&#46;subtitle
var i, len;
for (i = 0, len = allP&#46;length; i < len; i++) {
alert(allP);
}
for (i = 0, len = allSubTitle&#46;length; i < len; i++) {
alert(allSubTitle);
}/code

But please note that arrays p and subtitle became independent. So if you need to save responce structure on service Complete runthe following code:
codevar xmlText = jqXHR&#46;responseText;
var parser = new DOMParser();
var xmlDoc = parser&#46;parseFromString(xmlText,"text&#47;xml");
var intro = xmlDoc&#46;getElementsByTagName("intro");
$(intro)&#46;children()&#46;each(function(index, value) {
var $value = $(value);
alert(index + " It's var xmlText = jqXHR.responseText;
var parser = new DOMParser();
var xmlDoc = parser.parseFromString(xmlText,"text/xml");
var intro = xmlDoc.getElementsByTagName("intro");
$(intro).children().each(function(index, value) {
var $value = $(value);
alert(index + " It's \"" + $value.prop(""tagName"") + ""\"" and here is text "" + ""\"""" + $value.text() + ""\"""");
})quot;" + $value&#46;prop("tagName") + "var xmlText = jqXHR.responseText;
var parser = new DOMParser();
var xmlDoc = parser.parseFromString(xmlText

Return to “Issues”