Link to home
Start Free TrialLog in
Avatar of Insoftservice inso
Insoftservice insoFlag for India

asked on

data fetch from xml

Hi,
following is the xml format which has to be rendered.
I want to know how to access the specific node and how to convert it into array.
Specially node name
' <application><clients>........ </clients></application>'.

<?xml version="1.0" encoding="UTF-8"?>
<clientApplication>
  <client_application_id>2</client_application_id>
  <client_id>1</client_id>
  <application_name>Intergamma</application_name>
  <application_desc>http://www.abc.com/chain=intergamma</application_desc>
  <application_url>http://www.abc.com/</application_url>
  <access_key>gamma</access_key>
  <ip_low>127.0.0.0</ip_low>
  <ip_high>127.0.0.1</ip_high>
  <default_i18n_code></default_i18n_code>
  <is_active>Y</is_active>
  <created></created>
  <modified></modified>
  <createdby></createdby>
  <modifiedby></modifiedby>
  <clients><user_id>1</user_id><role_id>1</role_id><prefix>mr</prefix><first_name>xyz</first_name><middle_name>r</middle_name><last_name>nag</last_name><email>abc@ya.com</email><username>test</username><is_active>Y</is_active><lastlogin_IP></lastlogin_IP><lastlogin></lastlogin><company_name>Intergamma</company_name><contact_person_name>jj</contact_person_name><address1>amsterdam</address1><address2>netherland</address2><zipcode></zipcode><phone2></phone2><mobile></mobile><phone1></phone1><email1></email1><email2></email2><logo></logo><website></website></clients>
  <modules><module_permission_id>1</module_permission_id><module_id>1</module_id><permission_code>VIEW</permission_code><created></created><modified></modified><module_title>TESTER</module_title><module_desc></module_desc><module_link></module_link><module_icon></module_icon><module_help></module_help><is_active>Y</is_active><role_id>1</role_id><role_title>View</role_title><role_description></role_description><role_is_active>Y</role_is_active><client_application_id>1</client_application_id></modules>
  <application><clients><client_application_id>2</client_application_id><client_id>1</client_id><application_name>Intergamma</application_name><application_desc>http://www.abc.com/chain=intergamma</application_desc><application_url>http://www.abc.com/</application_url><access_key>gamma</access_key><ip_low>127.0.0.0</ip_low><ip_high>127.0.0.1</ip_high><default_i18n_code></default_i18n_code><is_active>Y</is_active><created></created><modified></modified><createdby></createdby><modifiedby></modifiedby></clients><clients><client_application_id>1</client_application_id><client_id>1</client_id><application_name>Gamma</application_name><application_desc>test</application_desc><application_url>http://www.abc.com/</application_url><access_key>intergamma</access_key><ip_low>127.0.0.0</ip_low><ip_high>127.0.0.1</ip_high><default_i18n_code>en</default_i18n_code><is_active>Y</is_active><created>0000-00-00 00:00:00</created><modified>0000-00-00 00:00:00</modified><createdby>1</createdby><modifiedby>1</modifiedby></clients><clients><client_application_id>3</client_application_id><client_id>1</client_id><application_name>Karwei</application_name><application_desc></application_desc><application_url>http://www.abc.com/</application_url><access_key>karwei</access_key><ip_low>127.0.0.0</ip_low><ip_high>127.0.0.1</ip_high><default_i18n_code></default_i18n_code><is_active>Y</is_active><created></created><modified></modified><createdby></createdby><modifiedby></modifiedby></clients></application>
</clientApplication>

Open in new window

SOLUTION
Avatar of vsudip
vsudip
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of Beverley Portlock
Beverley Portlock
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Insoftservice inso

ASKER

HI,

Please check my dummy code.
But its not working please let me know where i am wrong
$doc = new DOMDocument();
$doc->load( $xml );

//$books1 = $doc->getElementsByTagName( "clientApplication" );


$books = $books1->getElementsByTagName( "application" );
   foreach( $books as $book )
    {
	$authors = $book->getElementsByTagName( "clients" );
	$author = $authors->item(0)->nodeValue;

	$publishers = $book->getElementsByTagName( "client_application_id" );
	$publisher = $publishers->item(0)->nodeValue;

	$titles = $book->getElementsByTagName( "client_id" );
	$title = $titles->item(0)->nodeValue;

	echo "$title - $author - $publisher\n==";
  }

Open in new window

Hi,
thx @bportlock

and thx to all even i will try other method too.

it was perfect anwer what i wanted.
But actually i would not have actual name of the xml tag similar to application->clients.
Actually its converted to xml from numerative array and later it has to be again converted to array.
So, how to get tag name which is been developed from such type of array.
' <application><clients>........ </clients></application>'. was the actual example of it.
 
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thx to all.
Happy holi in advance.