Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

General Discussions


You are currently viewing our General Discussions as a guest. Please register to participate.
Login



Reply
Help me with XML feeds
Old 07-31-2006, 02:19 AM Help me with XML feeds
epithet's Avatar
Experienced Talker

Posts: 30
Trades: 0
Is there anyone in here who knows about xml feeds? Anyone who knows a good deal of sources to read or something that can give out a sample written code?

Thanks guys.
epithet is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-31-2006, 05:56 PM
Junior Talker

Posts: 10
Trades: 0
I am also needy of XML tuts. I've found many through Google but they explain how to write hundreds of pages just to read an (unrelated) XML document
miseria is offline
Reply With Quote
View Public Profile
 
Old 07-31-2006, 07:09 PM
Lpspider's Avatar
Seniority Minority

Posts: 1,534
Trades: 0
Hate to be a third, but I've always been not so good with this... I'm interested in a little guidance too.
__________________
AdminAddict.com -
Please login or register to view this content. Registration is FREE
Lpspider is offline
Reply With Quote
View Public Profile Visit Lpspider's homepage!
 
Old 07-31-2006, 09:41 PM
dadofgage's Avatar
Extreme Talker

Posts: 224
Trades: 0
Try this code:

Code:
<?php
function GetXMLTree ($xmldata)
{
    // we want to know if an error occurs
    ini_set ('track_errors', '1');

    $xmlreaderror = false;

    $parser = xml_parser_create ('ISO-8859-1');
    xml_parser_set_option ($parser, XML_OPTION_SKIP_WHITE, 1);
    xml_parser_set_option ($parser, XML_OPTION_CASE_FOLDING, 0);
    if (!xml_parse_into_struct ($parser, $xmldata, $vals, $index)) {
        $xmlreaderror = true;
        echo "error";
    }
    xml_parser_free ($parser);

    if (!$xmlreaderror) {
        $result = array ();
        $i = 0;
        if (isset ($vals [$i]['attributes']))
            foreach (array_keys ($vals [$i]['attributes']) as $attkey)
            $attributes [$attkey] = $vals [$i]['attributes'][$attkey];

        $result [$vals [$i]['tag']] = array_merge ($attributes, GetChildren ($vals, $i, 'open'));
    }

    ini_set ('track_errors', '0');
    return $result;
}

function GetChildren ($vals, &$i, $type)
{
    if ($type == 'complete') {
        if (isset ($vals [$i]['value']))
            return ($vals [$i]['value']);
        else
            return '';
    }

    $children = array (); // Contains node data

    /* Loop through children */
    while ($vals [++$i]['type'] != 'close') {
        $type = $vals [$i]['type'];
        // first check if we already have one and need to create an array
        if (isset ($children [$vals [$i]['tag']])) {
            if (is_array ($children [$vals [$i]['tag']])) {
                $temp = array_keys ($children [$vals [$i]['tag']]);
                // there is one of these things already and it is itself an array
                if (is_string ($temp [0])) {
                    $a = $children [$vals [$i]['tag']];
                    unset ($children [$vals [$i]['tag']]);
                    $children [$vals [$i]['tag']][0] = $a;
                }
            } else {
                $a = $children [$vals [$i]['tag']];
                unset ($children [$vals [$i]['tag']]);
                $children [$vals [$i]['tag']][0] = $a;
            }

            $children [$vals [$i]['tag']][] = GetChildren ($vals, $i, $type);
        } else
            $children [$vals [$i]['tag']] = GetChildren ($vals, $i, $type);
        // I don't think I need attributes but this is how I would do them:
        if (isset ($vals [$i]['attributes'])) {
            $attributes = array ();
            foreach (array_keys ($vals [$i]['attributes']) as $attkey)
            $attributes [$attkey] = $vals [$i]['attributes'][$attkey];
            // now check: do we already have an array or a value?
            if (isset ($children [$vals [$i]['tag']])) {
                // case where there is an attribute but no value, a complete with an attribute in other words
                if ($children [$vals [$i]['tag']] == '') {
                    unset ($children [$vals [$i]['tag']]);
                    $children [$vals [$i]['tag']] = $attributes;
                }
                // case where there is an array of identical items with attributes
                elseif (is_array ($children [$vals [$i]['tag']])) {
                    $index = count ($children [$vals [$i]['tag']]) - 1;
                    // probably also have to check here whether the individual item is also an array or not or what... all a bit messy
                    if ($children [$vals [$i]['tag']][$index] == '') {
                        unset ($children [$vals [$i]['tag']][$index]);
                        $children [$vals [$i]['tag']][$index] = $attributes;
                    }
                    $children [$vals [$i]['tag']][$index] = array_merge ($children [$vals [$i]['tag']][$index], $attributes);
                } else {
                    $value = $children [$vals [$i]['tag']];
                    unset ($children [$vals [$i]['tag']]);
                    $children [$vals [$i]['tag']]['value'] = $value;
                    $children [$vals [$i]['tag']] = array_merge ($children [$vals [$i]['tag']], $attributes);
                }
            } else
                $children [$vals [$i]['tag']] = $attributes;
        }
    }

    return $children;
}
$url = "http://www.yourdomain.com/test.xml"; //URL of the XML FEED

$contents = file_get_contents($url);

$data = GetXMLTree ($contents);
print_r($data);


?>
Toward the bottom of this you can just put in your URL that you are trying to parse/read.

That will get the XML into a PHP array that you can then do with what you want.

If you are not a PHP guy, you will need to comment out the print_r($data); line as well once you see that it works.

Source: http://www.zend.com/codex.php?id=1455&single=1
__________________

Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE
dadofgage is offline
Reply With Quote
View Public Profile Visit dadofgage's homepage!
 
Old 08-01-2006, 02:29 AM
Ultra Talker

Posts: 406
Trades: 4
what exactly are you trying to do with the xml? that's the important part.
briansol is offline
Reply With Quote
View Public Profile Visit briansol's homepage!
 
Old 08-01-2006, 04:30 AM
epithet's Avatar
Experienced Talker

Posts: 30
Trades: 0
To Briansol:

I'll be working with someone who will install some SEs into an interface that would generate us some data. After installation, I will be assigned to write xml to combine the data and present them to previous interface. Unfortunately, this will be my firs time to work on xml feeds. A few exmaples as to how it looks like and how it functions would be very helpful.

To dadofgage:

I'll be keeping the sample codes and see where can I specifically include that in my work. Thanks! Great tip! Hope it will work.

By the way, do all programmers in this universe know all about xml feeds?
epithet is offline
Reply With Quote
View Public Profile
 
Old 08-01-2006, 08:08 AM
dadofgage's Avatar
Extreme Talker

Posts: 224
Trades: 0
Quote:
By the way, do all programmers in this universe know all about xml feeds?
Pretty much, yes.
__________________

Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE
dadofgage is offline
Reply With Quote
View Public Profile Visit dadofgage's homepage!
 
Old 08-08-2006, 04:26 AM
epithet's Avatar
Experienced Talker

Posts: 30
Trades: 0
Hello dadofage!

I used the codes you have provided. So far I haven't received any feedback yet but I am hoping that it's the right code to get what what my client really wanted me to work on.

Regarding my question, all of my programmer friends gave me RSS thingy for this query. Am I right in saying that xml feeds are written as RSS feeds?
epithet is offline
Reply With Quote
View Public Profile
 
Old 08-08-2006, 12:32 PM
Plugin-Developer's Avatar
Weightlifting CS Student

Posts: 504
Name: Nick Ohrn
Trades: 0
Quote:
Originally Posted by epithet View Post
Hello dadofage!

I used the codes you have provided. So far I haven't received any feedback yet but I am hoping that it's the right code to get what what my client really wanted me to work on.

Regarding my question, all of my programmer friends gave me RSS thingy for this query. Am I right in saying that xml feeds are written as RSS feeds?
I may be incorrect, but I believe that RSS feeds are just a form of XML. XML is very, very versatile, because you can tag content as anything you want, formulate your own structure,and produce a reader to analyze it. RSS, I believe, is just a standard type of XML file that is produced. Again, however, I could be wrong.

-Nick
__________________

Please login or register to view this content. Registration is FREE
- Custom plugin development to fit your needs. Plugins available for WordPress and Drupal, among others.
Plugin-Developer is offline
Reply With Quote
View Public Profile Visit Plugin-Developer's homepage!
 
Old 08-08-2006, 11:11 PM
$100 - $999 Monthly

Posts: 20
Trades: 0
Quote:
Originally Posted by nickohrn View Post
I may be incorrect, but I believe that RSS feeds are just a form of XML. XML is very, very versatile, because you can tag content as anything you want, formulate your own structure,and produce a reader to analyze it. RSS, I believe, is just a standard type of XML file that is produced. Again, however, I could be wrong.
That's correct. RSS is a standard method of using XML for a feed.
Much like HTML (technically XHTML) is a standard method of interface design with XML.

I think really the only tough thing when it comes to coding scripts/apps that mess with XML is you need to have a proper understanding of parent/child/root nodes. If you get that and have good general coding knowledge (particularly loops), you should find it relatively easy coding.
Kyle J is offline
Reply With Quote
View Public Profile
 
Old 08-17-2006, 04:37 AM
epithet's Avatar
Experienced Talker

Posts: 30
Trades: 0
It's the other way. An rss feed is basically an xml document that is created in accordance with the rss specification.

If you fancy a read this is probably the best source of info i have found on rss specs blogs dot law dot harvard dot edu slash tech slash rss.
epithet is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Help me with XML feeds
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.47076 seconds with 12 queries