Pranav
Pranav

Reputation: 143

simplexml_load_string warnings

I am using simplexml_load_string function of php to convert xml string into object that can be used for futhur processing.

I code like this :

simplexml_load_string( $strXml, NULL, LIBXML_NOWARNING );

gives warning messages but executes it properly.

Where as if i code like this :

simplexml_load_string( $strXml, NULL, LIBXML_ERR_NONE );

failed to execute service.

I have already tried for LIBXML_ERR_NONE, LIBXML_ERR_ERROR.

Is there any way to get the object but without warning messages?

Upvotes: 1

Views: 3141

Answers (2)

ymiraola
ymiraola

Reputation: 140

This works for me.

simplexml_load_string($strXml, 'SimpleXMLElement', LIBXML_NOWARNING | LIBXML_NOERROR);

Upvotes: 3

Eva H. J.
Eva H. J.

Reputation: 11

You can suppress these errors by calling libxml_use_internal_errors.

libxml_use_internal_errors (true);
$xml = simplexml_load_string($user_input);
if (!$xml) {
    $xml_errors = libxml_get_errors();
    foreach ($xml_errors as $err) {
        var_dump($err);
    }
    libxml_clear_errors();
}

You might also want to check out libxml_get_errors and libxml_clear_errors

Upvotes: 1

Related Questions