5 Replies - 716 Views - Last Post: 14 July 2011 - 08:33 PM Rate Topic: -----

#1 neverender2488  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 51
  • Joined: 27-September 10

LOOPING problem...Excel to php to xml

Posted 13 July 2011 - 07:11 PM

i have he the code getting the date from my excel file to transfer to xml, the problem is that i can't seem to get the right format that i want...i tried using counter variables but can't get any luck...any help could be appreciated

	for ($i = 1; $i <= $reader->sheets[0]["numRows"]; $i++){
	$dev = $reader->sheets[0]["cells"][$i][1];
	echo $dev;
	if ($dev!=$reader->sheets[0]["cells"][1+$i][1]){
		$variant1 = $pResource -> addChild('variant','');
		$variant1 -> addChild('device',$reader->sheets[0]["cells"][1+$i][2]);
			$jar1 = $variant1 ->addChild('jar','');
			$jar1 -> addAttribute('uri',$reader->sheets[0]["cells"][$i][4].$reader->sheets[0]["cells"][1+$i][6]);
			$jar1 -> addAttribute('contentType','application/java-archive');

		}else{	
		$variant1 -> addChild('device',$reader->sheets[0]["cells"][1+$i][2]);	
		}
					
	}


output:

 <variant>
        <device>Magic</device>
        <jar uri="FishLife.apk" contentType="application/java-archive"/>
        <device>Legend</device>
        <device>Hero</device>
        <device>Droid</device>
        <device>Sapphire</device>
      </variant>
      <variant>
        <device>KH5200</device>
        <jar uri="FishLife.apk" contentType="application/java-archive"/>
      </variant>
      <variant>
        <device>i1</device>
        <jar uri="FishLife.apk" contentType="application/java-archive"/>
      </variant>
      <variant>
        <device>G2</device>
        <jar uri="FishLife.apk" contentType="application/java-archive"/>
        <device>Mytouch 3G</device>
      </variant>



this sound fine but i want it like this: the <jar uri="FishLife.apk" contentType="application/java-archive"/> should be in the last place of the variants..something like below


 <variant>
        <device>Magic</device>
        <device>Legend</device>
        <device>Hero</device>
        <device>Droid</device>
        <device>Sapphire</device>
        <jar uri="FishLife.apk" contentType="application/java-archive"/>
      </variant>
      <variant>
        <device>KH5200</device>
        <jar uri="FishLife.apk" contentType="application/java-archive"/>
      </variant>
      <variant>
        <device>i1</device>
        <jar uri="FishLife.apk" contentType="application/java-archive"/>
      </variant>
      <variant>
        <device>G2</device>
        <device>Mytouch 3G</device>
        <jar uri="FishLife.apk" contentType="application/java-archive"/>
      </variant>

This post has been edited by Dormilich: 14 July 2011 - 02:34 AM
Reason for edit:: making the paragraph font smaller for better reading


Is This A Good Question/Topic? 0
  • +

Replies To: LOOPING problem...Excel to php to xml

#2 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 948
  • View blog
  • Posts: 2,357
  • Joined: 15-February 11

Re: LOOPING problem...Excel to php to xml

Posted 13 July 2011 - 07:54 PM

The way XML works is it doesn't matter which order the child nodes fall. The only thing that matters is what parent they fall under. So basically your two examples are the same.
Was This Post Helpful? 1
  • +
  • -

#3 neverender2488  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 51
  • Joined: 27-September 10

Re: LOOPING problem...Excel to php to xml

Posted 13 July 2011 - 07:58 PM

oh i see...so im doing the right thing eh...i don't know about that, but thanks a lot i learned a lot with that basic info...
Was This Post Helpful? 0
  • +
  • -

#4 neverender2488  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 51
  • Joined: 27-September 10

Re: LOOPING problem...Excel to php to xml

Posted 14 July 2011 - 05:56 PM

as a follow up...if have similar problem with this kind of arrangement...how would i make that desire output i want? can you tell me what to do get that output?
Was This Post Helpful? 0
  • +
  • -

#5 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 948
  • View blog
  • Posts: 2,357
  • Joined: 15-February 11

Re: LOOPING problem...Excel to php to xml

Posted 14 July 2011 - 07:42 PM

Call this $jar1 = $variant1 ->addChild('jar',''); after you've added the other nodes.
Was This Post Helpful? 0
  • +
  • -

#6 neverender2488  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 51
  • Joined: 27-September 10

Re: LOOPING problem...Excel to php to xml

Posted 14 July 2011 - 08:33 PM

View Postcodeprada, on 14 July 2011 - 07:42 PM, said:

Call this $jar1 = $variant1 ->addChild('jar',''); after you've added the other nodes.


im sorry but i don't really get it,,,i mean what line?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1