Click here to Skip to main content
Click here to Skip to main content

XML file/stream processing

, 5 Jan 2007
Rate this:
Please Sign up or sign in to vote.
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
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)

Comments and Discussions

 
QuestionBug with using different encoding PinmemberM A V22-Apr-08 6:03 
GeneralDocumentation Anomaly PinmemberGarth J Lancaster5-Jan-07 12:26 
GeneralRe: Documentation Anomaly PinmemberLymington7-Jan-07 8:09 
QuestionXMJ_deProfundis() returning 2, not zero? PinmemberCJayNC27-Dec-06 7:25 
AnswerRe: XMJ_deProfundis() returning 2, not zero? PinmemberLymington3-Jan-07 3:47 
QuestionEnumerating through a depth? PinmemberTonyCounts19-Apr-06 10:54 
Generalwhat's the meaning of depth Pinmemberxiyuanzuren12-Apr-06 17:19 
GeneralRe: what's the meaning of depth PinmemberLymington17-Apr-06 21:50 
GeneralRe: what's the meaning of depth Pinmemberxiyuanzuren19-Apr-06 22:17 
GeneralBatch Command PinsussAnonymous1-Aug-05 0:13 
Generalreplace attribute Pinmemberthanhthuyvn_vtajkhskjakjd2-Jun-05 15:50 
GeneralRe: replace attribute PinmemberLymington6-Jun-05 6:40 
QuestionHow Can I read tag's Data Field ? Pinmembernico9999999995-May-05 0:35 
AnswerRe: How Can I read tag's Data Field ? PinmemberLymington5-May-05 4:48 
Generallooking for a way to read excel attachments PinmemberDawnYoshimura21-Jun-04 23:04 
GeneralRe: looking for a way to read excel attachments PinmemberLymington22-Jun-04 13:15 
GeneralRe: looking for a way to read excel attachments PinmemberXiAoYanG14-Dec-04 4:36 
Generalparse xml utf-8 &amp; utf-16 PinmemberSancho-Panso12-May-04 1:52 
GeneralRe: parse xml utf-8 &amp; utf-16 PinmemberLymington13-May-04 0:20 
GeneralRe: parse xml utf-8 &amp; utf-16 PinmemberLymington3-Jun-04 21:52 
GeneralRe: parse xml utf-8 &amp; utf-16 Pinmembermartyconnelly12-Jun-04 7:23 
GeneralRe: parse xml utf-8 &amp; utf-16 PinmemberLymington13-Jun-04 6:49 
GeneralRe: parse xml utf-8 &amp; utf-16 PinmemberLymington13-Jun-04 6:56 
GeneralShort, but fine PinmemberStHubi18-Mar-04 20:35 

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.

| Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 5 Jan 2007
Article Copyright 2004 by Lymington
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid