Jump to content
happycode

Erro ao ler o ficheiro XML

Recommended Posts

happycode

Bom dia,

Estou a importar produtos de um XML para o WooCommerce, onde está a dar o seguinte erro:

 

Citação

Failed loading XML Memory allocation failed Memory allocation failed : xmlSAX2Characters Memory allocation failed Extra content at the end of the document

No script de importação usava um ficheiro XML com 128MB e onde está tudo ok, agora no novo XML com actualização de preços dá o erro.

Bloco de código:

$xml_path 	= plugins_url( 'files/folder/file.xml', __FILE__ );
$xml 		= simplexml_load_file( $xml_path );

 

Alguém consegue indicar onde poderá estar a origem do problema?

Share this post


Link to post
Share on other sites
happycode

Continuo com o mesmo problema e ainda não consegui ultrapassar. 

Alguém consegue dar alguma dica?

function x_function() {
global $wpdb;
set_time_limit(0);

$xml_path   = $plugin_dir_path = dirname(__FILE__) . '/files/x/file.xml';
$xml        = simplexml_load_file( $xml_path ) or die( 'Error: Cannot create object' );

$row = 0;

foreach( $xml->structure as $data ) {
    $row++; 
    $id         = (string)$data->id;
    $name       = (string)$data->name;
    $parent_id  = (string)$data->parentid;

    $check_exist = $wpdb->get_var( "SELECT COUNT(id) FROM table Where id='$id'" );

    if ( $check_exist == '0' AND $parent_id == '1' ) {
        $cat_insert = wp_insert_term( $name, 'product_cat' );
        if ( ! is_wp_error( $cat_insert ) ) {
            $cat_id = isset( $cat_insert['term_id'] ) ? $cat_insert['term_id'] : 0;
        }
    }

    if ( $check_exist == '0' AND $parent_id != '1' ) {
        $get_parent = $wpdb->get_var( "SELECT category FROM table Where id='$parent_id'" );
        $cat_insert = wp_insert_term( $name, 'product_cat', array( 'parent' => $get_parent ) );
        if ( ! is_wp_error( $cat_insert ) ) {
            $cat_id = isset( $cat_insert['term_id'] ) ? $cat_insert['term_id'] : 0;
        }
    }

    if ( isset($cat_id) ) {
        $save_id = $wpdb->get_var( "INSERT INTO table (id, category) VALUES ('$id', '$cat_id')" );
    }
}
}

 

 

DMNwJ.jpg

 

9hZmc.jpg

 

Share this post


Link to post
Share on other sites
M6

Confirma se o teu XML tem um nó raiz que encapsula tudo.


10 REM Generation 48K!
20 INPUT "URL:", A$
30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50
40 PRINT "404 Not Found"
50 PRINT "./M6 @ Portugal a Programar."

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.