March 29, 2024, 02:22:27 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Mini XML class for Aurora and Emergence

Started by sapero, November 28, 2008, 02:10:32 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

sapero

November 28, 2008, 02:10:32 PM Last Edit: November 28, 2008, 02:52:41 PM by sapero
I've recently  played a little with MSXML interfaces and created a mini class to read and create base xml files for program settings.
There is only one class which can represent a root xml document, or xml node. It uses unicode strings because MSXML is implemented in wide character set.

A small example - enumerating all nodes:sub main()
{
XML doc;
if (doc.Open(L"xml_read.xml"))
{
EnumChilds(doc, 0);
}
}


sub EnumChilds(XML parent, int indent)
{
XML node;
if (parent.GetFirstNode(&node))
{
do {
printf("%s%S", strspace(indent), node.GetName());

if (!wcscmp(node.GetName(), L"#text"))
{
printf(" = %S", node.GetText());
}
print();
EnumChilds(node, indent + 3);
}
until !parent.GetNextNode(&node);
}
}


Attached examples for reading and creating, both for Aurora and Emergence.

sapero

November 29, 2008, 01:22:15 PM #1 Last Edit: November 30, 2008, 08:03:15 AM by sapero
I have extended the class with cdata and comment nodes. The Open method has now optional parameters to a/synchronously load and to load/ignore external dependencies.
Added example with tiny RSS reader. The xml file is downloaded from ionicwind.com, and finally the html code is generated and displayed in webbrowser window.

EDIT: fixed missing SysFreeString in Cleanup method.

sapero

December 12, 2008, 06:28:20 PM #2 Last Edit: December 13, 2008, 01:04:05 AM by sapero


Next example shows how to download the xml file asynchronously. I've added a function which removes potential dangerous elements from topics (script, iframe, object, embed) and ensures that every topic has closed all html tags.
For tag closing there is a hidden html document created by CoCreateInstance. By setting the body.innerHTML to topic text, and returning the text back we can close all opened tags, but before retrieving it back, we do a cleanup loop for document.body.all.

Added blue border for code and quote.
Todo's: only topic content is filtered. All other strings returned by XML::GetText() should be also filtered. To close tags and apply security filter to html code you can use CloseAllTags() function. It returns a BSTR with unicode string.

You can also run it with a parameter:xml_rss_async.exe http://a.b.c/rss.xml
EDIT: added StripTags function.