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!!!

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.

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.