MiniXML-2.9 binaries/src Windows Linux (32/64-bit)

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
D.J.Peters
Posts: 7852
Joined: May 28, 2005 3:28

MiniXML-2.9 binaries/src Windows Linux (32/64-bit)

Postby D.J.Peters » Oct 16, 2015 6:19

Most of content for the 3D engine Horde is XML stuff so i searched for a XML lib.

I found in the FreeBASIC include folder "mxml.bi" I fixed the *.html docs
(all links to the reference.html was broken) and build this tiny lib.

/doc
/src
/libmxml-2.9-32.so
/libmxml-2.9-64.so
/mxml-2.9-32.dll
/mxml-2.9-32.so
minixml.bi
minixml-tools.bi

download: mxml-2.9.zip

Joshy
Last edited by D.J.Peters on Sep 25, 2017 15:39, edited 2 times in total.
sancho2
Posts: 547
Joined: May 17, 2015 6:41

Re: MiniXML-2.9 binaries/src Windows Linux (32/64-bit)

Postby sancho2 » Oct 08, 2016 4:52

Hello Joshy, thanks for making these. I am trying to use this library on windows10 32bit.
I copied the .dll to my project folder.
I ran just the code #Include Once "mxml.bi" and it returns two library not found errors.
I had to rename it mxml.dll to remove one error.
Now there is one more error:
C:\PROGRA~2\FREEBA~1.05\bin\win32\ld.exe: cannot find -lpthread
Is this a library I need to copy as well? Or am I doing this wrong?
Can you post a small example of code to load an xml file?

EDIT:
I see now that I was including the wrong file. I have now #Include Once "minixml.bi" and that removes both errors.
I would still appreciate a small example of how you handle loading and accessing an element.
Thanks again.
MrSwiss
Posts: 3307
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: MiniXML-2.9 binaries/src Windows Linux (32/64-bit)

Postby MrSwiss » Oct 08, 2016 9:09

@Joshy,

great Tool. Tested with latest FBC 1.06.0 WIN x64 --> OK! (except some Warnings)
Also tested: FBC 1.06.0 WIN x32 --> OK! (with below fixes!)

Both dated: FreeBASIC Compiler - Version 1.06.0 (10-05-2016), built for win64 (64bit)
Copyright (C) 2004-2016 The FreeBASIC development team.
standalone

I've fixed those:

3 x in minixml.bi:

Code: Select all

#ifndef __MINIXML_BI__
#define __MINIXML_BI__

' Mini-XML, a small XML-like file parsing library.
' Copyright 2003-2014 by Michael R Sweet.
'

#include once "crt/stdio.bi"
#include once "crt/stdlib.bi"
#include once "crt/string.bi"
#include once "crt/ctype.bi"
#include once "crt/errno.bi"

#ifndef __FB_64BIT__
# inclib "mxml-2.9-32"
#else
# inclib "mxml-2.9-64"
#endif

extern "C"


const MXML_MAJOR_VERSION   = 2
const MXML_MINOR_VERSION   = 9

const MXML_TAB             = 8

const MXML_NO_CALLBACK     = 0
const MXML_TEXT_CALLBACK   = 0
const MXML_NO_PARENT       = 0

const MXML_DESCEND         = 1
const MXML_NO_DESCEND      = 0
const MXML_DESCEND_FIRST   = -1

const MXML_WS_BEFORE_OPEN  = 0
const MXML_WS_AFTER_OPEN   = 1
const MXML_WS_BEFORE_CLOSE = 2
const MXML_WS_AFTER_CLOSE  = 3

const MXML_ADD_BEFORE      = 0
const MXML_ADD_AFTER       = 1
#define MXML_ADD_TO_PARENT NULL

type mxml_sax_event_t as long
const as mxml_sax_event_t MXML_SAX_CDATA         = 0
const as mxml_sax_event_t MXML_SAX_COMMENT       = 1
const as mxml_sax_event_t MXML_SAX_DATA          = 2
const as mxml_sax_event_t MXML_SAX_DIRECTIVE     = 3
const as mxml_sax_event_t MXML_SAX_ELEMENT_CLOSE = 4
const as mxml_sax_event_t MXML_SAX_ELEMENT_OPEN  = 5

type mxml_type_t as long
const as mxml_type_t MXML_IGNORE = -1
const as mxml_type_t MXML_ELEMENT = 0
const as mxml_type_t MXML_INTEGER = 1
const as mxml_type_t MXML_OPAQUE  = 2
const as mxml_type_t MXML_REAL    = 3
const as mxml_type_t MXML_TEXT    = 4
const as mxml_type_t MXML_CUSTOM  = 5

type mxml_attr_t
  as zstring ptr name
  as zstring ptr value
end type

type mxml_element_t
  as zstring ptr     name
  as long            num_attrs
  as mxml_attr_t ptr attrs
end type

type mxml_text_t
  as long        whitespace
  as zstring ptr string
end type

type mxml_custom_destroy_cb_t as sub(byval as any ptr)
type mxml_custom_t
  as any ptr                  data
  as mxml_custom_destroy_cb_t destroy
end type

union mxml_value_t
  as mxml_element_t element
  as long           integer
  as zstring ptr    opaque
  as double         real
  as mxml_text_t    text
  as mxml_custom_t  custom
end union

type mxml_node_t
  as mxml_type_t     type
  as mxml_node_t ptr next
  as mxml_node_t ptr prev
  as mxml_node_t ptr parent
  as mxml_node_t ptr child
  as mxml_node_t ptr last_child
  as mxml_value_t    value
  as long            ref_count
  as any ptr         user_data
end type

type mxml_index_t
  as zstring ptr         attr
  as long                num_nodes
  as long                alloc_nodes
  as long                cur_node
  as mxml_node_t ptr ptr nodes
end type

type mxml_error_cb_t       as sub     (byval as const zstring ptr)

type mxml_custom_load_cb_t as function(byval as mxml_node_t ptr, byval as const zstring ptr) as long
type mxml_custom_save_cb_t as function(byval as mxml_node_t ptr) as zstring ptr

type mxml_entity_cb_t      as function(byval as const zstring ptr) as long
type mxml_load_cb_t        as function(byval as mxml_node_t ptr) as mxml_type_t
type mxml_save_cb_t        as function(byval as mxml_node_t ptr, byval as long) as const zstring ptr
type mxml_sax_cb_t         as sub     (byval as mxml_node_t ptr, byval as mxml_sax_event_t, byval as any ptr)

declare function mxmlLoadFd(byval top as mxml_node_t ptr, byval fd as long, byval cb as mxml_load_cb_t) as mxml_node_t ptr
declare function mxmlLoadFile(byval top as mxml_node_t ptr, byval fp as FILE ptr, byval cb as mxml_load_cb_t) as mxml_node_t ptr
declare function mxmlLoadString(byval top as mxml_node_t ptr, byval s as const zstring ptr, byval cb as mxml_load_cb_t) as mxml_node_t ptr

declare function mxmlNewXML(byval version as const zstring ptr) as mxml_node_t ptr
declare sub      mxmlDelete(byval node as mxml_node_t ptr)

declare sub      mxmlAdd(byval parent as mxml_node_t ptr, byval where as long, byval child as mxml_node_t ptr, byval node as mxml_node_t ptr)

declare sub      mxmlElementDeleteAttr(byval node as mxml_node_t ptr, byval name as const zstring ptr)
declare function mxmlElementGetAttr(byval node as mxml_node_t ptr, byval name as const zstring ptr) as const zstring ptr
declare sub      mxmlElementSetAttr(byval node as mxml_node_t ptr, byval name as const zstring ptr, byval value as const zstring ptr)
declare sub      mxmlElementSetAttrf(byval node as mxml_node_t ptr, byval name as const zstring ptr, byval format as const zstring ptr, ...)

declare function mxmlEntityAddCallback(byval cb as mxml_entity_cb_t) as long
declare sub      mxmlEntityRemoveCallback(byval cb as mxml_entity_cb_t)

declare function mxmlEntityGetName(byval val as long) as const zstring ptr
declare function mxmlEntityGetValue(byval name as const zstring ptr) as long


declare function mxmlFindElement(byval node as mxml_node_t ptr, byval top as mxml_node_t ptr, byval name as const zstring ptr, byval attr as const zstring ptr, byval value as const zstring ptr, byval descend as long) as mxml_node_t ptr
declare function mxmlFindPath(byval node as mxml_node_t ptr, byval path as const zstring ptr) as mxml_node_t ptr

declare function mxmlGetParent(byval node as mxml_node_t ptr) as mxml_node_t ptr
declare function mxmlGetPrevSibling(byval node as mxml_node_t ptr) as mxml_node_t ptr

declare function mxmlGetCDATA(byval node as mxml_node_t ptr) as const zstring ptr
declare function mxmlGetCustom(byval node as mxml_node_t ptr) as const any ptr

declare function mxmlGetFirstChild(byval node as mxml_node_t ptr) as mxml_node_t ptr
declare function mxmlGetInteger(byval node as mxml_node_t ptr) as long
declare function mxmlGetLastChild(byval node as mxml_node_t ptr) as mxml_node_t ptr
declare function mxmlGetNextSibling(byval node as mxml_node_t ptr) as mxml_node_t ptr

declare function mxmlGetOpaque(byval node as mxml_node_t ptr) as const zstring ptr

declare function mxmlGetReal(byval node as mxml_node_t ptr) as double
declare function mxmlGetRefCount(byval node as mxml_node_t ptr) as long
declare function mxmlGetText(byval node as mxml_node_t ptr, byval whitespace as long ptr) as const zstring ptr
declare function mxmlGetType(byval node as mxml_node_t ptr) as mxml_type_t
declare function mxmlGetUserData(byval node as mxml_node_t ptr) as any ptr

declare function mxmlIndexNew(byval node as mxml_node_t ptr, byval element as const zstring ptr, byval attr as const zstring ptr) as mxml_index_t ptr
declare sub      mxmlIndexDelete(byval ind as mxml_index_t ptr)

declare function mxmlIndexEnum(byval ind as mxml_index_t ptr) as mxml_node_t ptr
declare function mxmlIndexFind(byval ind as mxml_index_t ptr, byval element as const zstring ptr, byval value as const zstring ptr) as mxml_node_t ptr
declare function mxmlIndexGetCount(byval ind as mxml_index_t ptr) as long
declare function mxmlIndexReset(byval ind as mxml_index_t ptr) as mxml_node_t ptr

' element
declare function mxmlGetElement(byval node as mxml_node_t ptr) as const zstring ptr
declare function mxmlNewElement(byval parent as mxml_node_t ptr, byval name as const zstring ptr) as mxml_node_t ptr
declare function mxmlNewCDATA(byval parent as mxml_node_t ptr, byval string as const zstring ptr) as mxml_node_t ptr
declare function mxmlNewInteger(byval parent as mxml_node_t ptr, byval integer as long) as mxml_node_t ptr
declare function mxmlNewOpaque(byval parent as mxml_node_t ptr, byval opaque as const zstring ptr) as mxml_node_t ptr
declare function mxmlNewReal(byval parent as mxml_node_t ptr, byval real as double) as mxml_node_t ptr
declare function mxmlNewText(byval parent as mxml_node_t ptr, byval whitespace as long, byval string as const zstring ptr) as mxml_node_t ptr
declare function mxmlNewTextf(byval parent as mxml_node_t ptr, byval whitespace as long, byval format as const zstring ptr, ...) as mxml_node_t ptr
declare function mxmlNewCustom(byval parent as mxml_node_t ptr, byval data as any ptr, byval destroy as mxml_custom_destroy_cb_t) as mxml_node_t ptr

declare function mxmlRelease(byval node as mxml_node_t ptr) as long
declare sub      mxmlRemove(byval node as mxml_node_t ptr)
declare function mxmlRetain(byval node as mxml_node_t ptr) as long

declare function mxmlSaveAllocString(byval node as mxml_node_t ptr, byval cb as mxml_save_cb_t) as zstring ptr
declare function mxmlSaveFd(byval node as mxml_node_t ptr, byval fd as long, byval cb as mxml_save_cb_t) as long
declare function mxmlSaveFile(byval node as mxml_node_t ptr, byval fp as FILE ptr, byval cb as mxml_save_cb_t) as long
declare function mxmlSaveString(byval node as mxml_node_t ptr, byval buffer as zstring ptr, byval bufsize as long, byval cb as mxml_save_cb_t) as long

declare function mxmlSAXLoadFd(byval top as mxml_node_t ptr, byval fd as long, byval cb as function(byval as mxml_node_t ptr) as mxml_type_t, byval sax as mxml_sax_cb_t, byval sax_data as any ptr) as mxml_node_t ptr
declare function mxmlSAXLoadFile(byval top as mxml_node_t ptr, byval fp as FILE ptr, byval cb as function(byval as mxml_node_t ptr) as mxml_type_t, byval sax as mxml_sax_cb_t, byval sax_data as any ptr) as mxml_node_t ptr
declare function mxmlSAXLoadString(byval top as mxml_node_t ptr, byval s as const zstring ptr, byval cb as function(byval as mxml_node_t ptr) as mxml_type_t, byval sax as mxml_sax_cb_t, byval sax_data as any ptr) as mxml_node_t ptr

declare function mxmlSetCDATA(byval node as mxml_node_t ptr, byval data as const zstring ptr) as long
declare function mxmlSetCustom(byval node as mxml_node_t ptr, byval data as any ptr, byval destroy as mxml_custom_destroy_cb_t) as long
declare sub      mxmlSetCustomHandlers(byval load as mxml_custom_load_cb_t, byval save as mxml_custom_save_cb_t)
declare function mxmlSetElement(byval node as mxml_node_t ptr, byval name as const zstring ptr) as long
declare sub      mxmlSetErrorCallback(byval cb as mxml_error_cb_t)
declare function mxmlSetInteger(byval node as mxml_node_t ptr, byval integer as long) as long
declare function mxmlSetOpaque(byval node as mxml_node_t ptr, byval opaque as const zstring ptr) as long
declare function mxmlSetReal(byval node as mxml_node_t ptr, byval real as double) as long
declare function mxmlSetText(byval node as mxml_node_t ptr, byval whitespace as long, byval string as const zstring ptr) as long
declare function mxmlSetTextf(byval node as mxml_node_t ptr, byval whitespace as long, byval format as const zstring ptr, ...) as long
declare function mxmlSetUserData(byval node as mxml_node_t ptr, byval data as any ptr) as long
declare sub      mxmlSetWrapMargin(byval column as long)

declare function mxmlWalkNext(byval node as mxml_node_t ptr, byval top as mxml_node_t ptr, byval descend as long) as mxml_node_t ptr
declare function mxmlWalkPrev(byval node as mxml_node_t ptr, byval top as mxml_node_t ptr, byval descend as long) as mxml_node_t ptr

declare sub      mxml_error(byval format as const zstring ptr, ...)
declare function mxml_ignore_cb(byval node as mxml_node_t ptr)  as mxml_type_t
declare function mxml_integer_cb(byval node as mxml_node_t ptr) as mxml_type_t
declare function mxml_opaque_cb(byval node as mxml_node_t ptr)  as mxml_type_t
declare function mxml_real_cb(byval node as mxml_node_t ptr)    as mxml_type_t

end extern

#endif ' __MINIXML_BI__

and 3 x in minixml-tools.bi:

Code: Select all

#ifndef __MINIXML_TOOLS_BI__
#define __MINIXML_TOOLS_BI__

#ifndef __MINIXML_BI__
  #include once "minixml.bi"
#endif

' load node from memory (refcount is saet to 1)
function LoadXMLMemory(byval buffer as ubyte ptr,byval parent as mxml_node_t ptr=MXML_NO_PARENT) as mxml_node_t ptr
  if buffer=0 then return 0
  return mxmlLoadString(parent,buffer,MXML_NO_CALLBACK)
end function

' load node from file (refcount is saet to 1)
function LoadXMLFile(byval fileName as string,byval parent as mxml_node_t ptr=MXML_NO_PARENT) as mxml_node_t ptr
  var hFile = FreeFile()
  if open(fileName,for binary,access read,as #hFile)<>0 then return 0
  var nBytes = LOF(hFile)
  dim as ubyte ptr buffer = allocate(nBytes+1) ' alloc one byte more "\0"
  get #hFile,,*buffer,nBytes
  close #hFile
  buffer[nBytes]=0
  var node = LoadXMLMemory(buffer,parent)
  deallocate buffer
  return node
end function

' save node to memory (use Free() for deallocation)
function SaveXMLMemory(byval node as mxml_node_t ptr,byref nBytes as long) as ubyte ptr
  nBytes=0 : if node=0 then return 0
  dim as zstring ptr buffer = mxmlSaveAllocString(node,MXML_NO_CALLBACK)
  if buffer=0 then return 0
  nBytes=len(*buffer)
  return buffer
end function

function SaveXMLFile(byval fileName as string,byval node as mxml_node_t ptr) as long
  if node=0 then return 0
  dim as long nBytes
  ' save/create XML document in memory
  var buffer = SaveXMLMemory(node,nBytes)
  if buffer=0 then return 0
  var hFile = FreeFile()
  if open(fileName,for binary,access write,as #hFile)<>0 then
    free(buffer) : return 0
  end if
  put #hFile,,*buffer,nBytes
  close #hFile
  free(buffer)
  return nBytes
end function

function NodeTypeAsString(byval typ as mxml_type_t) as string
  select case as const typ
  case MXML_ELEMENT : return "(0) ELEMENT"
  case MXML_INTEGER : return "(1) INTEGER"
  case MXML_OPAQUE  : return "(2) OPAQUE"
  case MXML_REAL    : return "(3) REAL"
  case MXML_TEXT    : return "(4) TEXT"
  case MXML_CUSTOM  : return "(5) CUSTOM"
  case else         : return "(" & typ & ") UNKNOW !"
  end select
end function

#endif ' __MINIXML_TOOLS_BI__
D.J.Peters
Posts: 7852
Joined: May 28, 2005 3:28

Re: MiniXML-2.9 binaries/src Windows Linux (32/64-bit)

Postby D.J.Peters » Oct 08, 2016 12:15

sancho2 wrote:I would still appreciate a small example of how you handle loading and accessing an element.
Why do not start and reading /doc/basics.html ?
MrSwiss wrote:... except some Warnings
It's BASIC and I'm not pedantic :-)

Joshy
MrSwiss
Posts: 3307
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: MiniXML-2.9 binaries/src Windows Linux (32/64-bit)

Postby MrSwiss » Oct 08, 2016 12:32

D.J.Peters wrote:It's BASIC and I'm not pedantic :-)
OK, but, "-w pedantic" is ...
I'd just use the fixed headers in the distribution ;-)
D.J.Peters
Posts: 7852
Joined: May 28, 2005 3:28

Re: MiniXML-2.9 binaries/src Windows Linux (32/64-bit)

Postby D.J.Peters » Oct 08, 2016 13:47

@sancho2 something like this ?

Joshy

file: test2.xml

Code: Select all

<element attribute1="one" attribute2="two" />

file element.bas

Code: Select all

#include once "minixml.bi"
#include once "minixml-tools.bi" ' <-- Load/SaveXMLFile, LoadSavewXMLMemory, NodeTypeAsString

sub parseELEMENT(byval node as mxml_node_t ptr)
  print "element.name " & *node->value.element.name
  if node->value.element.num_attrs>0 then
    for i as long=0 to node->value.element.num_attrs-1
      print "attrs[" & i & "].name  = " & *node->value.element.attrs[i].name
      print "attrs[" & i & "].value = " & *node->value.element.attrs[i].value
    next
  end if
end sub

sub ParseNode(byval node as mxml_node_t ptr)
  if node=NULL then return
  select case node->type
  case MXML_IGNORE  : print "ignored"
  case MXML_ELEMENT : parseELEMENT(node)
  case MXML_INTEGER : ' parseINTEGER(node)
  case MXML_OPAQUE  : ' parseOPAQUE(node)
  case MXML_REAL    : ' parseREAL(node)
  case MXML_TEXT    : ' parseTEXT(node)
  case MXML_CUSTOM  : ' parseCUSTOM(node)
  case else
    print "unknow node type !"
    beep : sleep : end 1
  end select
end sub


chdir exepath()
' test2.xml does not have an <?xml ?> tag
var root = LoadXMLFile("test2.xml")
if root=0 then
  print "eror: LoadXMLFile() !"
  beep: sleep : end
end if
ParseNode(root)
mxmlRelease(root)
sleep
D.J.Peters
Posts: 7852
Joined: May 28, 2005 3:28

Re: MiniXML-2.9 binaries/src Windows Linux (32/64-bit)

Postby D.J.Peters » Oct 08, 2016 19:35

Simple parsing the included "test.xml" file.

Joshy

file: parse.bas

Code: Select all

#include once "minixml.bi"
#include once "minixml-tools.bi" ' <-- Load/SaveXMLFile, LoadSaveXMLMemory, NodeTypeAsString

sub parseELEMENT(byval node as mxml_node_t ptr)
  print "value.element.name " & *node->value.element.name
  if node->value.element.num_attrs>0 then
    for i as long=0 to node->value.element.num_attrs-1
      print "attrs[" & i & "].name  = " & *node->value.element.attrs[i].name
      print "attrs[" & i & "].value = " & *node->value.element.attrs[i].value
    next
  end if
end sub

sub parseTEXT(byval node as mxml_node_t ptr)
  if node->value.text.whitespace=0 then
    print "value.text.string " & * node->value.text.string
  end if
end sub

sub ParseNode(byval node as mxml_node_t ptr)
  if node=NULL then return
  select case node->type
  case MXML_IGNORE  : print "MXML_IGNORE"
  case MXML_ELEMENT : parseELEMENT(node)
  case MXML_INTEGER : print "MXML_INTEGER" ' parseINTEGER(node)
  case MXML_OPAQUE  : print "MXML_OPAQUE"  ' parseOPAQUE(node)
  case MXML_REAL    : print "MXML_REAL"    ' parseREAL(node)
  case MXML_TEXT    : parseTEXT(node)
  case MXML_CUSTOM  : print "MXML_CUSTOM"  ' parseCUSTOM(node)
  case else
    print "unknow node type !"
    beep : sleep : end 1
  end select
  var Child = mxmlGetFirstChild(node)
  while Child
    var Sibling = mxmlGetNextSibling(Child)
    while Sibling
      ParseNode(Sibling)
      Sibling = mxmlGetNextSibling(Sibling)
    wend
    ParseNode(Child)
    Child = mxmlGetFirstChild(Child)
  wend
end sub

chdir exepath()

var root = LoadXMLFile("test.xml")
if root=NULL then
  print "error: LoadXMLFile() !"
  beep: sleep : end
end if
ParseNode(root)
mxmlRelease(root)
sleep
parse.bas wrote:value.element.name ?xml version="1.0" encoding="UTF-8"?
value.element.name group
value.element.name option
value.element.name keyword
attrs[0].name = type
attrs[0].value = opaque
value.text.string InputSlot
value.element.name default
attrs[0].name = type
attrs[0].value = opaque
value.text.string Auto
value.element.name text
value.text.string Media
value.element.name order
attrs[0].name = type
attrs[0].value = real
value.text.string 10.000000
value.element.name choice
value.element.name keyword
attrs[0].name = type
attrs[0].value = opaque
value.text.string Auto
value.element.name text
value.text.string Auto
value.element.name code
attrs[0].name = type
attrs[0].value = opaque
value.element.name choice
value.element.name keyword
attrs[0].name = type
attrs[0].value = opaque
value.text.string Upper
value.element.name text
value.text.string Tray
value.element.name code
attrs[0].name = type
attrs[0].value = opaque
value.text.string <</MediaPosition
value.element.name choice
value.element.name keyword
attrs[0].name = type
attrs[0].value = opaque
value.text.string Lower
value.element.name text
value.text.string Tray
value.element.name code
attrs[0].name = type
attrs[0].value = opaque
value.text.string <</MediaPosition
value.element.name integer
value.text.string 123
value.element.name string
value.text.string Now
value.element.name !-- this is a comment --
value.element.name ![CDATA[this is CDATA 0123456789ABCDEF]]
sancho2
Posts: 547
Joined: May 17, 2015 6:41

Re: MiniXML-2.9 binaries/src Windows Linux (32/64-bit)

Postby sancho2 » Oct 09, 2016 0:50

Thank you Joshy. I will study the code (and the contents of the download zip file),
sancho2
Posts: 547
Joined: May 17, 2015 6:41

Re: MiniXML-2.9 binaries/src Windows Linux (32/64-bit)

Postby sancho2 » Oct 11, 2016 4:28

Given the following xml file, why does mxmlGetNextSibling return <a>, mxml_text node, <a>, mxml_text node, etc?
Surely the empty string text nodes (if that is what is being found) are not siblings of <a>, but children of <a>.

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<testabc>
   <one>
      <a>
      </a>
      <a>
      </a>
      <a>
      </a>
      <a>
      </a>
      <b />
      <c />
   </one>
   <two>
   </two>
   <three />
</testabc>

I tested this by removing the crlf from the file, putting the <a> elements on a single line (<a></a><a></a>) and it only returned <a> elements.
So it is finding the crlf is a sibling of the <a> element. Isn't the crlf a child of <a>?
EDIT:
I figured it out. Its not the text nodes inside the element that are being found it is the ones between the elements.
When I re-configure the file like this, mxmlGetSibling returns the 4 <a> elements and no text nodes between them.

Code: Select all

      <a>
     </a><a>
     </a><a>
      </a><a>
      </a>
sancho2
Posts: 547
Joined: May 17, 2015 6:41

Re: MiniXML-2.9 binaries/src Windows Linux (32/64-bit)

Postby sancho2 » Oct 22, 2016 4:41

Hello again:

I have a text element with approx. 15000 chars delimited by commas. It is stored in the xml file on a line by line basis. Each line ends with a crlf.
I use mxmlGetText to get the text, however it only gives me one line. How do I get the entire xml text element into a string variable.
Here are relevant portions of the code:

Code: Select all

dim as string fileText
node = mxmlFindElement(node, node, "data", NULL, NULL, 1)
   node = mxmlFindElement(node, node, "data", NULL, NULL, 1)

   If node = NULL Then
      Print "could not find data element"
      Return 0
   EndIf
   
   ? "Data Node Found: "; *node->value.element.name
   
   node = mxmlGetFirstChild(node)
   If node = NULL Then
      Print "could not find first child of data"
      Return 0
   EndIf
   
   ?
   ? "child node of Data Found: "; NodeTypeAsString(node->type)
   fileText = *mxmlGetText(node, 0)
   ? "length of text: "; Len(fileText)
   ? Len(*mxmlGetText(node, 0))
   ? *mxmlGetText(node, 0)

sancho2
Posts: 547
Joined: May 17, 2015 6:41

Re: MiniXML-2.9 binaries/src Windows Linux (32/64-bit)

Postby sancho2 » Oct 23, 2016 2:50

I see now that mxml is handling each line of text as an individual text element. I don't think this is correct in xml. The entire text, new line chars and all are 1 element.
I set up a short xml file and code to read it.

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<data>
8,7,7,4,
1,2,3,4,
5,6,7,8,
9,10,11,12,13,
14,15,16,17
</data>

Code: Select all

#Include once "minixml.bi"
#include once "minixml-tools.bi" ' <-- Load/SaveXMLFile

Const XML_FILE As String = "C:\Freebasic Stuff\DWTileSet\ttt.xml"


Dim As mxml_node_t Ptr doc, node

doc = LoadXMLFile(xml_file)

If doc = NULL Then
   Print "Error: "; xml_file; " not found", doc
   Sleep
   End
EndIf

node = mxmlFindElement(doc, doc, "data", NULL, NULL, 1)
node = mxmlGetFirstChild(node)
? node->type
? *mxmlGetText(node, 0)
Sleep

node = mxmlGetNextSibling(node)
? node->type
? *mxmlGetText(node, 0)

sleep   
mxmlrelease(doc)

I pasted the xml into a xml -> json converter and here it is in json. Clearly the text is one entity:

Code: Select all

{
   "data": "8,7,7,4,\n1,2,3,4,\n5,6,7,8,\n9,10,11,12,13,\n14,15,16,17"
}
sancho2
Posts: 547
Joined: May 17, 2015 6:41

Re: MiniXML-2.9 binaries/src Windows Linux (32/64-bit)

Postby sancho2 » Oct 23, 2016 6:57

I have discovered that this is a known bug in minxml.
See here: http://www.hmgforum.com/viewtopic.php?t=2120
If you scroll down to user 'mol' post, Thu Oct 16, 2014 11:41 am , he fixes the minxml source.
Minxml actually will stop reading text even on a space (as well as other chars) as can be demonstrated by changing the xml in my last post like so (note the space after '8,':

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<data>
8, 7,7,4,
1,2,3,4,
5,6,7,8,
9,10,11,12,13,
14,15,16,17
</data>

The output text is '8,'.
This bug is at least 2 years old as evidenced by mol's post.
Is minxml stil being developed? Why wouldn't this bug be addressed?
This issue renders minxml useless if text elements are to be parsed. I would consider that a major bug.
D.J.Peters
Posts: 7852
Joined: May 28, 2005 3:28

Re: MiniXML-2.9 binaries/src Windows Linux (32/64-bit)

Postby D.J.Peters » Sep 25, 2017 17:18

Because of malware on alice-dsl.net domain I moved all content to my new shiny3d.de server.

Joshy

Return to “Libraries”

Who is online

Users browsing this forum: No registered users and 2 guests