Click here to Skip to main content
11,428,825 members (58,808 online)
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

Share

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 Pin
M A V22-Apr-08 7:03
memberM A V22-Apr-08 7:03 
GeneralDocumentation Anomaly Pin
Garth J Lancaster5-Jan-07 13:26
memberGarth J Lancaster5-Jan-07 13:26 
GeneralRe: Documentation Anomaly Pin
Lymington7-Jan-07 9:09
memberLymington7-Jan-07 9:09 
QuestionXMJ_deProfundis() returning 2, not zero? Pin
CJayNC27-Dec-06 8:25
memberCJayNC27-Dec-06 8:25 
AnswerRe: XMJ_deProfundis() returning 2, not zero? Pin
Lymington3-Jan-07 4:47
memberLymington3-Jan-07 4:47 
QuestionEnumerating through a depth? Pin
TonyCounts19-Apr-06 11:54
memberTonyCounts19-Apr-06 11:54 
Generalwhat's the meaning of depth Pin
xiyuanzuren12-Apr-06 18:19
memberxiyuanzuren12-Apr-06 18:19 
GeneralRe: what's the meaning of depth Pin
Lymington17-Apr-06 22:50
memberLymington17-Apr-06 22:50 
GeneralRe: what's the meaning of depth Pin
xiyuanzuren19-Apr-06 23:17
memberxiyuanzuren19-Apr-06 23:17 
GeneralBatch Command Pin
Anonymous1-Aug-05 1:13
sussAnonymous1-Aug-05 1:13 
Generalreplace attribute Pin
thanhthuyvn_vtajkhskjakjd2-Jun-05 16:50
memberthanhthuyvn_vtajkhskjakjd2-Jun-05 16:50 
GeneralRe: replace attribute Pin
Lymington6-Jun-05 7:40
memberLymington6-Jun-05 7:40 
QuestionHow Can I read tag's Data Field ? Pin
nico9999999995-May-05 1:35
membernico9999999995-May-05 1:35 
AnswerRe: How Can I read tag's Data Field ? Pin
Lymington5-May-05 5:48
memberLymington5-May-05 5:48 
Generallooking for a way to read excel attachments Pin
DawnYoshimura22-Jun-04 0:04
memberDawnYoshimura22-Jun-04 0:04 
GeneralRe: looking for a way to read excel attachments Pin
Lymington22-Jun-04 14:15
memberLymington22-Jun-04 14:15 
GeneralRe: looking for a way to read excel attachments Pin
XiAoYanG14-Dec-04 5:36
memberXiAoYanG14-Dec-04 5:36 
Generalparse xml utf-8 &amp; utf-16 Pin
Sancho-Panso12-May-04 2:52
memberSancho-Panso12-May-04 2:52 
GeneralRe: parse xml utf-8 &amp; utf-16 Pin
Lymington13-May-04 1:20
memberLymington13-May-04 1:20 
GeneralRe: parse xml utf-8 &amp; utf-16 Pin
Lymington3-Jun-04 22:52
memberLymington3-Jun-04 22:52 
GeneralRe: parse xml utf-8 &amp; utf-16 Pin
martyconnelly12-Jun-04 8:23
membermartyconnelly12-Jun-04 8:23 
GeneralRe: parse xml utf-8 &amp; utf-16 Pin
Lymington13-Jun-04 7:49
memberLymington13-Jun-04 7:49 
GeneralRe: parse xml utf-8 &amp; utf-16 Pin
Lymington13-Jun-04 7:56
memberLymington13-Jun-04 7:56 
GeneralShort, but fine Pin
StHubi18-Mar-04 21:35
memberStHubi18-Mar-04 21: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 | Terms of Use | Mobile
Web04 | 2.8.150428.2 | Last Updated 5 Jan 2007
Article Copyright 2004 by Lymington
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid