Category : xml

Im using SimpleXMLElement as follows: $xml = new SimpleXMLElement(‘<?xml version="1.0" encoding="UTF-8"?><xml></xml>’); $xml->addChild(‘tests’); Then im trying to add individual tests inside of the above like so: foreach($tests as $test){ $node1 = $xml->tests->addChild(‘test’); $node1->addAttribute(‘name’, $test[0]); $node1->addAttribute(‘example’, $test[1]); $subnode1 = $node1->addChild(‘header’); $subnode1->addAttribute(‘example’, ‘example’); } echo $xml->asXML(); I want the finished output to look like the following: <?xml version="1.0" ..

Read more

If I put a ‘&’ character to the SimpleXMLElement::addChild() method value parameter, the following error occured: Warning: SimpleXMLElement::addChild(): unterminated entity reference in No error, if I convert the value with htmlspecialchars function. Why do I need to convert the value, why not convert the addchild method automatically? Sourc..

Read more

I wrote this script to create an XML of my WooCommerce products: <?php require_once( $_SERVER[‘DOCUMENT_ROOT’] . ‘/wp-load.php’ ); $NS = array( ‘g’ => ‘http://base.google.com/ns/1.0’ ); $xml = new SimpleXMLElement(‘<rss xmlns:g="http://base.google.com/ns/1.0" version="2.0"/>’); $channel = $xml->addChild(‘channel’); $channel->addChild(‘title’, "Site title"); $channel->addChild(‘link’, "https://www.example.com"); $channel->addChild(‘description’, "Site description"); $query = new WP_Query( array( ‘post_type’ => ‘product’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => ..

Read more

i’m create own rss feed file in PHP and display unicode in xml tags that display ???? my code is below any one help me please <?PHP $databaseHost = ‘localhost’; $databaseName = ‘db’; $databaseUsername = ‘name11’; $databasePassword = ‘pass11’; $mysqli = mysqli_connect($databaseHost, $databaseUsername, $databasePassword, $databaseName); $mysqli->set_charset(‘utf8mb4’); // object oriented style mysqli_set_charset($link, ‘utf8mb4’); // procedural style ..

Read more

I’m trying to transform XML into Json with PHP. I have in input an XML file (file.xml) with a recursive structure and I would like to transpose it into Json (out.json). The graph contains a repeated recursive node: xml file sample: <Transfer> <Name>Transfer</Name> <Title>Transfer + Date</Title> <Level> <Name>Item 1</Name> <Title>Title 1</Title> <className>middle-level</className> <Level> <Name>Item 1.1</Name> ..

Read more

<?php $id =$_GET[‘book’]; if(filter_var($id,FILTER_VALIDATE_INT)) { if (file_exists(‘db.xml’)) { $xml = simplexml_load_file(‘db.xml’); echo $xml->book[$id]->title; //display empty string, $id=0 echo $xml->book[0]->title; //display correct string } ?> Why using a parameter doesn’t work? What am I doing wrong? Thank you! Sourc..

Read more

I want to sort all datas i get from xml files. How can i sort order by asc as "$myLink->Tanim"(Brand Name) or others. // Ignore this line // Ignore this line My Xml File <?xml version="1.0" encoding="utf-8"?> <Markalar> <Marka> <MarkaID>1</MarkaID> <Tanim>NUXE</Tanim> </Marka> <Marka> <MarkaID>2</MarkaID> <Tanim>Markasız</Tanim> </Marka> <Marka> <MarkaID>3</MarkaID> <Tanim>MUSTELA</Tanim> </Marka> <Marka> <MarkaID>4</MarkaID> <Tanim>SOLGAR</Tanim> </Marka> <Marka> ..

Read more

I have a rather large xml file that contains 70-80k products that I am using to store in a mysql database as: $xmlfile = "a-url-of-xml-file.xml"; $doc = new DOMDocument(); $doc->load($xmlfile); $arrFeeds = array(); foreach ($doc->getElementsByTagName(‘Item’) as $node) { $itemRSS = array ( ‘sku’ => $node->getElementsByTagName(‘ItemCode’)->item(0)->nodeValue, ‘stock’ => $node->getElementsByTagName(‘Available’)->item(0)->nodeValue, ‘price’ => $node->getElementsByTagName(‘Price’)->item(0)->nodeValue ); array_push($arrFeeds, $itemRSS); } ..

Read more