0

The user creates a XML-file and stores it in the database as BLOB. Every XML-file gets its own row.

My script should query the Database and retrieve the XML-file of every row.

Every XML-file should be in an own php object and stored in an array. After that I need to access the DOM of every XML to display the data in an html template.

This is what I have got so far:

$stmt = $pdo->query('SELECT xml FROM table');

foreach ($stmt as $row)
{
    echo $row['xml'] . "\n";
}

It will output the information without the xml-tags. I wonder why. The problem is, I somehow need to access the DOM.

I read about

simplexml_load_file

but it needs a filepath, which I don't have because the files are stored as BLOB in the DB.

Thank you!

1 Answer 1

2

You can use simplexml_load_string instead...

$stmt = $pdo->query('SELECT xml FROM table');

foreach ($stmt as $row)
{
    $data = simplexml_load_string($row['xml']);
    echo "<pre>".$data->asXML()."</pre>";
}

The reason why you probably don't see the tags is that you are echoing them out to a HTML page, which tries to interpret them as HTML tags.

Not sure about how your doing your foreach as it would more commonly be written as

while ($row = $stmt->fetch(\PDO::FETCH_ASSOC))  // Add correct retrieval method your after
{
    $data = simplexml_load_string($row['xml']);
    echo "<pre>".$data->asXML()."</pre>";
}

This depends on the API and if your using your own class methods though.

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.