Hello
I search for my new project a XML Parser/Edit library.
Has anyone, a good library and an example ?
Regads,
RAGDOG,
I started working on an XML library using the .NET Framework, and MABDELOUHAB's Masm32Ref (http://masm32.com/board/index.php?topic=5028.0). I thought it would be easy,...but, I thoroughly destroyed it (I must have some advanced form of programming dementia). :bgrin:
However, there are several fairly simple ways to do it, depending on which XML version you have loaded on your (or, the user's computer).
Here is a: Listing of Microsoft XML parser (MSXML) versions (https://support.microsoft.com/en-us/help/269238/list-of-microsoft-xml-parser-msxml-versions). These come with Internet Explorer, and they are implemented as COM interfaces. To use one of these versions from a MASM assembly language program, you will have to call LoadLibrary on the XML library DLL, and then call CoCreateInstance on whichever interface that you want to use. It will require way too much code to be really fun, but, it is possible,...:bgrin:
You will probably want to read this: MSXML Roadmap, MSDN (https://msdn.microsoft.com/en-us/library/jj152146(v=vs.85).aspx)
Could be work a look:
Mini-XML - Tiny XML Library: http://www.msweet.org/projects.php?Z3
Yxml - A small, fast and correct XML parser: https://dev.yorhel.nl/yxml
AsmXml - A very fast XML parser and decoder for x86: http://tibleiz.net/asm-xml/
Might have to compile some of them to lib and convert headers .h to .inc for use with asm
Done some conversion of the mxml header to an inc file and compiled the visual studio solution to a static lib: https://dl.dropboxusercontent.com/u/17077376/mxml.zip
Also a basic radasm v2 project to test some basics of the mxml nodes/elements just to verify if library is working: https://dl.dropboxusercontent.com/u/17077376/mxmltest.zip
I havent done any extensive tests apart from the ones in the radasm project, and cant say all features/functions are working - but so far the basic tests seem to work - i took the testmxml.c file from the mini-xml source as a basis to work through some of the test steps to use some of the functions.
Hi fearless!
What version of masm32 are you using?
ml -c -coff -Cp /I"$I" "mxmltest.Asm"
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997. All rights reserved.
Assembling: mxmltest.Asm
***********
ASCII build
***********
\Masm32\include\windows.inc(16531) : error A2037: statement not allowed inside structure definition
szText(2): Macro Called From
\Masm32\include\windows.inc(16531): Include File
\Masm32\include\windows.inc(16531) : error A2008: syntax error : db
szText(3): Macro Called From
\Masm32\include\windows.inc(16531): Include File
\Masm32\include\windows.inc(16531) : error A2034: must be in segment block
szText(4): Macro Called From
\Masm32\include\windows.inc(16531): Include File
\Masm32\include\windows.inc(16543) : error A2037: statement not allowed inside structure definition
szText(2): Macro Called From
\Masm32\include\windows.inc(16543): Include File
\Masm32\include\windows.inc(16543) : error A2008: syntax error : db
szText(3): Macro Called From
\Masm32\include\windows.inc(16543): Include File
\Masm32\include\windows.inc(16543) : error A2034: must be in segment block
szText(4): Macro Called From
\Masm32\include\windows.inc(16543): Include File
***********
ASCII build
***********
------------------------------------------
WARNING Duplicate include file windows.inc
------------------------------------------
-----------------------------------------
WARNING duplicate include file user32.inc
-----------------------------------------
-------------------------------------------
WARNING duplicate include file kernel32.inc
-------------------------------------------
----------------------------------------
WARNING duplicate include file gdi32.inc
----------------------------------------
------------------------------------------
WARNING duplicate include file shell32.inc
------------------------------------------
-------------------------------------------
WARNING duplicate include file comctl32.inc
-------------------------------------------
-------------------------------------------
WARNING duplicate include file comdlg32.inc
-------------------------------------------
Error(s) occured.
There is no problem with .incs. szText renamed in mxmltest.inc and debub32.inc. Is there another szText? szText in NMTTDISPINFO
Changing Windows.inc:
link /SUBSYSTEM:WINDOWS /RELEASE /VERSION:4.0 /OUT:"mxmltest.exe" "mxmltest.obj" "mxmltest.res" /Debug
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
Debug32.lib(Debug32.obj) : error LNK2001: unresolved external symbol _NtQuerySystemInformation@16
Debug32.lib(Debug32.obj) : error LNK2001: unresolved external symbol _NtQueryObject@20
Debug32.lib(Debug32.obj) : error LNK2001: unresolved external symbol _SymLoadModule64@28
Debug32.lib(Debug32.obj) : error LNK2001: unresolved external symbol _SymGetModuleInfo64@16
Debug32.lib(Debug32.obj) : error LNK2001: unresolved external symbol _SymEnumSymbols@24
Debug32.lib(Debug32.obj) : error LNK2001: unresolved external symbol _SymUnloadModule64@12
mxmltest.exe : fatal error LNK1120: 6 unresolved externals
Error(s) occured.
Using latest masm32
Prob the szText variable is getting confused with the macro of same name. Just rename szText in to something like szTestText. Ive uploaded a revised version of the project that has that change: https://dl.dropboxusercontent.com/u/17077376/mxmltest.zip (https://dl.dropboxusercontent.com/u/17077376/mxmltest.zip)
The debug stuff is due to using donkey's vkim like debug32. Ive uploaded a copy of it here: https://dl.dropboxusercontent.com/u/17077376/masm32_donkeys_vkimlike_debug.zip (https://dl.dropboxusercontent.com/u/17077376/masm32_donkeys_vkimlike_debug.zip) - copy debug32.inc to masm32\include, debug32.lib to masm32\lib and dbgwin.exe to masm32 - that should allow the debug macros to work (PrintDec, PrintStringByAddr etc)
When run the output in dbgwin should be something like:
(https://s20.postimg.org/4a9ocz1el/dbgwin2.png)
The problem with szText was solved changing include order (ie. macros.asm after mxml.inc)
From your post in "Adding items and subitems for listview" I obtained a working debug32.inc.
With link option \Debug now error is:
mxml.lib(gs_report.obj) : fatal error LNK1103: debugging information corrupt; recompile module
but work perfectly without the option.
Interestling, executable send the messages to the RadAsm Output window (instead of opening DbgWin), perhaps I change something a time ago, I don't remenber.
Now I can begin the test :t
Thank you Fearless
I have try other lib´s ex: Xmllite from MS ,etc..
If i compile you Radasm2 project works fine ,use i Radasm 3 have i a missing lib
QuoteLNK1104: cannot open file "uuid.lib"
Why this?
My settings
ml /c /coff /Cp "Console.asm"
link /SUBSYSTEM:CONSOLE /RELEASE /VERSION:4.0 /OUT:"Console.exe" "Console.obj"
Your settings
ML.EXE /c /coff /Cp /nologo /I"C:\Masm32\Include" "mxmltest.asm"
LINK.EXE /SUBSYSTEM:WINDOWS /RELEASE /VERSION:4.0 /LIBPATH:"C:\Masm32\Lib" /OUT:"mxmltest.exe"
And is a bug in your static mxml.lib ?
invoke crt_fopen ,chr$ ("Test.xml"), chr$ ("rb");
.if eax!=0
mov hFile,eax
invoke mxmlLoadFile,NULL,eax,MXML_TEXT_CALLBACK
PrintDec eax
.endif
MXML_NO_CALLBACK
Wrong, perhaps it's a different uuid.lib
Couldnt get the mxmlLoadfile function to work, but have a demo version using other functions that im putting together. The structures in my original mxml.inc are slightly wrong, so ive updated that and will upload that new version soon.
@Hse
Why is this wrong "MXML_NO_CALLBACK"?
testmxml.c
* Read the file...
*/
tree = mxmlLoadFile(NULL, fp, MXML_NO_CALLBACK);
Quoteand will upload that new version soon.
Nice fearless
@ragdog
I though MXML_TEXT_CALLBACK was the problem, but no.
No the problem is in the static lib it crash in the Ntdll.
if i use mxmlLoadFile
invoke crt_fopen ,chr$ ("Test.xml"), chr$ ("rb");
.if eax!=0
mov hFile,eax
invoke mxmlLoadFile,NULL,eax,MXML_TEXT_CALLBACK
PrintDec eax
.endif
Address=775E8E19
Message=Access violation when writing to [00000014]
But it same if i use the compiled mxml1.dll only the testmxml.exe works curious :icon_exclaim:
Updated zip with lib and inc: https://www.dropbox.com/s/zc2yvoy587oae87/mxml.zip?dl=0
mxmltree demo: https://www.dropbox.com/s/dc2orxxv5ypmxyo/mxmltree.zip?dl=0
Treeview lib and inc https://github.com/mrfearless/libraries/blob/master/releases/Treeview_x86.zip
Demo using memory mapped file and mxmlLoadString to open xml file. Then some processing looping through xml tree and MS Treeview Control adding elements to Treeview, then xml attributes as child nodes to Treeview. Shows using the structures to access xml tree node (mxml_node_t) and fetch mxml_node_t->node_value->element (mxml_element_t), fetch num_attrs and then loop through attrs array to get attribute name and attribute value.
Few other bits and pieces whilst i was playing around figuring it out.
(https://s20.postimg.org/q8bpasg65/mxmltree.png)
The child items could be reworked to better reflect actual hierarchy - just easier to add element nodes to root and save node, then add attributes as a child of the node saved, then next item etc etc.
Thank you
QuoteDemo using memory mapped file and mxmlLoadString to open xml file
This way works
But not mxmlLoadFile
I think is a problem with config.h by compile a static lib.
Can you share the Visual studio Project files Visual for this static lib?
Wow, a great advance :t
https://dl.dropboxusercontent.com/u/17077376/mxml-2.10.zip
Thank you
Yes it crash in mxmlLoadFile
004011F6 MOV EDI,[ARG.1]
004011F9 PUSH EDI ; /stream
004011FA CALL <JMP.&MSVCR120.getc> ; \getc
I must use a newer Msvcrt.lib from \Microsoft Visual Studio 12.0\VC\lib\
And it works.
I managed to trace into the getc as far as a lock function and then the exception was thrown. (I compiled static lib with debug /Zi setting in it, recompiled the mxmltree with debug settings and then used x64dbg to trace as far as the internal getc lock function)
Here is my radasm v2 project options for debug:
3,O,$B\ML.EXE /c /coff /Cp /Zi /Zd /nologo /I"$I",2
5,O,$B\LINK.EXE /SUBSYSTEM:WINDOWS /DEBUG /DEBUGTYPE:CV /PDB:"$18" /VERSION:4.0 /LIBPATH:"$L" /OUT:"$5",3,4
I dont seem to have a vc12 lib folder for some reason, maybe you can recompile the static on your system and upload that msvcrt.lib as well so i can try it out
Here is this msvcrt.lib from "\Microsoft Visual Studio 12.0\VC\lib\msvcrt.lib"
https://www.sendspace.com/file/ts239p
Copy this in your project folder rename it to msvcrt_.lib
and include this
include msvcrt.inc
includelib msvcrt_.lib
include mxml.inc
includelib mxml.lib
Here is my working code
invoke crt_fopen ,chr$ ("test.xml"), chr$ ("r");
.if eax!=0
mov FilePointer,eax
invoke mxmlLoadFile,NULL,FilePointer,MXML_NO_CALLBACK
.endif
Ok that seems to work, i was using standard CreateFile api call to open and passing the handle to mxmlLoadFile which doesnt seem to work for some reason - must be a c runtime thing. Anyhow at least we know why and now there is a couple of ways of handling the xml files.
I have rebuild this static library and use a older Msvcrt.lib from Xp
Now works it fine without MSVCR1xx Runtimes. etc
please test it
That crashed for me using mxmlFileOpen - the one i have seems to work ok for me.
My static lib what i have attach Crash in mxmlFileOpen ?
yes - but it could be that they are still calling msvrt routines as bundled in dll's on our different systems.
My static lib use not MSVCR1xxx runtimes, i use a older from xp
Correction.
your last static lib with MSVCR100 and the older MSVCR120 crash too.
This is if i use the msvcrt.lib from Masm32 package.
for run fine must i use msvcrt from sdk
My static lib use without MSVCR1xxx
.686
.model flat,stdcall
option casemap:none
include Console.inc
include msvcrt.inc
includelib msvcrt.lib
include mxml.inc
includelib mxml_ragdog.lib;mxml.lib
.data?
FilePointer dd ?
pTree dd ?
node dd ?
.code
start:
;#########################################################################
invoke crt_fopen ,chr$ ("test.xml"), chr$ ("r");
.if (eax)
mov FilePointer,eax
invoke mxmlLoadFile,NULL,FilePointer,MXML_NO_CALLBACK
.if (eax)
mov pTree,eax
invoke mxmlFindElement,pTree ,pTree, chr$ ("note"),NULL, NULL,MXML_DESCEND
.if (eax)
mov node,eax
invoke mxmlElementGetAttr,node,chr$ ("year")
invoke crt_printf,chr$ (" year:%s" ,CR,LF),eax
invoke mxmlElementGetAttr,node,chr$ ("date")
invoke crt_printf,chr$ (" date:%s" ,CR,LF),eax
.else
invoke crt_puts ,chr$ ("Unable to find first <choice> element in XML tree.")
.endif
.endif
.endif
;#########################################################################
invoke wait_key
@exit:
invoke ExitProcess, 0
end start
output
year:55
date:33
See in my attach.
https://www.sendspace.com/file/ax91c7
@ragdog:
working :t
@fearless:
there is a problem with debug32. I disabled. Try that.
Debug32 uses msvcrt i think anyhow. I commented out the DEBUG32 EQU 1 line when i want to exclude debug32 etc. Seems to work fine with that lib and the standard msvcrt.lib found in the masm32 lib folder.
Anyhow hopefully its useful stuff for others.
Thank you both for the test, and Fear for translate the header and the project files.
QuoteDebug32 uses msvcrt i think anyhow. I commented out the DEBUG32 EQU 1 line when i want to exclude debug32 etc. Seems to work fine with that lib and the standard msvcrt.lib found in the masm32 lib folder.
It works fine with Debug32 stuff and msvcrt.lib from Masm32 folder :t
include msvcrt.inc ;<<< From Masm32 folder
includelib msvcrt.lib ;<<< From Masm32 folder
include mxml.inc
includelib mxml_ragdog.lib;mxml.lib
DEBUG32 EQU 1
IFDEF DEBUG32
includelib \Masm32\lib\Debug32.lib
DBG32LIB equ 1
DEBUGEXE textequ <'\Masm32\DbgWin.exe'>
include \Masm32\include\debug32.inc
ENDIF
The problem was only the original MiniXml project by compile it with Vs it include the MSVCRxxx runtimes
In other Cpp projects have i add a Tinycrt or a older Msvcrt.lib from Windows XP sdk to remove this MSVCRxxx runtimes.
@fearless:
You can define NODEBUGTOOLS equ 0, and that disabled the calls to debug system (you don't need all those IFDEF DEBUG32) .
Still there is some problem with Debug32 here, perhaps a macro with same name. There is not serious consequences because usually I use OA32 DebugCenter, a more complex VKdebug descendent, but perhaps it's a problem to follow some projects that used it.
A year ago I downloaded several alternatives for Xml, but after some days none of them worked. Now I put to work these examples of Mini-MXML ( wich library I can't compile :biggrin:), asm-xml1.4, XML_parser from Nemeth_G and IoEXML Writer-Parser (I forgot that was working, it's a nightmare COM thing).
Thanks
QuoteNow I put to work these examples of Mini-MXML ( wich library I can't compile :biggrin:)
Why can´t you compile it?
Some undefined references ¿?. But the main problen is I don't know almost nothing about "c". Perhaps the command is wrong.
@ fearthless:
Is there some documentation of LTLI TreeView Library v1.0.0.0?
@RagDog:
Have you succeded with mxmlLoadFile?
Thanks
It was just an internal library created for convenience which wrapped some common code to help speed up use and re-use. Only whats in the .inc file and the example of the mxmltree example documentation wise i'm afraid.
Although i do have two .api.txt files in the zip ive attached (edit files to see contents and instructions for adding to RadASM for autocomplete of functions) they contain parameters used in the functions, which will help hopefully in figuring out what to pass as a parameter for specific functions.
A lot better. Thanks :t
QuotePosted by: HSE
@RagDog:
Have you succeded with mxmlLoadFile?
Here is my static lib i have compile it with a older msvcrt from xp sdk
http://masm32.com/board/index.php?action=dlattach;topic=5993.0;attach=6232
invoke crt_fopen ,chr$ ("test.xml"), chr$ ("r");
.if eax!=0
mov FilePointer,eax
invoke mxmlLoadFile,NULL,FilePointer,MXML_NO_CALLBACK
.endif
You can use without crt_fopen ,use CreateFile/ReadFile or Mapping File.
Regards,
Thanks Ragdog! I will try again :t
Finally I solve how to load an xml file "not well formed" (without ?xml element) :
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
include \masm32\include\masm32rt.inc
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
include \masm32\include\mxml_f.inc
includelib \masm32\lib\mxml10.lib
includelib \masm32\lib\uuid.lib
comment * -----------------------------------------------------
Build this console app with
----------------------------------------------------- *
.data
xml dd 0
fp dd 0
node dd 0
.code
start:
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
call main
inkey
exit
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
main proc
mov xml, rvc(mxmlNewXML,"1.0")
cls
mov fp, rvc(crt_fopen, "rule3.xml", "r");
fnc mxmlLoadFile(xml, fp, MXML_TEXT_CALLBACK);
fnc crt_fclose(fp);
print "Arbol creado",13,10
; /* Find the first element */
mov node, rvc (mxmlFindElement(xml, xml, NULL, NULL, NULL, MXML_DESCEND));
mov fp, rvc(crt_fopen, "filename2.xml", "w");
fnc mxmlSaveFile(node, fp, MXML_NO_CALLBACK);
fnc crt_fclose(fp);
print "Arbol not_well_formed guardado",13,10
fnc mxmlDelete(xml);
ret
main endp
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
end start
Only at the end, I read the manual!
Now I have to see how to save a "not well formed" xml file :biggrin: Ready above :biggrin: :biggrin:
Note: There is a new version 2.11 of the library, but the default compilation build a .dll