1

I do query an oracle database for a field that stores xml content using blob data type

I want to generate a string to pass as parameter to a simplexml_load_string function.

I am receiving the resource type:

object(OCI-Lob)[111]
  public 'descriptor' => resource(118, oci8 descriptor)

And using this code :

$query = "SELECT xmlcontent FROM myxmltable";
$stid = oci_parse($conn, $query);
            oci_execute($stid);

            $xml = '';

            while (($row = oci_fetch_assoc($stid)) != false) {

                // $xml = simplexml_load_string($row['XML']);
                $xml = $row['xmlcontent'];

            }

            var_dump($xml);

How can i transform resource to a string ?

The XML i wanto to turn from object to string is :

<?xml version="1.0" encoding="utf-8"?>
<VehicleValidation xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <Validation Id="Validation">
        <Vehicle>
            <Year>2017</Year>
            <Brand>One car brand</Brand>
        </Vehicle>

        <Brand>
            <Info>
                <Data>
                    <Address>
                    One car brand Address
                    </Address>
                <Data>
            </Info>
        </Brand>
    </Validation>
</VehicleValidation>
6
  • Can you share your XML string and your expected output? Commented Jun 1, 2017 at 17:48
  • Just add the XML to the question Commented Jun 1, 2017 at 18:15
  • Can you tell me what you want to extract from this XML? Commented Jun 1, 2017 at 18:16
  • Are you storing the XML as a BLOB or an XMLTYPE that is using BLOB under the covers. If you are using a BLOB you should migrate to XMLTYPE store as BINARY XML. Then you can get the serialized (textual) format using the XMLSerialize() operators. Commented Jun 1, 2017 at 18:18
  • Using Blob and storing XML will try to migrate to XMLTYPE, thank you Commented Jun 1, 2017 at 18:54

1 Answer 1

1

OCI-Lob is a class that provides various useful methods for interacting with the represented LOB content.

You can probably pass the result of the load method directly into simplexml_load_string:

$xml = simplexml_load_string($row['xmlcontent']->load());

Make sure to consider memory limitations as mentioned on the manual page:

As script execution is terminated when the memory_limit is reached, ensure that the LOB does not exceed this limit. In most cases it's recommended to use OCI-Lob::read instead.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.