Page 1 of 1

[newbie] Parsing UTF-8 unicode XML file

Posted: Wed May 28, 2014 7:46 pm
by joahim
Hi,

I'm trying to write a simple program for parsing [UTF-8] XML files.
The built-in XML library has some license restrictions, so I decided to read the file step by step, using the command ReadUnicodeCharacter.

Code: Select all

If OpenFile(1,"document.xml")
  While Eof(1) = 0
  something = ReadUnicodeCharacter(1)
  ...  
  Wend  

EndIf
1. How can I create a string from unicode characters read in this way?
2. How can I compare unicode character with a string?

TIA,

joahim

Re: [newbie] Parsing UTF-8 unicode XML file

Posted: Wed May 28, 2014 8:07 pm
by infratec
Hi,

you should read the file like this:

Code: Select all

File = OpenFile(#PB_Any,"document.xml")
If File
  ReadStringFormat(File)  ; to skip a BOM if available
  While Not Eof(File)
    Line$ = ReadString(File, #PB_UTF8)
    Debug Line$
  Wend 
  CloseFile(File)
EndIf
Than you can use the 'normal' string functions like FindString().

Bernd

Re: [newbie] Parsing UTF-8 unicode XML file

Posted: Wed May 28, 2014 8:39 pm
by joahim
ReadStringFormat?

Huh, the XML file contains no EOL character, so the string would have > 1 MB.

Any ideas?

joahim

Re: [newbie] Parsing UTF-8 unicode XML file

Posted: Wed May 28, 2014 8:41 pm
by infratec
Do you have more than 4MB RAM :?:

Than you'll have no problem :mrgreen:

Oh, maybe the Debug takes a bit...

Re: [newbie] Parsing UTF-8 unicode XML file

Posted: Wed May 28, 2014 8:44 pm
by infratec
You can also do this:

Code: Select all

File = OpenFile(#PB_Any,"document.xml")
If File
  ReadStringFormat(File)  ; to skip a BOM if available
  While Not Eof(File)
    Line$ + ReadString(File, #PB_UTF8)
  Wend
  Debug Line$
  CloseFile(File)
EndIf
So you can be sure that always everything is in Line$.

Bernd

Re: [newbie] Parsing UTF-8 unicode XML file

Posted: Thu May 29, 2014 6:53 am
by coco2
Sidenote: joahim how did you post the original post in 1970 :shock:

Re: [newbie] Parsing UTF-8 unicode XML file

Posted: Thu May 29, 2014 9:29 am
by Fred
joahim wrote:The built-in XML library has some license restrictions, so I decided to read the file step by step, using the command ReadUnicodeCharacter.
Just wondering, which license restriction is bothering you ?

Re: [newbie] Parsing UTF-8 unicode XML file

Posted: Thu May 29, 2014 10:28 am
by IdeasVacuum
License for the expat XML parser

Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd
and Clark Cooper
Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006 Expat maintainers.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
I cannot see any restrictions?

Re: [newbie] Parsing UTF-8 unicode XML file

Posted: Thu May 29, 2014 8:55 pm
by Zach
Sounds like at most you just have to acknowledge your used the parser in your ReadMe file / documentation, and display the appropriate copyright attributions.
I don't see a problem with this. I'm planning on using it in my Text RPG Engine.