[xsd-users] How to get a schema location path from existing
xml file
Boris Kolpackov
boris at codesynthesis.com
Mon Jan 4 05:42:31 EST 2010
Hi Mark,
Mark Erlich <mark_erlich at hotmail.com> writes:
> I can't get path for a schema out of the existing xml file! Is there any
> way to get this parameter when parsing a file?
This information is not copied to the object model so the only way to
get it is from the DOM representation. For that you will need to do
the XML-to-DOM parsing yourself. For an example on how to do it see
the multiroot example in the examples/cxx/tree/ directory. Once you
get the DOM document you can do something like this:
#include <xsd/cxx/xml/string.hxx> // xml::transcode
#include <xercesc/validators/schema/SchemaSymbols.hpp>
namespace xml = xsd::cxx::xml;
DOMElement* root = ...
const XMLCh* xsl = root->getAttributeNS (
xercesc::SchemaSymbols::fgURI_XSI,
xercesc::SchemaSymbols::fgXSI_NONAMESPACESCHEMALOCATION);
std::string sl;
if (xsl != 0)
{
sl = xml::transcode<char> (xsl);
}
If you want to store this string as part of the object model, then
you can customize the generated root element class to include this
information. With this approach you can also avoid the DOM creation
step and extract the schema directly location in the parsing
constructor. For more information on how to do this see the wildcard
example in the examples/cxx/tree/custom/ directory.
Boris
More information about the xsd-users
mailing list