2

I'm trying to create a rss feed and one element is

<content:encoded></content:encoded>

But, when i use this code:

$item->addChild('content:encoded',htmlspecialchars($itemdata->description));

I get this as a result:

<encoded> .................. </encoded>

I don't get the content namespace, and how would I be able to?

0

1 Answer 1

2

As you can see in the documentation, you need to provide the namespace URI as 3rd argument of addChild() to create element in namespace correctly :

$item->addChild(
        'content:encoded',
        htmlspecialchars($itemdata->description),
        'namespace-URI-for-content-prefix-here'
    );

Quick demo :

$raw = '<root xmlns:content="mynamespace"></root>';
$item = new SimpleXMLElement($raw);
$item->addChild(
          'content:encoded',
          'foo bar baz',
          'mynamespace'
      );
echo $item->asXML();

eval.in demo

output :

<?xml version="1.0"?>
<root xmlns:content="mynamespace"><content:encoded>foo bar baz</content:encoded></root>
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.