OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: simple XML for C++ application data-file I/O

[ Lists Home | Date Index | Thread Index ]
  • From: Stewart Rubenstein <sdr@camsoft.com>
  • To: Paul Miller <stele@fxtech.com>
  • Date: Sun, 05 Dec 1999 21:31:38 -0500

I was easily able to use XML for exactly this sort of thing.  For
reading, I used James Clark's expat parser with Andy Dent's expatpp
wrapper for C++, and it dropped in quite easily.  You can get them both
from <http://www.highway1.com.au/adsoftware/expatpp.htm>.

Writing XML is almost too easy to bother getting help for.  You do have
to take some care if you're going to be dealing with text beyond
US-ASCII.  Fortunately, my OS's - MacOS and Windows - both have fairly
decent Unicode support now.

My application already has an object tree, so I just wrote the following
in the base class, and implemented the obvious virtual functions in the
subclasses that can exist in the tree:

void CDXObject::XMLWrite(std::ostream &sink) const
{
	// First write the opening tag and the attributes.
	sink << "<" << XMLObjectName() << std::endl;
	
	// The id is the only totally generic tag
	if (m_objectID != 0)
		sink << " " << kCDXML_id << "=\"" << m_objectID << "\"" << std::endl;

	// This is overridden by subclasses to write any object-specific attributes
	XMLWriteAttributes(sink);
	
	// If there's any 
	if (!XMLNeedToWriteContent() && m_contents.empty())
		sink << "/>";
	else
	{
		sink << ">";
		XMLWriteContent(sink);
           for (CDXObjectContentMap::const_iterator i = m_contents.begin();
			i != m_contents.end();  ++i)
			GetObject(i)->XMLWrite(sink);	// write each of the contained objects
		sink << "</" << XMLObjectName() << ">";
	}
}

Paul Miller wrote:
> 
> > :: I've seen a lot of discussion about DOM, SAX, RDF, etc. but none of the
> > :: solutions I've seen are very simple or straightforward for generic
> > :: application data I/O (ie. non web, e-commerce, Java-type stuff). In
> > :: other words, I'm about to roll my own, and would like to gauge interest
> > :: in a small callback-based API for simple XML I/O.
> 
> > Not sure what you mean. Are you talking about IPC, RPC?
> > Have you looked at XML-RPC and SOAP?
> 
> I should have been more clear. I just want to use XML for simple
> non-web-bound application data files (document files). I need a
> non-validating parser that I can use to efficiently parse my application
> data, without all the complexity (and overhead) of something like DOM,
> but not as general-purpose as expat.
> 
> > <Heh. Nine acronyms embedded in one brief msg.>
> 
> Yeah, XML has definitely helped spawn plenty of new TLAs.
> 
> --
> Paul Miller - stele@fxtech.com
> 
> xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev@ic.ac.uk
> Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/ and on CD-ROM/ISBN 981-02-3594-1
> To unsubscribe, mailto:majordomo@ic.ac.uk the following message;
> unsubscribe xml-dev
> To subscribe to the digests, mailto:majordomo@ic.ac.uk the following message;
> subscribe xml-dev-digest
> List coordinator, Henry Rzepa (mailto:rzepa@ic.ac.uk)

xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev@ic.ac.uk
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/ and on CD-ROM/ISBN 981-02-3594-1
To unsubscribe, mailto:majordomo@ic.ac.uk the following message;
unsubscribe xml-dev
To subscribe to the digests, mailto:majordomo@ic.ac.uk the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa@ic.ac.uk)






 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS