2 Replies - 848 Views - Last Post: 12 September 2014 - 02:45 AM Rate Topic: -----

#1 suryachandra.p   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-September 14

how to generate dynamic xml file based on field data

Posted 12 September 2014 - 02:02 AM

in the following code i am retrieving image,audio,video paths from $fck POST field, and I need to generate xml file based on the paths please help out how to achieve that. my code is creating xml file but when i am trying to insert two images its not generating new tag in xml file.., please help me
$xml = new DOMDocument("1.0");
				$root = $xml->createElement("mmsdata");
					$xml->appendChild($root);
					
					$bookImage = $xml->createElement("img");
					$bookImageSub = $xml->createElement("ipath");
					
					$bookAVideo = $xml->createElement("avideo");
					$bookAVideoSub = $xml->createElement("avideo");
					
					$bookText = $xml->createElement("text");
					$bookTextTen = $xml->createElement("tencoding");
					$titleTextTen = $xml->createTextNode('" Text encoding "');
					$bookTextTen->appendChild($titleTextTen);
					
					$bookTextTenText = $xml->createElement("tdata");
					
				
				$doc= new DOMDocument();
				$doc->loadHTML($fck);
				$xpath = new DOMXPath($doc);
				foreach ($xpath->query('//p') as $div) {
				foreach ($xpath->query('text()', $div) as $text) {
				$xmltext1 = "$text->nodeValue\n";
				$xmltextArr[] = $xmltext;
				$xmltext = preg_replace('/[^(\x20-\x7F)]*/','',$xmltext1);
					$titleTextTenText = $xml->createTextNode($xmltext);
					$bookTextTenText->appendChild($titleTextTenText);
				}
				}
				$tagIMG = $doc->getElementsByTagName('img');
				 foreach ($tagIMG as $tag) {
					
					$xmlimg1 = $tag->getAttribute('src')."<br>";
					$xmlimgArr[]=$xmlimg;
					$xmlimg = trim(strip_tags($xmlimg1));
					$titleImageSub = $xml->createTextNode($xmlimg);
					$bookImageSub->appendChild($titleImageSub);
					
					
				}
				$tagAV = $doc->getElementsByTagName('embed');
				 foreach ($tagAV as $tag) {
					 $xmlavideo1 = $tag->getAttribute('src')."<br>";
					 $xmlavideoArr[]= $xmlavideo;
					$xmlavideo = trim(strip_tags($xmlavideo1));
					$titleAVideoSub = $xml->createTextNode($xmlavideo);
					$bookAVideoSub->appendChild($titleAVideoSub);
				}
				/*echo $xmlimgArr[0];
				echo $xmlimgArr[1];
				echo $xmlavideoArr[0];
				echo $xmlavideoArr[1];
				echo $xmltextArr[0];
				*/
					
				$root->appendChild($bookText);
				$bookText->appendChild($bookTextTen);
				$bookText->appendChild($bookTextTenText);
				$root->appendChild($bookImage);
				$bookImage->appendChild($bookImageSub);
				$root->appendChild($bookAVideo);
				$bookAVideo->appendChild($bookAVideoSub);
				$xml->formatOutput = true;
				echo "<xmp>". $xml->saveXML() ."</xmp>"; die;
				$pth=$xml->save("/tmp/xml/".$_POST['campaignname']."_.xml") or die("Error");


Is This A Good Question/Topic? 0
  • +

Replies To: how to generate dynamic xml file based on field data

#2 suryachandra.p   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-September 14

Re: how to generate dynamic xml file based on field data

Posted 12 September 2014 - 02:41 AM

finally I cracked this issue now.. thank you for reading my post
Was This Post Helpful? 0
  • +
  • -

#3 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6823
  • View blog
  • Posts: 28,276
  • Joined: 12-December 12

Re: how to generate dynamic xml file based on field data

Posted 12 September 2014 - 02:45 AM

Glad you sorted. Note that there is a PHP forum which would have been more appropriate.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1