#include <xercesc/util/XMLUniDefs.hpp>
#include <log4cpp/Category.hh>
+using namespace xmlconstants;
using namespace xmltooling;
using namespace log4cpp;
using namespace std;
unmarshallAttributes(element);
}
- unmarshallChildElements(element);
-
- /* TODO: Signing
- if (xmlObject instanceof SignableXMLObject) {
- verifySignature(domElement, xmlObject);
- }
- */
+ unmarshallContent(element);
setDOM(element,bindDocument);
return this;
#ifdef _DEBUG
xmltooling::NDC ndc("unmarshallAttributes");
#endif
- static const XMLCh type[]={chLatin_t, chLatin_y, chLatin_p, chLatin_e, chNull};
if (XT_log.isDebugEnabled()) {
auto_ptr_char dname(domElement->getNodeName());
attribute = static_cast<DOMAttr*>(childNode);
const XMLCh* nsuri=attribute->getNamespaceURI();
- if (XMLString::equals(nsuri,XMLConstants::XMLNS_NS)) {
- if (XMLString::equals(attribute->getLocalName(),XMLConstants::XMLNS_PREFIX)) {
+ if (XMLString::equals(nsuri,XMLNS_NS)) {
+ if (XMLString::equals(attribute->getLocalName(),XMLNS_PREFIX)) {
XT_log.debug("found default namespace declaration, adding it to the list of namespaces on the XMLObject");
addNamespace(Namespace(attribute->getValue(), NULL, true));
continue;
continue;
}
}
- else if (XMLString::equals(nsuri,XMLConstants::XSI_NS) && XMLString::equals(attribute->getLocalName(),type)) {
- XT_log.debug("skipping xsi:type declaration");
- continue;
+ else if (XMLString::equals(nsuri,XSI_NS)) {
+ static const XMLCh type[]= UNICODE_LITERAL_4(t,y,p,e);
+ static const XMLCh schemaLocation[]= UNICODE_LITERAL_14(s,c,h,e,m,a,L,o,c,a,t,i,o,n);
+ if (XMLString::equals(attribute->getLocalName(),type)) {
+ XT_log.debug("skipping xsi:type declaration");
+ continue;
+ }
+ else if (XMLString::equals(attribute->getLocalName(),schemaLocation)) {
+ XT_log.debug("storing off xsi:schemaLocation attribute");
+ if (m_schemaLocation)
+ XMLString::release(&m_schemaLocation);
+ m_schemaLocation=XMLString::replicate(attribute->getValue());
+ continue;
+ }
}
- else if (nsuri && !XMLString::equals(nsuri,XMLConstants::XML_NS)) {
+ else if (nsuri && !XMLString::equals(nsuri,XML_NS)) {
XT_log.debug("found namespace-qualified attribute, adding prefix to the list of namespaces on the XMLObject");
addNamespace(Namespace(nsuri, attribute->getPrefix()));
}
}
}
-void AbstractXMLObjectUnmarshaller::unmarshallChildElements(const DOMElement* domElement)
+void AbstractXMLObjectUnmarshaller::unmarshallContent(const DOMElement* domElement)
{
#ifdef _DEBUG
- xmltooling::NDC ndc("unmarshallChildElements");
+ xmltooling::NDC ndc("unmarshallContent");
#endif
if (XT_log.isDebugEnabled()) {
auto_ptr_char dname(domElement->getNodeName());
- XT_log.debug("unmarshalling child elements of DOM element (%s)", dname.get());
+ XT_log.debug("unmarshalling child nodes of DOM element (%s)", dname.get());
}
- DOMNodeList* childNodes = domElement->getChildNodes();
- DOMNode* childNode;
- if (!childNodes || childNodes->getLength()==0) {
+ DOMNode* childNode = domElement->getFirstChild();
+ if (!childNode) {
XT_log.debug("element had no children");
return;
}
- for (XMLSize_t i = 0; i < childNodes->getLength(); i++) {
- childNode = childNodes->item(i);
+ unsigned int position = 0;
+ while (childNode) {
if (childNode->getNodeType() == DOMNode::ELEMENT_NODE) {
const XMLObjectBuilder* builder = XMLObjectBuilder::getBuilder(static_cast<DOMElement*>(childNode));
if (!builder) {
auto_ptr<XMLObject> childObject(builder->buildFromElement(static_cast<DOMElement*>(childNode)));
processChildElement(childObject.get(), static_cast<DOMElement*>(childNode));
childObject.release();
+
+ // Advance the text node position marker.
+ ++position;
}
else if (childNode->getNodeType() == DOMNode::TEXT_NODE) {
- XT_log.debug("processing element content");
- processElementContent(childNode->getNodeValue());
+ XT_log.debug("processing text content at position (%d)", position);
+ setTextContent(childNode->getNodeValue(), position);
}
+
+ childNode = childNode->getNextSibling();
}
}
+
+void AbstractXMLObjectUnmarshaller::processChildElement(XMLObject* child, const DOMElement* childRoot)
+{
+ throw UnmarshallingException("Invalid child element: $1",params(1,child->getElementQName().toString().c_str()));
+}
+
+void AbstractXMLObjectUnmarshaller::processAttribute(const DOMAttr* attribute)
+{
+ auto_ptr<QName> q(XMLHelper::getNodeQName(attribute));
+ throw UnmarshallingException("Invalid attribute: $1",params(1,q->toString().c_str()));
+}