/    Sign up×
Community /Pin to ProfileBookmark

Parse text from a variable block

I have a result that returns from an API that looks like so:

[CODE]
<serv:header><serv:response>
<serv:result>SUCCESS</serv:result><serv:gsbStatus>PRIMARY</serv:gsbStatus>
</serv:response></serv:header>
[/CODE]

There is more before and after the example I have given but the ones I want are the result and the gsbStatus.

Example of a failed call:

[CODE]
<serv:header><serv:response><serv:result>FAILURE</serv:result><serv:reason>WebExID or Email is already in use by this site.</serv:reason><serv:gsbStatus>PRIMARY</serv:gsbStatus><serv:exceptionID>030004</serv:exceptionID></serv:response>
[/CODE]

So I am trying to yank a couple of values out of here. First, the result. If it’s SUCCESS that’s all I need to retrieve. If it’s FAILURE I also need to grab the reason.

Was wondering if anyone would have a good way to do this.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJul 21.2009 — Assuming this data is XML with a "serv" namespace definition, you could use the [url=http://php.net/dom]DOM functions[/url] to retrieve the info (see [url=http://php.net/manual/en/domdocument.getelementsbytagnamens.php]DOMDocument::getElementsByTagNameNS[/url](), for instance).
Copy linkTweet thisAlerts:
@halldorrauthorJul 21.2009 — Ahhh excellent! I haven't worked with XML parsing much, thanks for the function! ?
×

Success!

Help @halldorr 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.9,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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