NameSilo

Query on XML document

Spaceship Spaceship
Watch
Impact
0
Hi friends

I am working with PHP5 and have a requirement to select xml node on the base of parameter. My xml contains the list of country and it has child node of state list. Like this

HTML:
<?xml version="1.0" encoding="utf-8"?>
<country_list>
	<country id="US">
		<state>NY</state>
		<state>CA</state>
		<state>NJ</state>		
	</country>
	<country id="AU">
		<state>New South Wales</state>		
		<state>Victoria</state>				
		<state>Queensland</state>						
	</country>	
</country_list>

I want to get the xml like

HTML:
<country id="AU">
		<state>New South Wales</state>		
		<state>Victoria</state>				
		<state>Queensland</state>						
	</country>

Can anyone help me how can I achieve this?

thanks in advance.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
.US domains.US domains
PHP:
<?php

header('Content-type: text/xml');

$xml = new SimpleXMLElement('<?xml version="1.0"?><country_list> </country_list>');
$country = $xml->addChild('country');
$country->addAttribute('id', 'US');

$country->addChild('state', 'NY');
$country->addChild('state', 'CA');
$country->addChild('state', 'NJ');

echo $xml->asXML();

?>

Untested but modified from previous code.


Bruce
 
0
•••
Dynadot — .com Registration $8.99Dynadot — .com Registration $8.99
Appraise.net

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Payment Flexibility
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back