Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » XmlParser and <![CDATA[
XmlParser and <![CDATA[ [message #21260] Mon, 11 May 2009 03:24 Go to next message
iksobert is currently offline  iksobert
Messages: 6
Registered: August 2007
Promising Member
I haven't quite been able to figure this one out. I tried parsing some XML from an RSS feed, but it seems that the Parser discards any CDATA that it finds. Calling XmlNode::GetText() returns an empty string, and AsXml(XmlNode) returns the xml as an empty tag. Am I doing something wrong?

Here is simple snippet I made to demonstrate this:
#include "rssy.h"

#include <Web/Web.h>

rssy::rssy()
{
	CtrlLayout(*this, "No CDATA!");
	list.AddColumn("Text");
	list.AddColumn("XML");
	get_feeds();
}

void rssy::get_feeds(void)
{
	String out;
	HttpClient client;
	client.URL("http://losangeles.craigslist.org/search/jjj?query=php&format=rss");
	out=client.ExecuteRedirect();
	XmlNode n = ParseXML(out);
	const XmlNode &channel=n[0];
	int j;
	int tag;
	for(int i=channel.FindTag("item");i<channel.GetCount();i++) {
		if(channel[i].GetTag()!="item") continue;
		const XmlNode &item=channel[i];
		tag=item.FindTag("title");
		if(tag==-1) continue;
		const XmlNode &title=item[tag];
		j=list.GetCount()+1;
		list.SetCount(j);
		list.Set(j-1,0,title[0].GetText());
		list.Set(j-1,1,AsXML(item));
	}
}

GUI_APP_MAIN
{
	rssy().Run();
}

Re: XmlParser and <![CDATA[ [message #21262 is a reply to message #21260] Mon, 11 May 2009 08:37 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
ParseXML has second parameter that, in default form, makes it ignore anything but tags.

You can put there 0 to get all info from XML. Note, however, that in that case initial <? item also qualifies, so you can no longer use n[0].

#include <Web/Web.h>

using namespace Upp;

CONSOLE_APP_MAIN
{
	HttpClient client;
	client.URL("http://losangeles.craigslist.org/search/jjj?query=php&format=rss");
	String out = client.ExecuteRedirect();
	XmlNode n = ParseXML(out, 0);
	int q = n.FindTag("rdf:RDF");
	if(q >= 0) {
		const XmlNode& channel = n[q];
		for(int i = channel.FindTag("item"); i<channel.GetCount(); i++) {
			if(channel[i].GetTag() == "item") {
				const XmlNode &item=channel[i];
				int tag = item.FindTag("title");
				if(tag >= 0) {
					const XmlNode& title = item[tag];
					for(int j = 0; j < title.GetCount(); j++) {
						DUMP(title[j].GetType());
						DUMP(title[j].GetText());
					}
				}
			}
		}
	}
}


Mirek
Re: XmlParser and <![CDATA[ [message #21267 is a reply to message #21262] Mon, 11 May 2009 12:56 Go to previous message
iksobert is currently offline  iksobert
Messages: 6
Registered: August 2007
Promising Member
Thanks Mirek! i looked through XML.cpp, but i guess i completely overlooked the construct.

Cheers,
Trenton

[Updated on: Mon, 11 May 2009 13:55]

Report message to a moderator

Previous Topic: Proposal: add Vector::InsertPick(int i, pick_ T&)
Next Topic: date filter bug?
Goto Forum:
  


Current Time: Mon Apr 29 12:17:44 CEST 2024

Total time taken to generate the page: 0.02204 seconds