I've got the following problem and I can't find my mistake probably?
I try load the following XML(Over 15k Lines) Structure:
<Config>
<SystemFiles>
<Core>
<Info>
<Network>
<Capture>
<Store>
<Mount01>
<Mount02>
</Store>
</Core>
</Config>
I need access to the Substructure of Store with each Child of it. My function looks like:
public static function get_storage_data()
{
if(file_exists('/var/www/content/data/data.xml')) :
$xml = simplexml_load_file('/var/www/content/data/data.xml');
foreach ($xml->Config->Core->Store->children() as $mount) {
echo $mount;
}
else:
write_log(sprintf("data.xml not found"));
endif;
}
Which generates the following errors (Line 8 is the foreach line):
Notice
: Trying to get property 'Store' of non-object in
/var/www/inc/storage.inc
on line
8
Fatal error
: Uncaught Error: Call to a member function children() on null in /var/www/inc/storage.inc:8 Stack trace: #0 /var/www/storage.php(30): Storage::get_storage_data() #1 {main} thrown in
/var/www/inc/storage.inc
on line
8
What did I forget here or what is my mistake? Thanks!
You don't need to include the root node name when using SimpleXML to parse XML - it's already anchored at that level.
You should just be able to change the path from
$xml->Config->Core->Store->children()
to
$xml->Core->Store->children()
Note: I'm assuming that your <Mount01> and <Mount02> nodes just contain text content, since you won't be able to echo them otherwise.
See here for a worked example: https://eval.in/1006543
Related
I like to use the list on this page: list of teams of soccerclub
But I always get this error
Fatal error: Uncaught Error: Call to a member function find() on null in /home/u562375926/domains/lucswebsite.tech/public_html/resp/scrapvv.php:152 Stack trace: #0 {main} thrown in /home/u562375926/domains/lucswebsite.tech/public_html/resp/scrapvv.php on line 152
using this code:
<?php
include('simple_html_dom.php');
$file = 'https://www.voetbalvlaanderen.be/club/1771/ploegen';
$html = new simple_html_dom();
$html->load_file($file);
$club = $html->find('div',8)->find(h2);
echo $club. '<br>';
?>
I have used the same page in ParseHub and I get all a hrefs and the text of the corresponding spans.
Is it possible that DOM is not working on that page?
i am really having trouble getting this to work. xpath works fine in other functions in the same file. I am trying to get a specific item from the XML file, which works fine when i dd() it. But when i try to load the exact same code into a variable it prompts "undefined offset 0". I am working local with Laravel.
XML
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<idPkg:Graphic xmlns:idPkg="http://ns.adobe.com/AdobeInDesign/idml/1.0/packaging" DOMVersion="15.1">
<Color Self="Color/u2a64f" Model="Process" Space="RGB" ColorValue="204 204 204" />
</idPkg:Graphic>
PHP
function getColor($colorID){ //$colorID = Color/u2a64f
$xml= simplexml_load_file('/Resources/Graphic.xml');
$colorNode = $xml->xpath('//Color[#Self="'.$colorID.'"]');
dd($colorNode[0]->attributes()->ColorValue);
/* outputs:
SimpleXMLElement {#316 ▼
+"0": "204 204 204"
}
*/
$fillColor = $colorNode[0]->attributes()->ColorValue; // Line of error
/* outputs:
ErrorException (E_NOTICE)
Undefined offset: 0
*/
return $fillColor;
}
EDIT:
what i just found out: when i replace the variable in xpath with the content of the variable it works.
function getColor($colorID){ //$colorID = Color/u2a64f
$xml= simplexml_load_file('/Resources/Graphic.xml');
// doesnt work
$path = '//Color[#Self="'.$colorID.'"]';
// does work
$path = '//Color[#Self="Color/u2a64f"]';
$colorNode = $xml->xpath($path);
dd($colorNode[0]->attributes()->ColorValue);
/* outputs:
SimpleXMLElement {#316 ▼
+"0": "204 204 204"
}
*/
$fillColor = $colorNode[0]->attributes()->ColorValue; // Line of error
/* outputs:
ErrorException (E_NOTICE)
Undefined offset: 0
*/
return $fillColor;
}
i just cant get my head around it... I am glad for any hints or help!
Nevermind i found the solution myself.
After checking my code again i saw that sometimes some XML nodes dont have the attribute FillColor. So i checked my param first if it is set and then proceed to xpath.
I've started writing a scraper for one site that will also have a crawler, since I need to go through some links, but I'm getting this error :
PHP Fatal error: Uncaught Error: Call to a member function find() on
null in D:\Projekti\hemrank\simple_html_dom.php:1129 Stack trace:
0 D:\Projekti\hemrank\scrapeit.php(37): simple_html_dom->find('ul')
1 D:\Projekti\hemrank\scrapeit.php(19): ScrapeIt->getAllAddresses()
2 D:\Projekti\hemrank\scrapeit.php(55): ScrapeIt->run()
3 {main} thrown in D:\Projekti\hemrank\simple_html_dom.php on line 1129
When I var_dump the $html variable I get the full html with all the tags, etc, that's why it's strange to me that it says "Call to a member function find() on null", when there's actually value in the $html. Here's the part of the code that's not working :
$html = new simple_html_dom();
$html->load_file($baseurl);
if(empty($html)){echo "HTTP Response not received!<br/>\n";exit;}
$links = array();
foreach ($html->find('ul') as $ul) {
if(!empty($ul) && (count($ul)>0))
foreach ($ul->find('li') as $li) {
if(!empty($li) && (count($li)>0))
foreach ($li->find('a') as $a) {
$links[] = $a->href;
}
else
die("NOT AVAILABLE");
}
}
return $links;
}
Is this a common problem with PHP simple HTML DOM parser, is there a solution or should I switch to some other kind of scraping?
I just searched for the lib you are using, this is line 1129:
return $this->root->find($selector, $idx, $lowercase);
So your error message is telling you that $this->root inside the class is null, therefore no find() method exists!
I'm no expert on the lib, as I use the awesome DOMDocument for parsing HTML, but hopefully this should help you understand what has happened.
Also, $html will never be empty in that code of yours, you already populated it when you instantiated it!
I suggest the following change:
$html->load_file($baseurl); to $html = file_get_html($baseurl);
On my VPS server it works with $html->load_file($baseurl); but on my dedicated local server it only works with $html = file_get_html($baseurl);
This solved my problem:
- Call to a member function find() on null
- simple_html_dom.php on line 1129
I'm trying upload a file using zend form. I've tried in so many ways but i'm getting the form post data with file name but file was not receiving. Here is my code
**My Form code**
public function testUploadForm(){
$imageviewScript = new Zend_Form_Decorator_ViewScript();
$imageviewScript->setViewScript('image_element.phtml');
$image_name = new Zend_Form_Element_File('image_name');
$image_name->setAttrib('enctype', 'multipart/form-data');
$image_name->addValidator('Extension',false,'jpg,png,gif');
$image_name->addValidator('Count', false, 1)
//$image_name->setRequired(true)
->addDecorator($imageviewScript)
->setDecorators($this->setFieldElementDecorators());
$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel('Submit')
->setAttrib('class', 'addbutton_6')
->removeDecorator('label')
->setDecorators($this->getRightSubmitDecorators());
$this->addElements(array($image_name,$submit));
}
In controller i'm using to receive data like
public function testuploadAction(){
$params= array();
$this->_form->testUploadForm();
if($this->getRequest()->isPost()){
$params= $this->getRequest()->getParams();
$upload= new Zend_File_Transfer_Adapter_Http();
$upload->setDestination(APPLICATION_PATH.'/../images/uploads/');
if($uploads->receive()) {
//Code to process the file goes here
$filesize = $upload->getFileSize('image_name');
print_r($file_size);exit;
} else {
$errors = $upload->getErrors();
}
//$formData = $_POST->getValues(); //be sure to call this after receive()
print_r($formData);exit;
//$file = $upload->getFileInfo();
// $filename = $upload->getFileName('image_name'); //optional info about uploaded file
}
$this->_form->populate($params);
$this->view->form= $this->_form;
}
when I tried to print the data it was showing warnings like below.
Notice: Undefined index: validators in C:\xampp\htdocs\XXXX\library\Zend\File\Transfer\Adapter\Abstract.php on line 493
Warning: array_search() expects parameter 2 to be array, null given in C:\xampp\htdocs\XXXX\library\Zend\File\Transfer\Adapter\Abstract.php on line 493
Notice: Undefined index: tmp_name in C:\xampp\htdocs\XXXX\library\Zend\File\Transfer\Adapter\Abstract.php on line 589
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\XXXX\library\Zend\Validate\File\Count.php on line 228
No Syntax errors nothing. Form was submitting properly but file was not receiving here.
I've changed the file element to Zend file element i'm getting below fatal error after submitting the form.
Fatal error: Uncaught exception 'Zend_File_Transfer_Exception' with message '"image_name" not found by file transfer adapter' in C:\xampp\htdocs\XXXX\library\Zend\File\Transfer\Adapter\Abstract.php:1254 Stack trace: #0 C:\xampp\htdocs\XXXX\library\Zend\File\Transfer\Adapter\Abstract.php(572): Zend_File_Transfer_Adapter_Abstract->_getFiles('image_name') #1 C:\xampp\htdocs\XXXX\library\Zend\Form\Element\File.php(435): Zend_File_Transfer_Adapter_Abstract->isValid('image_name') #2 C:\xampp\htdocs\XXXX\library\Zend\Form.php(1987): Zend_Form_Element_File->isValid('shreyansh-ipad ...', Array) #3 C:\xampp\htdocs\XXXX\application\controllers\CustomerController.php(41): Zend_Form->isValid(Array) #4 C:\xampp\htdocs\XXXX\library\Zend\Controller\Action.php(503): CustomerController->registerAction() #5 C:\xampp\htdocs\XXXX\library\Zend\Controller\Dispatcher\Standard.php(285): Zend_Controller_Action->dispatch('registerAction') #6 C:\xampp\htdocs\XXXXX\library\Zend\Controller\Front.php(934): Zend_Co in C:\xampp\htdocs\XXXXX\library\Zend\File\Transfer\Adapter\Abstract.php on line 1254
Can some one plz suggest why the files are not uploading for me. Thank you.
Finally I found the solution. It is happening due to the form encryption only. To achieve some sort of website design I'm echoing each field in the view file i.e, .phtml file. So there i'm using the normal form. Even I'm assigning the encryption type to zend form, it was not coming in the phtml form, so the file was not uploading now i set like
<form enctype="multipart/form-data" method="post" action="" >
Now it is working fine. Thanks
I am currently getting this error on one of my files:
/var/www/vhosts/httpdocs/generator/index.php on line 6
Line 6 would be resulting in:
echo $results->GetBookCodesResult->BookCodes->BookInfo->ServiceCode;
My code:
<?php
$config['soap_url'] = "http://myservice.com?WSDL";
if(isset($_REQUEST['codes'])) {
$results = request_Data(explode("\n",$_REQUEST['codes']));
echo $results->GetBookCodesResult->BookCodes->BookInfo->ServiceCode;
}
....
What is the best method to have this fixed? Some advice would be appreciated.
your "->BookCodes" sub-property is empty as you can see in your var_dump-output...
this property "BookInfo" just not exist.. maybe no books are found? ;)