Home Tutorials Download Beta Store Forum Documentation KnowledgeBase Wiki Blog

ShiVa3D

Return to Game programming

xml API not supporting <![CDATA[]]> ?

All about the StoneScript

xml API not supporting <![CDATA[]]> ?

Postby _geo_ » 08 Oct 2011, 15:19

What i wanted to do:
I tried to load some remote xml which uses <![CDATA[]]> to mark "raw" data.

What happended:
Whenever i try to access a tags value which is defined like this: <tagname><![CDATA[some <> raw values &?!]]></tagename> using xml.getElementValue() it just returns nothing.

Removing <![CDATA[]]> did solve the problem for now but i am still curious whether or not ShiVa supports <![CDATA[]]>? Since it is a remote source that i cannot control it would be nice to have a solution which makes xmls containing <![CDATA[]]> useable in ShiVa without altering the xml source itself.

thx to everybody who´s reading ;)
fly yes, land no | Modern Alchemists | Blog | MASH | MATWEEN-AI
User avatar
_geo_
Gold Boarder
Gold Boarder
 
Posts: 197
Location: Austria

Re: xml API not supporting <![CDATA[]]> ?

Postby michax » 08 Oct 2011, 16:25

Yeap it would be nice to have <![CDATA[]]> support. For now i think we can go one child further and then use getElementValue to get CDATA content.
User avatar
michax
Platinum Boarder
Platinum Boarder
 
Posts: 466
Location: Poland

Re: xml API not supporting <![CDATA[]]> ?

Postby _geo_ » 09 Oct 2011, 12:06

Thx, i didn´t expect that to work!

For all those who are suffering from the same problem, here is a little convenienve function i wrote to solve the issue. It serves me as a replacement for xml.getElementValue()

Code: Select all
--------------------------------------------------------------------------------
function Main.xml_getElementValue ( hXml )
--------------------------------------------------------------------------------
   
    local result = nil
    local possiblyCDATA = xml.getElementFirstChild ( hXml )
   
    -- check if CDATA
    if( possiblyCDATA ~= nil and string.compare ( xml.getElementName ( possiblyCDATA ), "#CDATA" ) == 0 )
    then
        local possiblyCDATA = xml.getElementFirstChild ( hXml )
        if( string.compare ( xml.getElementName ( possiblyCDATA ), "#CDATA" ) == 0 )
        then
            result = xml.getElementValue( possiblyCDATA )
        end
    else
        result = xml.getElementValue( hXml )
    end
   
    return result
   
--------------------------------------------------------------------------------
end
--------------------------------------------------------------------------------


I will put that into snippets as well
fly yes, land no | Modern Alchemists | Blog | MASH | MATWEEN-AI
User avatar
_geo_
Gold Boarder
Gold Boarder
 
Posts: 197
Location: Austria


Return to Game programming