LibXML-1.0

LibXML-1.0 Is a simple library for importing XML data into your WoW addon.


LibXML:Import(xml_data, loose_mode)

XML Import function Imports the given XML string and returns a table structure containing the XML elements

Parameters

xml_data
The XML file (string) to be parsed.
loose_mode
If set to true, LibXML will permit a looser syntax (optional)

Return values

  1. nil if the XML is invalid, otherwise a table struct containing the XML elements
  2. A message of any error encounted while parsing the XML data.

Usage

local xml_data = [[ <xml> <img src="some image URL" /> <p>Text goes here!<br/>And here!</p></xml> ]];
local libxml = LibStub("LibXML-1.0);
local struct, errmsg = libxml:Import(xml_data);
if ( errmsg ) then error(errmsg)
else
    for i = 1, #struct do
        local element = struct[i]
        if ( element.class == "img" ) then ImageStuff(element.args.src) end
        if ( element.class == "p" ) then
            for j = 1, #element do
                local subElement = element[i]
                if ( type(subElement) == "string" ) then print(subElement) end
                if ( type(subElement) == "table" and subElement.class == "br" ) then
                    print("We have a line break!\n");
                end
            end
        end
    end
end


You must login to post a comment. Don't have an account? Register to get one!

Facts

Date created
Sep 25, 2010
Last updated
Jan 27, 2012

Author