Click here to Skip to main content
14,922,882 members
Articles / Programming Languages / Objective C
Article
Posted 14 Mar 2004

Stats

147.4K views
7.9K downloads
46 bookmarked

XML File/Stream Processing

Rate me:
Please Sign up or sign in to vote.
4.50/5 (14 votes)
5 Jan 20072 min read
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.

C#
//
// 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
Artem Moroz22-Apr-08 6:03
MemberArtem Moroz22-Apr-08 6:03 
GeneralDocumentation Anomaly Pin
Garth J Lancaster5-Jan-07 12:26
mveGarth J Lancaster5-Jan-07 12:26 
GeneralRe: Documentation Anomaly Pin
Lymington7-Jan-07 8:09
MemberLymington7-Jan-07 8:09 
QuestionXMJ_deProfundis() returning 2, not zero? Pin
CJayNC27-Dec-06 7:25
MemberCJayNC27-Dec-06 7:25 
AnswerRe: XMJ_deProfundis() returning 2, not zero? Pin
Lymington3-Jan-07 3:47
MemberLymington3-Jan-07 3:47 
QuestionEnumerating through a depth? Pin
TonyCounts19-Apr-06 10:54
MemberTonyCounts19-Apr-06 10:54 
Generalwhat's the meaning of depth Pin
xiyuanzuren12-Apr-06 17:19
Memberxiyuanzuren12-Apr-06 17:19 
GeneralRe: what's the meaning of depth Pin
Lymington17-Apr-06 21:50
MemberLymington17-Apr-06 21:50 
GeneralRe: what's the meaning of depth Pin
xiyuanzuren19-Apr-06 22:17
Memberxiyuanzuren19-Apr-06 22:17 
GeneralBatch Command Pin
Anonymous1-Aug-05 0:13
MemberAnonymous1-Aug-05 0:13 
Generalreplace attribute Pin
An Phung Nguyen2-Jun-05 15:50
MemberAn Phung Nguyen2-Jun-05 15:50 
GeneralRe: replace attribute Pin
Lymington6-Jun-05 6:40
MemberLymington6-Jun-05 6:40 
QuestionHow Can I read tag's Data Field ? Pin
nico9999999995-May-05 0:35
Membernico9999999995-May-05 0:35 
AnswerRe: How Can I read tag's Data Field ? Pin
Lymington5-May-05 4:48
MemberLymington5-May-05 4:48 
Generallooking for a way to read excel attachments Pin
DawnYoshimura21-Jun-04 23:04
MemberDawnYoshimura21-Jun-04 23:04 
GeneralRe: looking for a way to read excel attachments Pin
Lymington22-Jun-04 13:15
MemberLymington22-Jun-04 13:15 
GeneralRe: looking for a way to read excel attachments Pin
XiAoYanG14-Dec-04 4:36
MemberXiAoYanG14-Dec-04 4:36 
Generalparse xml utf-8 &amp; utf-16 Pin
Andrew Tyapuhin12-May-04 1:52
MemberAndrew Tyapuhin12-May-04 1:52 
GeneralRe: parse xml utf-8 &amp; utf-16 Pin
Lymington13-May-04 0:20
MemberLymington13-May-04 0:20 
GeneralRe: parse xml utf-8 &amp; utf-16 Pin
Lymington3-Jun-04 21:52
MemberLymington3-Jun-04 21:52 
GeneralRe: parse xml utf-8 &amp; utf-16 Pin
martyconnelly12-Jun-04 7:23
Membermartyconnelly12-Jun-04 7:23 
GeneralRe: parse xml utf-8 &amp; utf-16 Pin
Lymington13-Jun-04 6:49
MemberLymington13-Jun-04 6:49 
GeneralRe: parse xml utf-8 &amp; utf-16 Pin
Lymington13-Jun-04 6:56
MemberLymington13-Jun-04 6:56 
GeneralShort, but fine Pin
StHubi18-Mar-04 20:35
MemberStHubi18-Mar-04 20:35 

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

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