/    Sign up×
Community /Pin to ProfileBookmark

How to push data to database and publish at website from XML?

How to push data to database and pull at website from XML?

Example [B]structure for XML[/B]:

[code=php]

?xml version=”1.0″ encoding=”utf-8″?>
<rss version=”2.0″>

<channel>
<title>News ticket system</title>
<item>
<title>Google marketing</title>
<link>http://www.mydomain.com/</link>
<description>Short description</description>
<pubDate>Mon, 24 Jan 2011 14:20:01 GMT</pubDate>
<author>Mydomain.com</author>
</item>

</channel>
</rss>

[/code]

[B]News is published[/B] in HTML code like:

[code=php]

<table width=”450″ border=”0″ cellpadding=”0″ cellspacing=”0″>
<!– News 1 –>

<tr>
<td><span class=”news_date1″>24.01.2011</span>:<span class=”news_source1″>Source name</span></td>
</tr>
<tr>
<td class=”news_title1″>Title1</td>
</tr>
<tr>

<td class=”news_newsall1″>
<!–<h2></h2>–><br />
<strong>Short description:</strong>&nbsp;Short description<br />
<strong>Author:</strong>&nbsp;Author and his name<br />
<strong>Source:</strong>&nbsp;<br /><br />
<strong>Date of publish:</strong>24.01.2011<br /><br />
<div id=”image2″>
</div>
</td>
</tr>

</table>

[/code]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJan 19.2011 — The simple solution might be to grab one of the dozens of 3rd-party RSS/ATOM feed parsers out there, let it read the XML and dump it into an array or object, then it should be reasonably straight forward from there to loop through the data and insert it into your DB.
Copy linkTweet thisAlerts:
@toplisekauthorJan 20.2011 — I have read XML by feed parser:

<div class="item1" >

<h4><img class="favicon" alt="Favicon" src="/images/favicon/alternate.png"><a href="http://www.myydomain/">Title</a>&nbsp;<span class="footnote">20 Jan 2011, 7:20 am</span></h4>

Short description

</div>

How would you dump into object and store into database?
Copy linkTweet thisAlerts:
@toplisekauthorJan 21.2011 — I try with PHP manual:

http://www.php.net/manual/en/domdocument.loadxml.php

I put example XML:

?xml version="1.0" encoding="utf-8"?>

<rss version="2.0">


<channel>

<title>News ticket system</title>

<item>

<title>Google marketing</title>

<link>http://www.mydomain.com/</link>

<description>Short description</description>

<pubDate>Mon, 24 Jan 2011 14:20:01 GMT</pubDate>

<author>Mydomain.com</author>

</item>

</channel>

</rss>

Is correct code with DOM:
[code=php]



// Create a new DOMDocument object
$xmlDoc = new DOMDocument();

// Load XML from a file
$xmlDoc->load("myfiledom.xml");

// Search for all elements with tag name 'title'
$titles = $xmlDoc->getElementsByTagName('title');

// loop through titles and print all items
foreach ($titles AS $key => $title) {

// search for element 'item'
$item = $xmlDoc->getElementsByTagName('item');

// search for element 'link'
$link = $xmlDoc->getElementsByTagName('link');

// search for element 'pubDate'
$pubDate = $xmlDoc->getElementsByTagName('pubDate');

// search for element 'description'
$description = $xmlDoc->getElementsByTagName('description');


// search for element 'author'
$price = $xmlDoc->getElementsByTagName('author');

// print node value for all items
echo $title->item($key)->nodeValue . " = " . $item->item($key)->nodeValue . "<br />";
$link->item($key)->nodeValue . "<br />";
$pubDate->item($key)->nodeValue . "<br />";
$description->item($key)->nodeValue . "<br />";
$author->item($key)->nodeValue . "<br />";
}



[/code]
×

Success!

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