-----Original Message----- From: Gareth Reakes [mailto:[EMAIL PROTECTED] On Behalf Of Gareth Reakes Sent: Wednesday, April 07, 2004 12:17 PM To: [EMAIL PROTECTED] Subject: Re: DOMWriter Questions
Hi, > DOMImplementation *impl = > DOMImplementationRegistry::getDOMImplementation(XMLString::transcode(" > Core")); It specifies a specific implementation to use. For example Core or Load/Save. Take a look at the specs a tutorial or the docs for more info http://xml.apache.org/xerces-c/apiDocs/classDOMImplementationRegistry.ht ml > > 2. What does XMLString::transcode("...") do, and why is it needed? >>It converts from a string to the internal xerces format which supports UTF16. Again, >>take a look at the docs for more info Actually I think it is just the opposite In one of the samples there is a StrX class as follows: // --------------------------------------------------------------- // This is a simple class that lets us do easy (though not terribly // efficient) trancoding of XMLCh data to local code page for display. // --------------------------------------------------------------- class StrX I have modifed that sample class as follows: // --------------------------------------------------------------- // This is a simple class that lets us do easy (though not terribly // efficient) trancoding of XMLCh data to local code page for display. // --------------------------------------------------------------- class StrX { public : // ----------------------------------------------------------- // Constructors and Destructor // ----------------------------------------------------------- StrX ( ) { fLocalForm = NULL; } StrX ( const XMLCh* const toTranscode ) { // Call the private transcoding method fLocalForm = XMLString::transcode ( toTranscode ); } ~StrX ( ) { if ( fLocalForm ) XMLString::release ( &fLocalForm ); } // endif destructor operator= ( const XMLCh* const toTranscode ) { if ( fLocalForm ) release ( ); // Call the private transcoding method fLocalForm = XMLString::transcode(toTranscode); } // endif operator assignment release ( ) { XMLString::release ( &fLocalForm ); fLocalForm = NULL; } // ----------------------------------------------------------- // Getter methods // ----------------------------------------------------------- const char* local ( ) const { return fLocalForm; } private : // ----------------------------------------------------------- // Private data members // // fLocalForm // This is the local code page form of the string. // ----------------------------------------------------------- char* fLocalForm; }; inline ostream& operator<<(ostream& target, const StrX& toDump) { target << toDump.local(); return target; } So I can use the above class as follows, which again is copied from the samples. // --------------------------------------------------------------- // DOMCountHandlers: Overrides of the DOM ErrorHandler interface // --------------------------------------------------------------- bool DOMCountErrorHandler::handleError ( const DOMError& domError ) { fSawErrors = true; /* if ( domError.getSeverity() == DOMError::DOM_SEVERITY_WARNING ) cerr << "\nWarning at file "; else if ( domError.getSeverity() == DOMError::DOM_SEVERITY_ERROR ) cerr << "\nError at file "; else cerr << "\nFatal Error at file "; */ cerr << StrX ( domError.getLocation()->getURI() ) << ", line " << domError.getLocation()->getLineNumber() << ", char " << domError.getLocation()->getColumnNumber() << "\n Message: " << StrX ( domError.getMessage() ) << endl; return true; } // end of dom error handler My mods also allow me to do this: // -------------------------------------------------------- // Recursively Count up the total number of child Elements // under the specified Node. // -------------------------------------------------------- int walkDomChildren ( DOMNode *n, PHSCHEMA ss, int testFlag ) { DOMNode *child; DOMNamedNodeMap * nnm; int count = 0; int i, j; // translation decoder objects StrX element; StrX atrName; StrX atrValue; if ( n ) { if ( n->getNodeType() == DOMNode::ELEMENT_NODE ) { if ( testFlag ) fprintf (stderr, "********** Element ******\n" ); element = n->getLocalName(); // get localized version of name if ( testFlag ) fprintf ( stderr, " LocalName: %s\n", element ); count ++; } // endif got an element nnm = n->getAttributes(); if ( nnm != NULL ) { j = nnm->getLength(); if ( j ) if ( testFlag ) fprintf(stderr, "******** attributes ********\n" ); for ( i = 0; i < j; i++ ) { atrName = nnm->item(i)->getNodeName(); // get localized atr name atrValue = nnm->item(i)->getNodeValue(); // get localized atr value if ( testFlag ) fprintf ( stderr, " %s =\"%s\"\n", atrName, atrValue ); analyseDomChild ( ss, (char*) element, (char*) atrName, (char*) atrValue ); } // end atribute loop delete nnm; } // endif list attributes // free char * objects element.release(); atrName.release(); atrValue.release(); for ( child = n->getFirstChild(); child != 0; child = child->getNextSibling() ) { count += walkDomChildren ( child, ss, testFlag ); } // end recursive loop } // endif got a valid node return count; } // end of count elements recursively int analyseDomChild ( PHSCHEMA ss, char * element, char * atrName, char * atrValue ) { if ( ! strcmp ( element, "schema" ) ) { if ( ! strcmp ( atrName, "targetNamespace" ) ) strcpy ( ss->nameSpace, atrValue ); if ( ! strcmp ( atrName, "elementFormDefault" ) ) if ( ! strcmp ( atrValue, "qualified" ) ) ss->elemntQual = 1; if ( ! strcmp ( atrName, "attributeFormDefault" ) ) if ( ! strcmp ( atrValue, "qualified" ) ) ss->attribQual = 1; } // endif schema return 0; } // analyse dom child All the above code is compiled and working on an IBM z/OS system where EBCDIC is the "native" code page. But as noted by the sample comment warnings // --------------------------------------------------------------- // This is a simple class that lets us do easy (though not terribly // efficient) trancoding of XMLCh data to local code page for display. // --------------------------------------------------------------- The above is probably not a very efficient method . Because it probably entails creating and destroying a transcoder on the fly for every string. I am just guessing. (any one else care to weight in ??? ) http://xml.apache.org/xerces-c/apiDocs/classXMLString.html#z985_14 > 3. What is the advantage of creating your own XML document using the > Xerces CreateDocument API versus just encoding the XML string > manually? I'm new to XML, and to be honest, I don't quite see the > advantage of creating your own document. It seems much easier to > encode the string manually. In both cases, you would need to know the > structure of the tree. If I follow you correctly here then I think you are suggesting just building a string up that is XML. If this is the case then you would not be able to call any of the methods that DOm supports on this string. It would be hard to ensure the XML is well formed and very hard to manipulate it. Gareth -- Gareth Reakes, Managing Director +44-1865-811184 Parthenon Computing http://www.parthcomp.com --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]