libxml and serialization

BlitzMax Forums/Brucey's Modules/libxml and serialization

plash(Posted 2008) [#1]
Is there an example for reading xml files that use serialization?

I'm going to read rss feeds, if anyone has experience doing that I'm looking for an example on that too.


plash(Posted 2008) [#2]
example of rss 2.0 feed

taken from www.hulu.com/feed/show/60/episodes


what is "<![CDATA[]]>"?


Brucey(Posted 2008) [#3]
A CDATA section is Character Data that is not parsed in the same way as the rest of the document.
It means, characters that are normally not allowed in XML (like < and > for example) can appear in the CDATA section.


Brucey(Posted 2008) [#4]
Assuming RSS feeds use the same structure, I'd start by creating an object that matches that structure.

Then write a little parser which maps the xml onto your object.

say you have a String containing the feed :
Local doc:TxmlDoc = TxmlDoc.parseDoc(text)
Local root:TxmlNode = doc.GetRootElement()

you might then pass the root node into a method of your mapper...
Method map:RSSObject(root:TxmlNode)
  Local channel:TxmlNode = TxmlNode(root.GetFirstChild())

  Local rss:RSSObject = new RSSObject

  For Local part:TxmlNode = eachin channel.getChildren()

    select part.GetName()

      case "title"
         rss.SetTitle(part.GetContent())


      case "item"
         mapItem(rss, part)

    end select

  Next

  return rss
End Method

Method mapItem(rss:RSSObject, parent:TxmlNode)

... etc

  rss.AddItem(item)

End Method



or something like that.


plash(Posted 2008) [#5]
Thanks Brucey!

this is a working rss feed reader example, it has an error on closing, but it works :)



Brucey(Posted 2008) [#6]
Nice :-)

Just a couple of tweaks to make it happy to run on Mac :

You need to remove wxLC_REPORT from the LCtr_ChannelItems create. Since you already have wxLC_LIST.

You shouldn't connect to wxEVT_CLOSE_WINDOW and then in the event handler called Window.Close(). Either, don't connect at all (it will automagically quit the app when the last window is closed), or instead call Window.Destroy().

:o)


plash(Posted 2008) [#7]
Try using this as the rss feed: http://www.nytimes.com/services/xml/rss/nyt/Technology.xml

Is there a way it can be a normal listbox (going down, instead of going on to the right)?

EDIT: wxHtmlWindow updated version, includes another problem, when displaying the description the image does not show, however in firefox (opening the "test.html" file) shows everything correctly.



DavidDC(Posted 2008) [#8]
Yes this data in the wrong column business vexed me as well. Never really found the solution. This (sort of) works.

[edited to add hscrollbar]

Oh, and you lose the first item, (it's in the invisible header) - so either dummy first item or create the header outside the for-next I guess.




plash(Posted 2008) [#9]
This will show them all:
 Local row:Int
			  Local ritem:rssItem, wxl:wxListItem = New wxListItem.Create() 
				wxl.SetData(Null) wxl.SetText("") wxl.SetId(row) wxl.SetColumn(0) 
				LCtr_ChannelItems.InsertColumnItem(0, wxl) 
				
			  row:+1
				For ritem = EachIn rchan.chnItems
				  wxl:wxListItem = New wxListItem.Create() 
					wxl.SetData(ritem) wxl.SetText(ritem.Title) 
					wxl.SetId(row) wxl.SetColumn(0) 
					
					LCtr_ChannelItems.InsertItem(wxl) 
					row:+1
					
					Print ritem.Description
					
				Next



DavidDC(Posted 2008) [#10]
Or even
Local row:Int = 1
LCtr_ChannelItems.InsertColumnItem(0, New wxListItem.Create())

:-) No idea re that other problem though. I'm seeing an image in Leopard? I did read somewhere on the wxWidgets lists that wxHtmlWindow was considered a little flakey. Not what we want to hear I know.


plash(Posted 2008) [#11]
I can't currently test it in Ubuntu, and I don't have a mac.