Author Topic: XML / SVG importer  (Read 2309 times)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10638
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
XML / SVG importer
« on: 2009-Nov-24 »
Ye, you're right. This time I'm the requester :P
First, we need an XML parser library. The XML format is pretty easy to read. The hardest thing will be a structure to contain the XML trees.

Here's my suggestiong how to store a tree like stucture:
Code: GLBasic [Select]



TYPE Tpair
        name$
        value$
ENDTYPE

TYPE Titem
        main   AS Tpair
        kids%[] // kid indices
ENDTYPE


GLOBAL gTreePairs[] AS Titem

FUNCTION AllocItem%: name$, value$=""
LOCAL p AS Titem
        p.main.name$=name$
        p.main.value$=value$
        DIMPUSH gTreePairs[], p
        RETURN LEN(gTreePairs[])-1
ENDFUNCTION


FUNCTION FreeTree%:
        DIM gTreePairs[0]
ENDFUNCTION




FUNCTION AddKid%: item%, kid_item%
        DIMPUSH gTreePairs[item%].kids%[], kid_item%
ENDFUNCTION

FUNCTION GetNumKids%: item%
        RETURN LEN(gTreePairs[item%].kids[])
ENDFUNCTION

FUNCTION GetKid%: item%, index%
        RETURN gTreePairs[item%].kids%[index%]
ENDFUNCTION

FUNCTION GetItemName$: item%
        RETURN gTreePairs[item%].main.name$
ENDFUNCTION

FUNCTION SetItemName%: item%, name$
        gTreePairs[item%].main.name$ = name$
ENDFUNCTION


FUNCTION GetItemValue$: item%
        RETURN gTreePairs[item%].main.value$
ENDFUNCTION

FUNCTION SetItemValue%: item%, name$
        gTreePairs[item%].main.value$ = name$
ENDFUNCTION

FUNCTION RemoveKid%: item%, iKid%
        DIMDEL gTreePairs[item%].kids%[], iKid%
ENDFUNCTION
 

Volunteers?

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1748
    • View Profile
    • Homepage
Re: XML / SVG importer
« Reply #1 on: 2009-Nov-24 »
I've been wanting to do that for ages but I never get the time for it :-(

The problem of building the tree structure looks like I wanted to solve it.