0

Hello I want to send xml values to a database I just created, here is the xml file


<record>
<name>tcpmux</name>
<protocol>tcp</protocol>
<xref type="person" data="Mark_Lottor"/>
<description>TCP Port Service Multiplexer</description>
<number>1</number>
</record>
<record>
<name>tcpmux</name>
<protocol>udp</protocol>
<xref type="person" data="Mark_Lottor"/>
<description>TCP Port Service Multiplexer</description>
<number>1</number>
</record>

I've got 4 columns in my database:- ServiceName, PortNumber, TransportProtocol and Description and I need to send the name, protocol, description and number of each record to my database. I'm new to XML so your help will be highly appreciated.

Thanks in advance!!!

2
Contributors
2
Replies
9
Views
5 Years
Discussion Span
Last Post by shashik493
0

Sorry I forgot to mention that I was able to print the dat onto my screen for viewing.

<?php

$xml = simplexml_load_file('C:\view-source [url]www.iana.org[/url] assignments service-names-port-numbers service-names-port-numbers.xml')
or die("Could Not Open The TEXT File<hr /> ");

    foreach($xml->children() as $child)
      {
        foreach($child->children() as $young)
        {
            echo $young->getName() . ": " . $young . "<br />";           
        }    

        echo "<br />"; 

      }

Now all I need is to send the records to MySQL.

Thanks in advance.

Edited by Nick Evan: Fixed formatting

0

INSERT XML TO DB

foreach($xml->business as $row)
{
  $business_type = $row->attributes()->type;
  $id = $row->listingAgent->attributes()->id;
  $name = $row->listingAgent->name;
  $email = $row->listingAgent->email;
  mysql_query('INSERT INTO tableā€¦');
}



        this is useful to use.
        shashi
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.