[xsd-users] Deleting empty elements
Boris Kolpackov
boris at codesynthesis.com
Wed Jan 28 10:32:41 EST 2009
Hi,
delta42 <delta42 at gmail.com> writes:
> I did not find a definition for DomWriter in my* \CodeSynthesis XSD
> 3.2\include\xercesc* folders so I adapted the sample code to work with
> the DOMLSSerializer, as such:
The sample code in the FAQ was for Xerces-C++ 2-series. I've updated
it to include a version that works for both 2 and 3-series (XSD 3.2.0
ships with Xerces-C++ 3.0.0).
> I'm not sure if there's a faster/better way to do this or not, but it is not
> taking any "noticeable" time on my PC, so this is good.
I think the following version will do the same much faster:
void
remove_empty_elements (DOMElement* e)
{
for (DOMNode* n = e->getFirstChild (); n != 0; )
{
if (n->getNodeType () == DOMNode::ELEMENT_NODE)
{
DOMElement* ne = static_cast<DOMElement*> (n);
n = n->getNextSibling ();
if (ne->getFirstChild () != 0)
remove_empty_elements (ne);
if (ne->getFirstChild () == 0 &&
ne->getAttributes ().getLength () == 0)
{
e->removeChild (ne);
ne->release ();
}
}
else
n = n->getNextSibling ();
}
}
> Validation is another story for me, I find it takes forever, as in
> 10 seconds (E6600 processor/WinXP), but I suspect most of that time
> is parsing my huge amount of schemas, so when I get a chance I may
> cache the schemas in advance, or even implement the binary grammar
> object that I read about on your forum lately.
Yes, that sounds like a good idea. The 'caching' example shows how to
pre-load the schemas and reuse them to parse several documents.
Boris
More information about the xsd-users
mailing list