Provide a suite of common XML utilities.
More...
Detailed Description
- Outline
-
-
- Purpose:
- Provide a suite of common XML utilities.
-
- Classes:
-
- See also:
-
- Description:
- This component provides a namespace,
balxml::Util
, for various XML utilities. Included is a method for extracting the targetNamespace
from an XSD schema. Any top-level XSD schema must have a targetNamespace
attribute in the <schema>
element that identifies the namespace that the XSD schema defines.
- Note that a valid XSD file must have this attribute for the root element
<schema>
and the only place that the token "targetNamespace" can appear prior to its occurrence as the required attribute is in the comment string(s) before <schema>
. And any comments cannot be embedded in other comments or inside a tag. The extraction algorithm relies on these XML facts to jump over any comments prior to the first occurrence of "targetNamespace" and extract the attribute value. It leaves all other validation of xsdSource
to a parser.
-
- Usage:
static const char *targetNs = "http://localhost:2000/calc.wsdl";
static const char goodSchema[] =
"<?xml version='1.0' encoding='UTF-8'?>"
" <schema targetNamespace='http://localhost:2000/calc.wsdl'"
" elementFormDefault='qualified'"
" xmlns='http://www.w3.org/2001/XMLSchema'"
" xmlns:xs='http://www.w3.org/2001/XMLSchema'"
" xmlns:bdem='http://bloomberg.com/schemas/bdem'"
" xmlns:m_bascalc='http://localhost:2000/calc.wsdl'"
" xmlns:tns='http://localhost:2000/calc.wsdl'"
" <xs:complexType name='Options'>"
" <xs:sequence>"
" <xs:element name='MaxDepth' type='xs:int'"
" minOccurs='0' maxOccurs='1'"
" default='32'"
" bdem:allowsDirectManipulation='0'>"
" </xs:element>"
" </xs:sequence>"
" </xs:complexType>"
" <complexType name='Configuration'>"
" <sequence>"
" <element name='Options' type='m_bascalc:Options'/>"
" </sequence>"
" </complexType>"
" <element name='Configuration' type='m_bascalc:Options'/>"
"</schema>";
static const char badSchema1[] =
"<?xml version='1.0' encoding='UTF-8'?>"
" elementFormDefault='qualified'"
" xmlns='http://www.w3.org/2001/XMLSchema'"
" xmlns:xs='http://www.w3.org/2001/XMLSchema'"
" xmlns:bdem='http://bloomberg.com/schemas/bdem'"
" xmlns:m_bascalc='http://localhost:2000/calc.wsdl'"
" xmlns:tns='http://localhost:2000/calc.wsdl'"
" <xs:complexType name='Options'>"
" <xs:sequence>"
" <xs:element name='MaxDepth' type='xs:int'"
" minOccurs='0' maxOccurs='1'"
" default='32'"
" bdem:allowsDirectManipulation='0'>"
" </xs:element>"
" </xs:sequence>"
" </xs:complexType>"
" <complexType name='Configuration'>"
" <sequence>"
" <element name='Options' type='m_bascalc:Options'/>"
" </sequence>"
" </complexType>"
" <element name='Configuration' type='m_bascalc:Options'/>"
"</schema>";
bsl::string strGood(goodSchema);
bsl::string strBad1(badSchema1);
bsl::string resultNs;
bool rc;
rc = balxml::Util::extractNamespaceFromXsd(strGood, &resultNs);
assert(rc);
assert(resultNs == targetNs);
resultNs.clear();
rc = balxml::Util::extractNamespaceFromXsd(strBad1, &resultNs);
assert(!rc);