/    Sign up×
Community /Pin to ProfileBookmark

parsing xml in php

Can any one help me parsing this code in php
My Code:

[CODE]
<statement>

The following program will calculate the logarithm of x to the base b using the following formula: The source code missed some important keywords or reserved identifiers. Please complete the source code by filling the blanks using any of the following keywords or reserved identifiers: program, implicit, read, write, integer, real, character, log.
program logarithm
implicit none
real::b, x, result

<answer class=”inline”>write</answer>(*,*) “please enter the base of the logarithm:”
<answer class=”inline”> read</answer>(*,*) b
<answer class=”inline”>write</answer>(*,*) “please enter the input value of x for its log with the above base”
<answer class=”inline”> read</answer>(*,*) x
write(*,*) “Now I will calculate log_b(x) for you:”
result = log(x)/log(b)
<answer class=”inline”>write</answer>(*,*) “The result is “, result
end program
</statement>

[/CODE]

I Know how to parse xml tags in php using simplexml_load_string my question is I want to extract all the above data into to php variable and at the time of parsing when ever I read <answer> tag I want to replace the whole tag with <input type=”text”>… More or less I want to display a filling the blank question on html page by parsing this xml file.

Thanks in advance

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@jonathanwkellyAug 16.2010 — You want to replace the <answer> node with an input? So the inputs will be nested inside of the <statement> node? You'd first need to start with some valid XML. What's the actual XML you want to parse and use?
Copy linkTweet thisAlerts:
@NogDogAug 16.2010 — Perhaps this could be a job for XSLT via the PHP [url=http://www.php.net/manual/en/book.xsl.php]XSL extension[/url]?
Copy linkTweet thisAlerts:
@CharlesAug 16.2010 — Perhaps this could be a job for XSLT via the PHP [url=http://www.php.net/manual/en/book.xsl.php]XSL extension[/url]?[/QUOTE]On the other hand it might be a better candidate for the [url=http://www.php.net/manual/en/book.xml.php]XML Parser[/url]. It all depends upon the complexity of the XML and your willingness to scratch your own head.
Copy linkTweet thisAlerts:
@jaligamasrauthorAug 20.2010 — Thanks all for replying this mail. Actually I solved this problem by using some regular expressions and parsing it with simple_load_string()
×

Success!

Help @jaligamasr 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.28,
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,
)...