doc1355 Posted August 29, 2008 Share Posted August 29, 2008 I have a process.php with the following code: <?php $xdoc = new DomDocument; $xdoc->Load('1.xml'); $test = $xdoc->save("2.xml"); ?> It should load 1.xml file, and saves it as 2.xml. Here is my 1.xml file: <?xml version="1.0" encoding="UTF-8"?> <products> <product> <sku>10001</sku> <ti>Searchlight</ti> <qty>3</qty> <price>822.51</price> <st>1</st> </product> <product> <sku>10002</sku> <ti>Radio</ti> <qty></qty> <price>320.86</price> <st></st> </product> </products> and here is my 2.xml: <?xml version="1.0" encoding="UTF-8"?> <products> <product> <sku>10001</sku> <ti>Searchlight</ti> <qty>3</qty> <price>822.51</price> <st>1</st> </product> <product> <sku>10002</sku> <ti>Radio</ti> </qty> <price>320.86</price> </st> </product> </products> When I look at 2.xml, if there was a child element that had no value (<qty> and <st>) in 1.xml, it shows only as </qty> and </st> in 2.xml. The opening tag is not there. Is there anything I'm doing worng ? how can I fix this? Thanks Link to comment https://forums.phpfreaks.com/topic/121911-solved-missing-xml-opening-tag/ Share on other sites More sharing options...
FIREBALL5 Posted August 29, 2008 Share Posted August 29, 2008 So I'm guessing that your code there only copies the XML file? Link to comment https://forums.phpfreaks.com/topic/121911-solved-missing-xml-opening-tag/#findComment-629037 Share on other sites More sharing options...
doc1355 Posted August 29, 2008 Author Share Posted August 29, 2008 Will, my origianl code is much more than this. It adds attributes to the 2.xml. But I removed those extra codes only to prevent confusion here. The aboce code should copy the xml without change, but it is dropping the opeing tags for empty attributes. You can try above codes and see the result. Link to comment https://forums.phpfreaks.com/topic/121911-solved-missing-xml-opening-tag/#findComment-629045 Share on other sites More sharing options...
BlueSkyIS Posted August 29, 2008 Share Posted August 29, 2008 my output, with tags closed: <?xml version="1.0" encoding="UTF-8"?> <products> <product> <sku>10001</sku> <ti>Searchlight</ti> <qty>3</qty> <price>822.51</price> <st>1</st> </product> <product> <sku>10002</sku> <ti>Radio</ti> <qty/> <price>320.86</price> <st/> </product> </products> Link to comment https://forums.phpfreaks.com/topic/121911-solved-missing-xml-opening-tag/#findComment-629049 Share on other sites More sharing options...
doc1355 Posted August 29, 2008 Author Share Posted August 29, 2008 Yes, if you check the second product, it shows only <st/> and <qty/>. Is this correct or it should look like this: <st></st> <qty></qty> Link to comment https://forums.phpfreaks.com/topic/121911-solved-missing-xml-opening-tag/#findComment-629057 Share on other sites More sharing options...
DarkWater Posted August 29, 2008 Share Posted August 29, 2008 TECHNICALLY, empty elements can be written as <elem_name />, such as <img /> or a line break, so I guess it's correct. Link to comment https://forums.phpfreaks.com/topic/121911-solved-missing-xml-opening-tag/#findComment-629076 Share on other sites More sharing options...
doc1355 Posted August 29, 2008 Author Share Posted August 29, 2008 Thanks, That is all I wanted to know. You guys rock with your quick responses. Link to comment https://forums.phpfreaks.com/topic/121911-solved-missing-xml-opening-tag/#findComment-629078 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.