Click here to Skip to main content
Licence 
First Posted 14 Mar 2004
Views 122,968
Bookmarked 43 times

XML file/stream processing

By | 5 Jan 2007 | Article
Process an XML file or stream; read group and attribute values; write and delete groups, attribs, values and comments.

Sample Image

Introduction

This DLL provides routines to manipulate XML files. The set provided is not all-singing-and-dancing, but a useful, small collection. Several co-operating executables living off a common XML file may find their operating parameters and set parameters for others.

Background

Initially, the read functions were implemented to save incorporating the large overhead of using a proprietary interface. From this grew a certain understanding of the mechanism. Then were added write and delete routines; stream routines that allowed the user program to supply and recover the XML data (without using disk files); some super (i.e., over-arching) routines to shrink the user's code.

Using the code

VC 6.0 projects: Place the XMJDLL.dll in a directory on your path variable. Add the library XMJDLL.lib to the project resources. Add the module XMJcalls.h to the project. Use the routines therein.

VB 6.0 projects: Register the XMJDLL.dll with regsvr32. Add the module XMJDLL.bas to the project. Use the public routines therein.

//
// Sample source to produce the above file
//
  XMJ_newFile("Order");

  XMJ_getFrstGroup("Order",0);
  XMJ_newAttPutVal("number","1234");

  XMJ_pokeNewGrpPutVal("Date","2000/1/1");
  XMJ_newGrpPutVal("Customer","Acme Ltd");
  XMJ_newAttPutVal("ID","1234A");

  XMJ_getFrstGroup("Order",0);
  XMJ_newGroup("ITEM");
  XMJ_getFrstGroup("ITEM",1);
  XMJ_newAttPutVal("ID","01");
  XMJ_newGrpPutVal("Part-number","E16-25A");
  XMJ_newAttPutVal("warehouse","Warehouse11");
  XMJ_getFrstGroup("ITEM",1);
  XMJ_pokeNewGrpPutVal("Description","Production-Class Widget A");
  XMJ_newGrpPutVal("Quantity","16");

  XMJ_getFrstGroup("Order",0);
  XMJ_newGroup("ITEM");
  XMJ_getLastGroup("ITEM",1);
  XMJ_newAttPutVal("ID","02");
  XMJ_newGrpPutVal("Part-number","E23-45B");
  XMJ_newAttPutVal("warehouse","Warehouse11");
  XMJ_getLastGroup("ITEM",1);
  XMJ_pokeNewGrpPutVal("Description","Production-Class Widget B");
  XMJ_newGrpPutVal("Quantity","12");

  XMJ_writeFile(fileName);

Points of Interest

  • For C/C++ only users, a static library can be built using workspace and project files provided.
  • The private routines in the XMJDLL.bas module are to get around C/C++ <-> VB differences.
  • The implementation of 'false' (C/C++ 0, VB -1).
  • VB string addresses to C/C++ routines.
  • VB return-string-parameter is handled in the DLL.

History

  • 3.5 Corrections to XMJ_deProfundis.
  • 3.4 Encryption and catch up XM8.
    • New XMJ_crypt_vb.zip - demonstration of TEA encryption applied to XML files.
    • Four new encryption routines to implement Tiny Encryption Algorithm (TEA).
    • XMJ_sNew.cpp - new loop routine XMJ_deProfundis.
    • handles <,&,>," and ' within values; both read and write.
  • Group to attribute, and attribute to attribute, white space handled.
  • What took 440 mS now takes 160 mS.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Lymington

Web Developer

United Kingdom United Kingdom

Member

BSc (St.Andrews(1963-67))
MSCE
Systems Programmer 39+yrs
Married to first wife 35yrs & counting, four grown-up children
Religious opinions similar to MelG's
It is not the gnosis, but the praxis must be the fruit. (Aristotle)

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionBug with using different encoding PinmemberM A V6:03 22 Apr '08  
GeneralDocumentation Anomaly PinmemberGarth J Lancaster12:26 5 Jan '07  
GeneralRe: Documentation Anomaly PinmemberLymington8:09 7 Jan '07  
QuestionXMJ_deProfundis() returning 2, not zero? PinmemberCJayNC7:25 27 Dec '06  
Many thanks for the DLL; it has proven to be quite helpful. One question however...
 
The XMJ_deProfundis() documentation says that it will return a value of 0 once the depth has been raised to the root depth; however, in practice it never seems to go above '2'. Even immediately after opening the file, calling this function returns 2.
 
Looking at the code for the function, it appears that indeed '2' is the lowest number that will be returned.
 
I don't understand why 2 considered to be the root depth...am I missing something?
 
Thanks,
Chris

AnswerRe: XMJ_deProfundis() returning 2, not zero? PinmemberLymington3:47 3 Jan '07  
QuestionEnumerating through a depth? PinmemberTonyCounts10:54 19 Apr '06  
Generalwhat's the meaning of depth Pinmemberxiyuanzuren17:19 12 Apr '06  
GeneralRe: what's the meaning of depth PinmemberLymington21:50 17 Apr '06  
GeneralRe: what's the meaning of depth Pinmemberxiyuanzuren22:17 19 Apr '06  
GeneralBatch Command PinsussAnonymous0:13 1 Aug '05  
Generalreplace attribute Pinmemberthanhthuyvn_vtajkhskjakjd15:50 2 Jun '05  
GeneralRe: replace attribute PinmemberLymington6:40 6 Jun '05  
QuestionHow Can I read tag's Data Field ? Pinmembernico9999999990:35 5 May '05  
AnswerRe: How Can I read tag's Data Field ? PinmemberLymington4:48 5 May '05  
Generallooking for a way to read excel attachments PinmemberDawnYoshimura23:04 21 Jun '04  
GeneralRe: looking for a way to read excel attachments PinmemberLymington13:15 22 Jun '04  
GeneralRe: looking for a way to read excel attachments PinmemberXiAoYanG4:36 14 Dec '04  
Generalparse xml utf-8 & utf-16 PinmemberSancho-Panso1:52 12 May '04  
GeneralRe: parse xml utf-8 & utf-16 PinmemberLymington0:20 13 May '04  
GeneralRe: parse xml utf-8 & utf-16 PinmemberLymington21:52 3 Jun '04  
GeneralRe: parse xml utf-8 & utf-16 Pinmembermartyconnelly7:23 12 Jun '04  
GeneralRe: parse xml utf-8 & utf-16 PinmemberLymington6:49 13 Jun '04  
GeneralRe: parse xml utf-8 & utf-16 PinmemberLymington6:56 13 Jun '04  
GeneralShort, but fine PinmemberStHubi20:35 18 Mar '04  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120529.1 | Last Updated 5 Jan 2007
Article Copyright 2004 by Lymington
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid