/    Sign up×
Community /Pin to ProfileBookmark

Problem Retrieving XML Data

I can’t really seem to read my XML file and get the data. Or, really, I can’t seem to read the data and put it in a var.

Below is my php file, and below that is my xml file.

[code=php]
<?php

$name = “Foo”;
$redirvars = “user=Foo&id=Foo”;
$holdsendurl .= “http://www.foo.com/welcome.html?” . “{$redirvars}”;

$default_dir = “loggedusers.xml”;

$xmlstr = simplexml_load_file($default_dir);

//var_dump($xmlstr);

$dom = new domDocument;

$dom->loadXML($xmlstr);

$s_dom = simplexml_import_dom($dom);

$usrstr = “”;

foreach($s_dom->loggeduser[0]->username as $gname)
{
$usrstr .= “<username>” . “{$gname}” . “</username>”;
}

$usrstr .= “<username>” . “{$name}” . “</username>”;

$xmlstr = “<?xml version=’1.0′ encoding=’UTF-8′ ?><loggeduser>” . “{$usrstr}” . “</loggeduser>”;

$dom2 = new domDocument;

$dom2->loadXML($xmlstr);

$test = $dom2->save(“loggedusers.xml”);

echo “<br>hello World!<br><br><textarea>”.$usrstr.”</textarea>”;

?>
[/code]

[code=php]
<?xml version=”1.0″ encoding=”UTF-8″?>
<loggeduser>
<username>Foo</username>
</loggeduser>
[/code]

Whenever the php runs, it will simply save this exact file, but it should add a ‘Foo’ user to the list. Or at least that is what I want it to do.

It seems that it does not read the ‘username’ and get the list of users, then save them to the variable for me to save again.

any ideas?

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@Sup3rkirbyauthorJul 22.2007 — ....I didn't think this was complicated or anything, I'm just new with PHP.

Does anyone know how to properly read XML with PHP?
×

Success!

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