Go Back   kirupaForum > Flash > Flash IDE

Reply
 
Thread Tools Display Modes
Old 12-23-2009, 02:21 AM   #1
pete_s
Registered User
Flash + XML parse question

I have put together a simple flash that parses some text from a very simple XML, and it works just fine. Here is how the XML looks like
Code:
<result>
        <header>text</header>
        <content>text text</content>
        <info>text text text</info>
        <link>http://www.google.com</link>               
</result>
Now I would like the flash to make a difference between 3 different <types> tags in the XML. Then parse it togheter, but depending on witch <type> you choose it becomes slightly different in the layout. This is how the XML looks like
Code:
<result>
        <type>layout1</type>
        <header>text</header>
        <content>text text</content>
        <info>text text text</info>
        <link>http://www.google.com</link>       
</result>
<result>
        <type>layout2</type>
        <header>text</header>
        <content>text text</content>
        <info>text text text</info>
        <price>100</price>
        <link>http://www.google.com</link>       
</result>
<result>
        <type>layout3</type>
        <header>text</header>
        <content>text text</content>
        <info>text text text</info>
        <price>100</price>
        <units>100</untis>
        <link>http://www.google.com</link>       
</result>
My actionscript that parses the "simple" XML looks like this right now
Code:
function processXMLData(success)
{
        if (success)
        {
                var rootNode=this.firstChild;

                var headerNode=findNode(rootNode, "header");
                header=getValue(headerNode);
                
                var contentNode=findNode(rootNode, "content");
                content=getValue(contentNode);
                
                var infoNode=findNode(rootNode, "info");
                info=getValue(infoNode);
                
                var linkNode=findNode(rootNode, "link");
                link=getValue(linkNode);
                
        }
        else
        {
                content="Not found";
        }
}

function getValue(node)
{
  if (node && node.firstChild)
          return node.firstChild.nodeValue;
  return "";
}

function findNode(node, nodeName)
{
        if (node.nodeName==nodeName)
                return node;
        for (var i=0; node.childNodes && i<node.childNodes.length; i++)
        {
                var foundNode=findNode(node.childNodes[i], nodeName);
                if (foundNode!=null)
                        return foundNode;
        }
        return null;
}

link_btn.onRelease = function() {
                getURL(link, "_blank");
};
        
var xmlData=new XML();
xmlData.ignoreWhite=true;
xmlData.onLoad=processXMLData;
xmlData.load("info.xml");
stop();
Dose anyone have any suggestions or tutorials on how to do the things i like to do?
pete_s is offline   Reply With Quote

Sponsored Links (Guests Only) - Register | Need Help?

Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

Forum Jump


All times are GMT -4. The time now is 03:24 AM.

SHARE:

SUPPORTERS:

cdn
content delivery network (cdn)

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd. Copyright 2010 - kirupa.com Copyright 2010 - kirupa.com