You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by "D. Cameron DeHeer" <Ca...@blazesystems.com> on 2005/08/29 21:34:46 UTC

utility classes for element/attribute creation

Hello All,
I am using xerces 2.3.0 to both create and parse XML documents.  My DOM
creation code is full of snippets like the following, which adds an element
"name" with a value "value" to the root node (i.e.  <name>value</name>):

	ch = xercesc::XMLString::transcode("name");
	xercesc::DOMElement *name = doc.createElement(ch);
	xercesc::XMLString::release(&ch);
	root->appendChild(name);

	ch = xercesc::XMLString::transcode("value");
	xercesc::DOMText *value = doc.createTextNode(ch);
	xercesc::XMLString::release(&ch);
	name->appendChild(value);

Are there any exising mechanisms (class/template/macro) to make this code a
little more streamlined to automatically handle all the XMLString
manipulations, or would I need to roll my own?  It would be nice to condense
the above code to something like:

	AddTextElement(doc, root, "name", "value");

It would make the code more readable and save me a lot of typing.  I don't
want to reinvent the wheel if there is already something out there, but I
haven't found it in looking through the xerces API docs.  Thanks in advance
for your insights...
Cameron

D. Cameron DeHeer
Vice President, Research & Development
Blaze Systems Corporation
Cameron.DeHeer@blazesystems.com
+1 (302) 733-7236

Re: utility classes for element/attribute creation

Posted by Axel Weiß <aw...@informatik.hu-berlin.de>.
D. Cameron DeHeer wrote:
>         AddTextElement(doc, root, "name", "value");

Hi Cameron,

Xerces is a standard conforming xml parser and has it's focus on this 
task. On the other hand, every set of convenient access/manipulation 
functions/methods is mostly depending on application. So you have to 
write your own set - however, this is almost straight forward...

Cheers,
			Axel

-- 
Humboldt-Universität zu Berlin
Institut für Informatik
Signalverarbeitung und Mustererkennung
Dipl.-Inf. Axel Weiß
Rudower Chaussee 25
12489 Berlin-Adlershof
+49-30-2093-3050
** www.freesp.de **

---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org