/    Sign up×
Community /Pin to ProfileBookmark

Php how to access CDATA

HI everyone,
anyone has an idea about how to access cdata in php here is the structure of my xml so you can have a clear idea
<call-handling id=”1″ code=”0″ name=”My status=”on”>
– <![CDATA[
<user-script><incoming-call status=”on”><anonymous-filter status=”off” baring-type=”voicemail”/>
<reject status=”off/></incoming-call></user-script>
]]>
</call-handling>

i need to access the tag reject for example . I am usign php5 and the Dom function
$dom = new DomDocument;
$dom->preserveWhiteSpace = FALSE;
$dom->loadXML($str);
$params = $dom->getElementsByTagName(‘reject’);
foreach ($params as $reject ) {
echo $reject -> getAttribute(‘status’);
}

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@bokehOct 16.2006 — Mark-up contained within cdata elements is cdata and not part of the DOM. As such the XML parser should completely ignore it.
Copy linkTweet thisAlerts:
@nihaauthorOct 16.2006 — great then what is the solution then! how can i get these tags ?

desperate me
Copy linkTweet thisAlerts:
@nihaauthorOct 16.2006 — ok i resolved it using this

$str = str_replace("<![CDATA[","",$str);

$str = str_replace("]]>","",$str);

$dom = new DomDocument;
$dom->preserveWhitespace = false;
$dom->loadXML($str);
$params = $dom->getElementsByTagName('reject');

foreach ($params as $reject )
{

echo $reject -> getAttribute('status');
}


thanks anyway
Copy linkTweet thisAlerts:
@chazzyOct 16.2006 — what happens when you just got the call handling as a text node?

nevermind, PHP's handling of XML seems very limited.

Also, bokeh's assertion while the end result is correct, the assertion is wrong. <![CDATA elements reside as part of the "DOMText" of an element. PHP has no way of retrieving the DOMText of an element it seems. You can try using DOMCharacterData -> substringData(offset...) to get it as well.

http://us3.php.net/manual/en/function.dom-domcharacterdata-substringdata.php

Why exactly is this additional dom document enclosed in CDATA in the first place? Is this some sort of plugin material?
Copy linkTweet thisAlerts:
@nihaauthorOct 17.2006 — well the xml is like that i cant change the structure i can ony retrieve. that is why i was in all this mess. the sbstring seems to be ok though. as far it is working it is ok !

Thanks anyway for your help.

Niha
×

Success!

Help @niha spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...