Results 1 to 6 of 6

Thread: Trying to parse simple XML with YUI, thinking WTF.

  1. #1
    Join Date
    Apr 2008
    Location
    San Diego, CA
    Posts
    352
    Thanks
    57
    Thanked 6 Times in 6 Posts

    Default Trying to parse simple XML with YUI, thinking WTF.

    Hi all.

    I want to use Yahoo's YUI DataSource utility to parse my XML data, but I'm having trouble understanding the parameters of the function that parses the data!

    YUI is really good about giving solid examples for their stuff, but an example for simple XML seems to have been overlooked. Here is the page where they provide examples:

    http://developer.yahoo.com/yui/datasource/

    And here is the ONLY documentation I could find anywhere of DataSource's parseXMLData method:

    http://developer.yahoo.com/yui/docs/...d_parseXMLData

    And finally, here is the code I have come up with based on those examples:

    Code:
    var invData = new YAHOO.util.DataSource("http://www.example.com/example.xml");
    invData.responseType = YAHOO.util.DataSource.TYPE_XML;
    
    invData.responseSchema = {
    	resultNode: "result",
    	fields: [
    			 	"vin",
    				"stock",
    				{key: "year", parser: YAHOO.util.DataSource.parseNumber}
    			]
    };
    
    var invListing = invData.parseXMLData(oRequest,oFullResponse);
    I'm stumped on what to do with oRequest and oFullResponse.

    Any help greatly appreciated! Oh, and happy Labor Day everyone!
    Last edited by jlizarraga; 09-01-2008 at 10:51 AM. Reason: typo

  2. #2
    Join Date
    Apr 2008
    Location
    San Diego, CA
    Posts
    352
    Thanks
    57
    Thanked 6 Times in 6 Posts

    Default

    Oh, and the XML:

    Code:
    <results>
    	<result
    		vin = "PCF168FC9LWIZPY"
    		stock = "2DTSZ"
    		year = "2008"
    	/>
    </results>

  3. #3
    Join Date
    Apr 2008
    Location
    San Diego, CA
    Posts
    352
    Thanks
    57
    Thanked 6 Times in 6 Posts

    Default

    So I think my problem stems from the fact that this DataSource utility was intended for making calls to a URL that produces different content depending on its parameters, whereas I'm using just using a completely static XML file.

    I'm now looking into these libraries:

    http://xmljs.sourceforge.net/

    http://dev.abiss.gr/sarissa/

    Any advice on which to use?

  4. #4
    Join Date
    Apr 2008
    Location
    San Diego, CA
    Posts
    352
    Thanks
    57
    Thanked 6 Times in 6 Posts

    Default

    Well, I decided against xmljs because it requires you to format the type of XML I'm loading in a weird way, so I'm going to try Sarissa. Results later!

  5. #5
    Join Date
    Apr 2008
    Location
    San Diego, CA
    Posts
    352
    Thanks
    57
    Thanked 6 Times in 6 Posts

    Default

    Okay, I've finally got access to my XML with this, which works great in FF and IE, but not in Safari:

    Code:
    function loadXMLDoc(dname) 
    {
    try //Internet Explorer
      {
      xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
      var oMSIE = true;
      }
    catch(e)
      {
      try //Firefox, Mozilla, Opera, etc.
        {
        xmlDoc=document.implementation.createDocument("","",null);
    	var oMSIE = false;
        }
      catch(e) {alert(e.message)}
      }
    try 
      {
      xmlDoc.async=false;
      xmlDoc.load(dname);
      if (oMSIE == false){
      	alert(xmlDoc.childNodes[0].nodeName);
      } else if (oMSIE == true){
      	alert(xmlDoc.childNodes[1].nodeName);
      }
      return(xmlDoc);
      }
    catch(e) {alert(e.message)}
    return(null);
    }
    
    var oXML = loadXMLDoc("http://autofusion.com/development/mm3/example_results/example_feed.xml"); // alerts "results" in FF and IE, "Value undefined (result of expression xmlDoc.load) is not object" in Safari.
    If anyone knows how to get this function working in Safari, it would be greatly appreciated!
    Last edited by jlizarraga; 09-01-2008 at 09:43 PM. Reason: typo

  6. #6
    Join Date
    Apr 2008
    Location
    San Diego, CA
    Posts
    352
    Thanks
    57
    Thanked 6 Times in 6 Posts

    Default

    Here is the W3C example, which produces the same error in Safari (3.1.2):

    http://www.w3schools.com/DOM/tryit.a...dom_loadxmldoc

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •