Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

XML File/Stream Processing

0.00/5 (No votes)
5 Jan 2007 1  
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.

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