Reputation: 35
All good day. When using crxml repository, not correctly generated xml document. And that's what happens when you add a new element into the document. Course of action: To begin with I create document
$this->genXml->Item['Type'] = 'view';
$this->genXml->Item->{'http://'.$this->siteUrll.'|Name'} = 'Last View';
$this->genXml->Item->LastView->View->Time = $app['Time'];
$this->genXml->Item->LastView->View->Action = $app['Action'];
$this->genXml->Item->LastView->View->IP = $app['IP'];
return $this->genXml->xml();
and I get this kind of xml file
<?xml version="1.0" encoding="UTF-8"?>
<Item Type="view">
<Name xmlns="http://sitename.com">Last View</Name>
<LastView>
<View>
<Time>11:45:12</Time>
<Action>Click</Action>
<IP>192.168.1.1</IP>
</View>
</LastView>
</Item>
further to the finished result add new values
$GetFile = <<<EOB
<?xml version="1.0" encoding="UTF-8"?>
<Item Type="view">
<Name xmlns="http://sitename.com">Last View</Name>
<LastView>
<View>
<Time>11:45:12</Time>
<Action>Click</Action>
<IP>192.168.1.1</IP>
</View>
</LastView>
</Item>
EOB;
$this->genXml->loadXML($GetFile);
$this->genXml->Item->LastView->View[2]->Time = $app['Time'];
$this->genXml->Item->LastView->View[2]->Action = $app['Action'];
$this->genXml->Item->LastView->View[2]->IP = $app['IP'];
echo($this->genXml->xml());
and get the faulty code xml
<?xml version="1.0" encoding="UTF-8"?>
<Item Type="view">
<Name xmlns="http://sitename.com">Last View</Name>
<LastView>
<View>
<Time>11:45:12</Time>
<Action>Click</Action>
<IP>192.168.1.1</IP>
</View>
<View/><View><Time>11:45:12</Time><Action>Click</Action> <IP>192.168.1.1</IP></View></LastView>
</Item>
namely where the tag is
<View/>
Help solve a problem with the output. Maybe I am doing something wrong? (sorry for my English, I know im not as good as I would like) Just give the link to the repository and a description of the problem.
Upvotes: 2
Views: 63
Reputation: 359
It is somehow hilarious as it is a typical problem of Informatics. We like to start counting from 0. You created a first view with the ID 0 (implicit). If you now add a new view with the ID 2, it misses the ID 1 and simply inserts an empty view. The result is thereby syntactically correct.
You just have to change the index of the added view to 1 to prevent this.
Upvotes: 1