gareth 2003/01/29 11:43:42
Modified: c/src/xercesc/parsers AbstractDOMParser.cpp
Log:
Updated to set Level 3 TypeInfo
Revision Changes Path
1.34 +88 -19 xml-xerces/c/src/xercesc/parsers/AbstractDOMParser.cpp
Index: AbstractDOMParser.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/parsers/AbstractDOMParser.cpp,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- AbstractDOMParser.cpp 29 Jan 2003 15:24:45 -0000 1.33
+++ AbstractDOMParser.cpp 29 Jan 2003 19:43:42 -0000 1.34
@@ -95,8 +95,8 @@
#include <xercesc/dom/impl/DOMNodeIDMap.hpp>
#include <xercesc/validators/common/ContentSpecNode.hpp>
#include <xercesc/validators/common/GrammarResolver.hpp>
-
-
+#include <xercesc/validators/schema/SchemaSymbols.hpp>
+#include <iostream>
XERCES_CPP_NAMESPACE_BEGIN
@@ -677,6 +677,10 @@
fCurrentNode = fCurrentParent;
fCurrentParent = fNodeStack->pop();
+ //validation is performed after the startElement event so we have to associate
the info here
+ ((DOMElementImpl *)(fCurrentNode))->setTypeInfo(elemDecl.getDOMTypeInfoName(),
elemDecl.getDOMTypeInfoUri());
+
+
// If we've hit the end of content, clear the flag
if (fNodeStack->empty())
fWithinElement = false;
@@ -762,9 +766,13 @@
chLatin_x, chLatin_m, chLatin_l, chLatin_n, chLatin_s, chNull
};
- if (fScanner -> getDoNamespaces()) { //DOM Level 2, doNamespaces on
+ static const XMLCh XSI[] = {
+ chLatin_x, chLatin_s, chLatin_i, chNull
+ };
- XMLBufBid bbURI(&fBufMgr);
+ if (fScanner -> getDoNamespaces()) { //DOM Level 2, doNamespaces on
+
+ XMLBufBid bbURI(&fBufMgr);
XMLBuffer& bufURI = bbURI.getBuffer();
XMLCh* namespaceURI = 0;
@@ -783,6 +791,13 @@
elem = createElementNSNode(namespaceURI, elemQName.getRawBuffer());
elemImpl = (DOMElementImpl *) elem;
+
+ //get the list for use in the loop
+ XMLAttDefList* defAttrs = 0;
+ if(elemDecl.hasAttDefs()) {
+ defAttrs = &elemDecl.getAttDefList();
+ }
+
for (unsigned int index = 0; index < attrCount; ++index) {
const XMLAttr* oneAttrib = attrList.elementAt(index);
unsigned int attrURIId = oneAttrib -> getURIId();
@@ -817,6 +832,31 @@
}
attr->setSpecified(oneAttrib->getSpecified());
+ if(defAttrs != 0) {
+ XMLAttDef *attDef = defAttrs->findAttDef(attrURIId,
oneAttrib->getQName());
+ if(attDef != 0) {
+ attr->setTypeInfo(attDef->getDOMTypeInfoName(),
attDef->getDOMTypeInfoUri());
+ attDef->reset();
+ }
+ }
+ else {
+ const XMLCh *name = oneAttrib->getName();
+ if (XMLString::equals(oneAttrib->getPrefix(), XSI)) {
+ if(XMLString::equals(name, SchemaSymbols::fgXSI_TYPE)) {
+ attr->setTypeInfo(SchemaSymbols::fgDT_QNAME,
SchemaSymbols::fgURI_SCHEMAFORSCHEMA);
+ }
+ else if(XMLString::equals(name, SchemaSymbols::fgATT_NILL)) {
+ attr->setTypeInfo(SchemaSymbols::fgDT_BOOLEAN,
SchemaSymbols::fgURI_SCHEMAFORSCHEMA);
+ }
+ else if(XMLString::equals(name,
SchemaSymbols::fgXSI_NONAMESPACESCHEMALOCACTION)) {
+ attr->setTypeInfo(SchemaSymbols::fgDT_ANYURI,
SchemaSymbols::fgURI_SCHEMAFORSCHEMA);
+ }
+ }
+ else {
+ //for normal ns attrs
+ attr->setTypeInfo(SchemaSymbols::fgDT_ANYURI,
SchemaSymbols::fgURI_SCHEMAFORSCHEMA);
+ }
+ }
}
}
else { //DOM Level 1
@@ -857,14 +897,13 @@
while (defAttrs->hasMoreElements())
{
attr = &defAttrs->nextElement();
- const XMLAttDef::DefAttTypes defType = attr->getDefaultType();
+ const XMLAttDef::DefAttTypes defType = attr->getDefaultType();
if ((defType == XMLAttDef::Default)
|| (defType == XMLAttDef::Fixed))
{
- if (attr->getValue() != 0)
- {
- if (fScanner->getDoNamespaces())
+
+ if (fScanner->getDoNamespaces())
{
// DOM Level 2 wants all namespace declaration attributes
// to be bound to "http://www.w3.org/2000/xmlns/"
@@ -881,29 +920,59 @@
uriId = fScanner->getXMLNSNamespaceId();
if (uriId != fScanner->getEmptyNamespaceId()) { //TagName
has a prefix
namespaceURI = fScanner->getURIText(uriId);
- }
+ }
insertAttr = (DOMAttrImpl *) fDocument->createAttributeNS(
- namespaceURI, // NameSpaceURI
- qualifiedName); // qualified name
+
namespaceURI, // NameSpaceURI
+
qualifiedName); // qualified name
- DOMNode* remAttr =
elemImpl->setDefaultAttributeNodeNS(insertAttr);
- if (remAttr)
+ DOMAttr* remAttr =
elemImpl->setDefaultAttributeNodeNS(insertAttr);
+ if (remAttr)
remAttr->release();
+
+ if (attr->getValue() != 0)
+ {
+ insertAttr->setValue(attr->getValue());
+ insertAttr->setSpecified(false);
+ }
+
}
- else
+ else
{
// Namespaces is turned off...
insertAttr = (DOMAttrImpl *)
fDocument->createAttribute(attr->getFullName());
+
DOMNode* remAttr =
elemImpl->setDefaultAttributeNode(insertAttr);
- if (remAttr)
+ if (remAttr)
remAttr->release();
+
+ //need to do this before the get as otherwise we overwrite
any value in the attr
+ if (attr->getValue() != 0)
+ {
+ insertAttr->setValue(attr->getValue());
+ insertAttr->setSpecified(false);
+ }
+
+ if(insertAttr) {
+ insertAttr = (DOMAttrImpl
*)(elemImpl->getAttributeNode(attr->getFullName()));
+ insertAttr->setTypeInfo(attr->getDOMTypeInfoName(),
attr->getDOMTypeInfoUri());
+ }
}
- insertAttr->setValue(attr->getValue());
- insertAttr->setSpecified(false);
+ }
+ else {
+ //we deal with the non namespace attrs down here as we are
iterating over the XMLAttDefs anyway
+ if(!fScanner->getDoNamespaces()) {
+ if(insertAttr == 0) {
+ insertAttr = (DOMAttrImpl
*)(elemImpl->getAttributeNode(attr->getFullName()));
+ }
+ if(insertAttr)
+ insertAttr->setTypeInfo(attr->getDOMTypeInfoName(),
attr->getDOMTypeInfoUri());
}
}
+
+ insertAttr = 0;
+ attr->reset();
}
}
@@ -916,7 +985,7 @@
fWithinElement = true;
// If an empty element, do end right now (no endElement() will be called)
- if (isEmpty)
+ if (isEmpty)
endElement(elemDecl, urlId, isRoot, elemPrefix);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]