Пример #1
0
DOMAttr *DOMNodeIDMap::find(const XMLCh *id)
{
    //
    //  Get the hashcode for the supplied string.
    //
	XMLSize_t initalHash = XMLString::hash(id, fSize-1, ((DOMDocumentImpl *)fDoc)->getMemoryManager());
	initalHash++;
	XMLSize_t currentHash = initalHash;

	//
	// Loop looking for a slot pointing to an attr with this id.
    //
    while (true)
	{
		DOMAttr *tableSlot = fTable[currentHash];
		if (tableSlot == 0)
        {
            // There is no matching entry in the table
            return 0;
        }


        if ((tableSlot != (DOMAttr *)-1) && XMLString::equals(tableSlot->getValue(), id))
            return tableSlot;

        currentHash += initalHash;  // rehash
        if (currentHash >= fSize)
            currentHash = currentHash % fSize;
    }
    return 0;  // Never gets here, but keeps some compilers happy.
}
Пример #2
0
void SYSTEM::CConfigItem::SetProperties(const char * propName, const char * value)
{
	if(!propName||!value)
	{
		return;
	}
	if(((DOMElement*)itemElement)->hasAttributes())
	{
		DOMNamedNodeMap *pAttributes = ((DOMElement*)itemElement)->getAttributes();
		XMLCh *t = XMLString::transcode(propName);
		DOMAttr *pAttributeNode = (DOMAttr*)pAttributes->getNamedItem(t);
		XMLString::release(&t);
		if(!pAttributeNode)
		{
			return;	//属性名错误,抛出异常
		}
		t = XMLString::transcode(value);
		pAttributeNode->setValue(t);
		XMLString::release(&t);
	}
	else
	{
		return;
	}	 
}
std::string getAttributeByName (DOMNode* node, std::string attrName) {
	cdebug << "getAttr " << attrName << std::endl;
	assert (node->getNodeType () == DOMNode::ELEMENT_NODE);
	
	std::string value = "";
	
	if (node->hasAttributes()) {
		DOMNamedNodeMap *pAttributes = node->getAttributes ();
		
		for (unsigned int i = 0; i < pAttributes->getLength (); i++) {
			DOMAttr* pAttributeNode = (DOMAttr*) pAttributes->item(i);
			char* name = XMLString::transcode(pAttributeNode->getName());
			if (name == attrName) {
				char* tmpValue = XMLString::transcode(pAttributeNode->getValue());
				value = tmpValue;
				XMLString::release(&tmpValue);
			}
			XMLString::release(&name);
		}
	} else {
		cdebug << "Error in file to parse" << std::endl;
		throw ("Error in file to parse attributes");
	}
	cdebug << value << std::endl;
	return value;
} /* std::string getAttributeByName (DOMNode* node, std::string attrName) */
DOMElement* EppCommandInfoLaunchRegistration::toXML( DOMDocument& doc, const DOMString& tag )
{
	DOMElement* elm;
	DOMElement* body = EppUtil::createElementNS(doc, "launch", (tag.isNull()) ? "info" : tag, false, "-1.0");

	DOMAttr* attr = doc.createAttribute(XS("includeMark"));
	attr->setValue( ( this->_includeMark ) ? XS("true") : XS("false") );
	body->setAttributeNode(attr);

	if( this->_phase.phase().length() > 0 )
	{
		DOMElement* elm = this->_phase.toXML(doc, "phase");
		body->appendChild(elm);
	}
	if( this->_appId.isNotNull() )
	{
		if( this->_appId.length() > 0 )
		{
			elm = doc.createElement(XS("applicationID"));
			elm->appendChild(doc.createTextNode(this->_appId));
			body->appendChild(elm);
		}
	}
	return body;
}
Пример #5
0
DOMNode *DOMAttrMapImpl::removeNamedItemNS(const XMLCh *namespaceURI, const XMLCh *localName)
{
    if (this->readOnly())
        throw DOMException(
        DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNamedNodeMapMemoryManager);
    int i = findNamePoint(namespaceURI, localName);
    if (i < 0)
        throw DOMException(DOMException::NOT_FOUND_ERR, 0, GetDOMNamedNodeMapMemoryManager);

    DOMNode * removed = fNodes -> elementAt(i);
    fNodes -> removeElementAt(i);	//remove n from nodes
    castToNodeImpl(removed)->fOwnerNode = fOwnerNode->getOwnerDocument();
    castToNodeImpl(removed)->isOwned(false);

    // Replace it if it had a default value
    // (DOM spec level 2 - Element Interface)

    if (hasDefaults() && (removed != 0))
    {
        DOMAttrMapImpl* defAttrs = ((DOMElementImpl*)fOwnerNode)->getDefaultAttributes();
        DOMAttr* attr = (DOMAttr*)(defAttrs->getNamedItemNS(namespaceURI, localName));
        if (attr != 0)
        {
            DOMAttr* newAttr = (DOMAttr*)attr->cloneNode(true);
            setNamedItemNS(newAttr);
        }
    }

    return removed;
}
Пример #6
0
DOMAttr *DOMNodeIDMap::find(const XMLCh *id)
{
    //
    //  Get the hashcode for the supplied string.
    //
    XMLSize_t initalHash = XMLString::hash(id, fSize-1);
	initalHash++;
	XMLSize_t currentHash = initalHash;

	//
	// Loop looking for a slot pointing to an attr with this id.
    //
	DOMAttr *tableSlot;
    while ((tableSlot= fTable[currentHash])!=0)
	{
        if ((tableSlot != (DOMAttr *)-1) && XMLString::equals(tableSlot->getValue(), id))
            return tableSlot;

        currentHash += initalHash;  // rehash
        if (currentHash >= fSize)
            currentHash = currentHash % fSize;
    }
    // There is no matching entry in the table
    return 0;
}
Пример #7
0
/**
 * Get this AttributeMap in sync with the given "defaults" map.
 * @param defaults The default attributes map to sync with.
 */
void DOMAttrMapImpl::reconcileDefaultAttributes(const DOMAttrMapImpl* defaults) {

    // remove any existing default
    XMLSize_t nsize = getLength();
    for (XMLSSize_t i = nsize - 1; i >= 0; i--) {
        DOMAttr* attr = (DOMAttr*)item(i);
        if (!attr->getSpecified()) {
            removeNamedItemAt(i);
        }
    }

    hasDefaults(false);

    // add the new defaults
    if (defaults) {
        hasDefaults(true);

        if (nsize == 0) {
            cloneContent(defaults);
        }
        else {
            XMLSize_t dsize = defaults->getLength();
            for (XMLSize_t n = 0; n < dsize; n++) {
                DOMAttr* attr = (DOMAttr*)defaults->item(n);

                DOMAttr* newAttr = (DOMAttr*)attr->cloneNode(true);
                setNamedItemNS(newAttr);
                DOMAttrImpl* newAttrImpl = (DOMAttrImpl*) newAttr;
                newAttrImpl->setSpecified(false);
            }
        }
    }
} // reconcileDefaults()
Пример #8
0
void XercesUpdateFactory::completeDeletions(DynamicContext *context)
{
  //    e. Finally, for each node marked for deletion by one of the update primitives listed above, let $N be the node that is marked
  //       for deletion, and let $P be its parent node. The following actions are applied:
  //          i. The parent property of $N is set to empty.
  //         ii. If $N is an attribute node, the attributes property of $P is modified to remove $N.
  //        iii. If $N is a non-attribute node, the children property of $P is modified to remove $N.
  //         iv. If $N is an element, attribute, or text node, and $P is an element node, then upd:removeType($P) is invoked.

  for(DOMNodeSet::iterator i = forDeletion_.begin(); i != forDeletion_.end(); ++i) {
    DOMNode *domnode = *i;

    if(domnode->getNodeType() == DOMNode::ATTRIBUTE_NODE) {
      DOMAttr *attr = (DOMAttr*)domnode;
      DOMElement *owner = attr->getOwnerElement();
      if(owner != 0) {
        owner->removeAttributeNode(attr);
        removeType(owner);
      }
    }
    else {
      DOMNode *parent = domnode->getParentNode();
      if(parent != 0) {
        parent->removeChild(domnode);
        if(domnode->getNodeType() == DOMNode::ELEMENT_NODE ||
           domnode->getNodeType() == DOMNode::TEXT_NODE ||
           domnode->getNodeType() == DOMNode::CDATA_SECTION_NODE) {
          removeType(parent);
        }
      }
    }
  }
}
Пример #9
0
  virtual void attributeEvent(const XMLCh *prefix, const XMLCh *uri, const XMLCh *localname, const XMLCh *value,
                              const XMLCh *typeURI, const XMLCh *typeName)
  {
    assert(node_ && node_->getNodeType() == DOMNode::ELEMENT_NODE);

    DOMNamedNodeMap *attrs = node_->getAttributes();
    DOMAttr *at = (DOMAttr*)attrs->getNamedItemNS(uri, localname);

    // Add the attribute
    if(!at) {
      at = node_->getOwnerDocument()->createAttributeNS(uri, localname);
      if(prefix && *prefix)
        at->setPrefix(prefix);
      attrs->setNamedItemNS(at);
    }

    // Copy the schema normalized value
    at->setNodeValue(value);

    // Copy the attribute's type
    const XMLCh *oldTypeURI, *oldTypeName;
    XercesNodeImpl::typeUriAndName(at, oldTypeURI, oldTypeName);
    if(!XPath2Utils::equals(oldTypeName, typeName) ||
       !XPath2Utils::equals(oldTypeURI, typeURI)) {
      XercesSequenceBuilder::setAttributeTypeInfo(at, typeURI, typeName);
    }
  }
Пример #10
0
// remove the name using index
// avoid calling findNamePoint again if the index is already known
DOMNode * DOMAttrMapImpl::removeNamedItemAt(XMLSize_t index)
{
    DOMNode* removed = DOMNamedNodeMapImpl::removeNamedItemAt(index);

    // Replace it if it had a default value
    // (DOM spec level 1 - Element Interface)
    if (hasDefaults() && (removed != 0))
    {
        DOMAttrMapImpl* defAttrs = ((DOMElementImpl*)fOwnerNode)->getDefaultAttributes();

        const XMLCh* localName = removed->getLocalName();
        DOMAttr* attr = 0;
        if (localName)
            attr = (DOMAttr*)(defAttrs->getNamedItemNS(removed->getNamespaceURI(), localName));
        else
            attr = (DOMAttr*)(defAttrs->getNamedItem(((DOMAttr*)removed)->getName()));

        if (attr != 0)
        {
            DOMAttr* newAttr = (DOMAttr*)attr->cloneNode(true);
            setNamedItem(newAttr);
        }
    }

    return removed;
}
Пример #11
0
const char* SYSTEM::CConfigItem::GetProperties(const char * propName)
{
	if(!propName)
	{
		return NULL;
	}
	if(((DOMElement*)itemElement)->hasAttributes())		//判断当前节点是否存在属性
	{
		DOMNamedNodeMap *pAttributes = ((DOMElement*)itemElement)->getAttributes();
		XMLCh *t = XMLString::transcode(propName);
		DOMAttr *pAttributeNode = (DOMAttr*)pAttributes->getNamedItem(t);
		XMLString::release(&t);
		if( m_curValue != NULL )
			XMLString::release(&m_curValue);
		if(!pAttributeNode)		//属性名称不存在
			m_curValue = NULL;
		else
			m_curValue = XMLString::transcode(pAttributeNode->getValue());
		return m_curValue;
	}
	else
	{
		return NULL;
	}	
}
DOMElement* EppCommandTransferDomain::toXML( DOMDocument& doc, const DOMString& tag )
{
	DOMElement* body = toXMLPoll(doc, tag);

	DOMAttr* attr = doc.createAttribute(XS("op"));
	attr->setValue(this->getOperation());
	ValueVectorOf<DOMAttr*> attrList(1);
	attrList.addElement(attr);

	return toXMLCommon(doc, tag, body, &attrList);
}
Пример #13
0
bool CopyAttr(DOMElement *target, const DOMElement *source, const XMLCh* attrName, bool MustBeFound=true) {
	DOMAttr *attrNode = source->getAttributeNode(attrName);
	if (attrNode==NULL) {
		if (MustBeFound==true) {
			THROW_AWAY(("Mandatory Attribute on Delta Operation Node was not found for CopyAttr()"));
		}
		else return false;
	}
	target->setAttribute(attrName, attrNode->getNodeValue());
	return true;
}
Пример #14
0
const char *SkinElementsMgr::getElementAlias(const char *id)  {
  if(m_doc) {   
    DOMElement * node = m_doc->getElementById(id);
    if (node && !STRCMP(node->getNodeName(),"elementalias")) {
      DOMAttr * attr = node->getAttributeNode("target");
      if( attr && attr->getSpecified() )
        return attr->getValue();
    }
  }
  return NULL;
}
Пример #15
0
	bool Manager::attribute(const DOMNode* n,const u_str attrname) {
		bool result=false;
		if (n != nullptr && !attrname.empty() && n->getNodeType() == DOMNode::ELEMENT_NODE ) {
			DOMElement* enod = (DOMElement*)n;
			DOMAttr* enoda = enod->getAttributeNode(pcx(attrname.c_str()));
			if (enoda != nullptr) {
				const XMLCh* x_attrval = enoda->getNodeValue();
				if (x_attrval != nullptr && x_attrval[0] != 0 ) {
					result = true; //only true if result is not empty.
				}
			}
		}
		return result;
	}
DOMElement* EppCommandCreateLaunchRegistration::toXML( DOMDocument& doc, const DOMString& tag )
{
    DOMElement* elm;
    DOMElement* body = EppUtil::createElementNS(doc, "launch", (tag.isNull()) ? "create" : tag, false, "-1.0");

    if( this->_type.length() > 0 )
    {
        DOMAttr* attr = doc.createAttribute(XS("type"));
        attr->setValue( this->_type);
        body->setAttributeNode(attr);
    }

    if ( this->_phase.phase().length() > 0 )
    {
        DOMElement* elm = this->_phase.toXML(doc, "phase");
        body->appendChild(elm);
    }

    if( (_signedMark.hasSMD()) )
    {   /*RAII*/
        DOMElement* elm = this->_signedMark.toXML(doc, "signedMark");
        body->appendChild(elm);
    }
    if( (_encSignedMark.hasSMD()) )
    {   /*RAII*/
        DOMElement* elm = this->_encSignedMark.toXML(doc, "encodedSignedMark");
        body->appendChild(elm);
    }
    if( this->_noticeID.length() > 0  )
    {
        elm = doc.createElement(XS("noticeID"));
        elm->appendChild(doc.createTextNode(this->_noticeID));
        body->appendChild(elm);
    }
    if( this->_notAfter.length() > 0  )
    {
        elm = doc.createElement(XS("notAfter"));
        elm->appendChild(doc.createTextNode(this->_notAfter));
        body->appendChild(elm);
    }
    if( this->_acceptedDate.length() > 0  )
    {
        elm = doc.createElement(XS("acceptedDate"));
        elm->appendChild(doc.createTextNode(this->_acceptedDate));
        body->appendChild(elm);
    }

    return body;
}
Пример #17
0
void DOMElementImpl::setAttribute(const XMLCh *nam, const XMLCh *val)
{
    if (fNode.isReadOnly())
        throw DOMException(
        DOMException::NO_MODIFICATION_ALLOWED_ERR, 0);

    DOMAttr* newAttr = getAttributeNode(nam);
    if (!newAttr)
    {
        newAttr = this->fNode.getOwnerDocument()->createAttribute(nam);
        fAttributes->setNamedItem(newAttr);
    }

    newAttr->setNodeValue(val);
}
Пример #18
0
/**
 * Move specified attributes from the given map to this one
 */
void DOMAttrMapImpl::moveSpecifiedAttributes(DOMAttrMapImpl* srcmap) {
    XMLSize_t nsize = srcmap->getLength();

    for (XMLSSize_t i = nsize - 1; i >= 0; i--) {
        DOMAttr* attr = (DOMAttr*)srcmap->item(i);
        if (attr->getSpecified()) {
            srcmap->removeNamedItemAt(i);
        }

        if (attr->getLocalName())
            setNamedItemNS(attr);
        else
            setNamedItem(attr);
    }
} // moveSpecifiedAttributes(AttributeMap):void
Пример #19
0
DOMElement* EppLaunchPhase::toXML(DOMDocument &doc, const DOMString &tag)
{
    //DOMElement* elm;
    DOMElement* body = doc.createElement(tag);
    if( this->_sub_phase.length() > 0 )
    {
        DOMAttr* attr = doc.createAttribute(XS("name"));
        attr->setValue( this->_sub_phase );
        body->setAttributeNode(attr);
    }
    if( this->_phase.length() > 0 )
    {
        body->appendChild(doc.createTextNode(this->_phase));
    }
    return body;
}
Пример #20
0
void DOMElementImpl::setAttributeNS(const XMLCh *fNamespaceURI,
    const XMLCh *qualifiedName, const XMLCh *fValue)
{
    if (fNode.isReadOnly())
        throw DOMException(
        DOMException::NO_MODIFICATION_ALLOWED_ERR, 0);

    DOMAttr* newAttr = getAttributeNodeNS(fNamespaceURI, qualifiedName);

    if (!newAttr)
    {
        newAttr = this->fNode.getOwnerDocument()->createAttributeNS(fNamespaceURI, qualifiedName);
        fAttributes->setNamedItemNS(newAttr);
    }

    newAttr->setNodeValue(fValue);
}
Пример #21
0
/* NOTE: need to keep _type field in consideration as attribute type/entitlement depends on it.*/
DOMElement* EppMarkHolder::toXML(DOMDocument &doc, const DOMString &tag)
{
	DOMString attr_name = "type";
	DOMElement* elm;
	DOMElement* body = doc.createElement(tag);

	if( this->_type == EPPMARK_HOLDER )
	{
		attr_name = "entitlement";
	}
	DOMAttr* attr = doc.createAttribute(attr_name);
	attr->setValue( this->_addParam );
	body->setAttributeNode(attr);

	if( this->_name.length() > 0 )
	{
		elm = doc.createElement(XS("name"));
		elm->appendChild(doc.createTextNode(this->_name));
		body->appendChild(elm);
	}
	if( this->_org.length() > 0 )
	{
		elm = doc.createElement(XS("org"));
		elm->appendChild(doc.createTextNode(this->_org));
		body->appendChild(elm);
	}
	body->appendChild(this->_addr.toXML(doc, "addr"));

	if( this->_voice.getNumber().length() > 0 )
	{
		elm = this->_voice.toXML(doc, "voice");
		body->appendChild(elm);
	}
	if( this->_fax.getNumber().length() > 0 )
	{
		elm = this->_fax.toXML(doc, "fax");
		body->appendChild(elm);
	}
	if( this->_email.length() > 0 )
	{
		elm = doc.createElement(XS("email"));
		elm->appendChild(doc.createTextNode(this->_email));
		body->appendChild(elm);
	}
	return body;
}
Пример #22
0
void XercesUpdateFactory::applyReplaceAttribute(const PendingUpdate &update, DynamicContext *context)
{
  const XercesNodeImpl *nodeImpl = (const XercesNodeImpl*)update.getTarget()->getInterface(Item::gXQilla);
  DOMAttr *domnode = (DOMAttr*)nodeImpl->getDOMNode();
  Node::Ptr parentNode = nodeImpl->dmParent(context);
  DOMElement *element = domnode->getOwnerElement();
  DOMDocument *doc = element->getOwnerDocument();

  bool untyped = parentNode->dmNodeKind() == Node::element_string &&
    XPath2Utils::equals(parentNode->getTypeName(), DocumentCache::g_szUntyped) &&
    XPath2Utils::equals(parentNode->getTypeURI(), SchemaSymbols::fgURI_SCHEMAFORSCHEMA);

  Result children = update.getValue();
  Item::Ptr item;
  while((item = children->next(context)).notNull()) {
    const XercesNodeImpl *childImpl = (const XercesNodeImpl*)item->getInterface(Item::gXQilla);
    DOMNode *newChild = importNodeFix(doc, const_cast<DOMNode*>(childImpl->getDOMNode()), /*deep*/true);

    // 1. Error checks:
    //    a. If the QNames of any two attribute nodes in $replacement have implied namespace bindings that conflict with
    //       each other, a dynamic error is raised [err:XUDY0024].
    //    b. If the QName of any attribute node in $replacement has an implied namespace binding that conflicts with a
    //       namespace binding in the "namespaces" property of parent($target), a dynamic error is raised [err:XUDY0024].
    // Checks performed by UpdateFactory

    // 2b. If the type-name property of parent($target) is xs:untyped, then upd:setToUntyped() is invoked
    //     on each element node in $replacement.
    if(!untyped) setTypes(newChild, childImpl->getDOMNode());

    // 2a. For each node in $replacement, the parent property is set to parent($target).
    // 4a. If $target is an attribute node, the attributes property of parent($target) is modified by removing $target
    //     and adding the nodes in $replacement (if any).
    // 4b. If $target is an attribute node, the namespaces property of parent($target) is modified to include namespace
    //     bindings for any attribute namespace prefixes in $replacement that did not already have bindings.
    element->setAttributeNode((DOMAttr*)newChild);
  }

  // 3a. $target is marked for deletion.
  forDeletion_.insert(domnode);

  // 4d. upd:removeType(parent($target)) is invoked.
  removeType(element);

  // Use parentNode, since the attr replace could have removed the original attr
  addToPutSet(parentNode, &update, context);
}
Пример #23
0
DOMNode* DOMAttrImpl::rename(const XMLCh* namespaceURI, const XMLCh* name)
{
    DOMElement* el = getOwnerElement();
    DOMDocumentImpl* doc = (DOMDocumentImpl*)fParent.fOwnerDocument;

    if (el)
        el->removeAttributeNode(this);

    if (!namespaceURI || !*namespaceURI) {
        fName = doc->getPooledString(name);

        if (el)
            el->setAttributeNode(this);

        // and fire user data NODE_RENAMED event
        castToNodeImpl(this)->callUserDataHandlers(DOMUserDataHandler::NODE_RENAMED, this, this);

        return this;
    }
    else {

        // create a new AttrNS
        DOMAttr* newAttr = doc->createAttributeNS(namespaceURI, name);

        // transfer the userData
        doc->transferUserData(castToNodeImpl(this), castToNodeImpl(newAttr));

        // move children to new node
        DOMNode* child = getFirstChild();
        while (child) {
            removeChild(child);
            newAttr->appendChild(child);
            child = getFirstChild();
        }

        // reattach attr to element
        if (el)
            el->setAttributeNodeNS(newAttr);

        // and fire user data NODE_RENAMED event
        castToNodeImpl(newAttr)->callUserDataHandlers(DOMUserDataHandler::NODE_RENAMED, this, newAttr);

        return newAttr;
    }
}
Пример #24
0
void DeltaApplyEngine::Attribute_Insert( XID_t nodeXID, const XMLCh* attr, const XMLCh* value ) {
	vddprintf(("        insert attr at xid=%d\n",(int)nodeXID));
	DOMNode* node = xiddoc->getXidMap().getNodeWithXID( nodeXID );
	if (node==NULL) THROW_AWAY(("node with XID=%d not found",(int)nodeXID));
	DOMAttr* attrNode = xiddoc->createAttribute( attr );
	attrNode->setNodeValue( value );
	DOMNamedNodeMap *attrs = node->getAttributes();
	if (attrs == NULL) {
		if (node->getNodeType() != DOMNode::ELEMENT_NODE) {
			THROW_AWAY(("Attempted to insert an attribute on a non-element node. Perhaps xidmap was corrupted?"));
		} else {
			THROW_AWAY(("Unexpected error encountered: getAttributes() returned NULL for element"));
		}
	} else {
		attrs->setNamedItem( attrNode );
	}
	
}
Пример #25
0
XMLNode *JobXML::deepCopyElement( XMLNode **copy, const XMLNode *original )
{
   // add the element to the copy
   char *nodeName = XMLString::transcode( original->getNodeName() );
   XMLNode *newElement = AddElement( (*copy), nodeName );
   XMLString::release( &nodeName );

   // add its attributes
   if ( original->hasAttributes() )
   {
      DOMNamedNodeMap *attributes = original->getAttributes();
      for( unsigned int i=0; i<attributes->getLength(); i++ )
      {
         DOMAttr *attr = (DOMAttr*)attributes->item( i );
         char *key = XMLString::transcode( attr->getName() );
         char *val = XMLString::transcode( attr->getValue() );
         SetAttribute( newElement, key, val );
         XMLString::release( &key );
         XMLString::release( &val );
      }
   }

   // recursively copy all child elements
   int childElementCount=0;
   XMLNode *itr = original->getFirstChild();
   for ( ; itr != NULL; itr = itr->getNextSibling() )
   {      
      if ( itr->getNodeType() == XMLNode::ELEMENT_NODE )
      {
         deepCopyElement( &newElement, itr );
         childElementCount++;
      }
   }

   // if no child elements, copy this element's text content and we are done
   if ( childElementCount == 0 )
   {
      char *content = XMLString::transcode( original->getTextContent() );
      SetContent( newElement, content );
      XMLString::release( &content );
   }

   return newElement;
}
Пример #26
0
	bool Manager::attribute(const DOMNode* n,const u_str attrname, std::string& attrval) {
		bool result=false;
		if (n != nullptr && !attrname.empty() && n->getNodeType() == DOMNode::ELEMENT_NODE ) {
			DOMElement* enod = (DOMElement*)n;
			DOMAttr* enoda = enod->getAttributeNode(pcx(attrname.c_str()));
			if (enoda != nullptr) {
				const XMLCh* x_attrval = enoda->getNodeValue();
				if (x_attrval != nullptr && x_attrval[0] != 0 ) {
					char* value = (char*)TranscodeToStr(x_attrval,"UTF-8").adopt();
					size_t vl = strlen(value);
					attrval.reserve(vl);
					attrval.assign(value,vl);
					XMLString::release(&value); //delete attr;
					result = true; //only true if result is not empty.
				}
			}
		}
		return result;
	}
Пример #27
0
void DOMElementImpl::setAttributeNS(const XMLCh *fNamespaceURI,
    const XMLCh *qualifiedName, const XMLCh *fValue)
{
    if (fNode.isReadOnly())
        throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNodeMemoryManager);

    int index = DOMDocumentImpl::indexofQualifiedName(qualifiedName);
    if (index < 0)
        throw DOMException(DOMException::NAMESPACE_ERR, 0, GetDOMNodeMemoryManager);

    DOMAttr* newAttr = getAttributeNodeNS(fNamespaceURI, qualifiedName+index);
    if (!newAttr)
    {
        newAttr = fParent.fOwnerDocument->createAttributeNS(fNamespaceURI, qualifiedName);
        fAttributes->setNamedItemNS(newAttr);
    }

    newAttr->setNodeValue(fValue);
}
Пример #28
0
DOMNode *DOMAttrMapImpl::removeNamedItem(const XMLCh *name)
{
    DOMNode* removed = DOMNamedNodeMapImpl::removeNamedItem(name);

    // Replace it if it had a default value
    // (DOM spec level 1 - Element Interface)
    if (hasDefaults() && (removed != 0))
    {
        DOMAttrMapImpl* defAttrs = ((DOMElementImpl*)fOwnerNode)->getDefaultAttributes();
        DOMAttr* attr = (DOMAttr*)(defAttrs->getNamedItem(name));
        if (attr != 0)
        {
            DOMAttr* newAttr = (DOMAttr*)attr->cloneNode(true);
            setNamedItem(newAttr);
        }
    }

    return removed;
}
Пример #29
0
// ---------------------------------------------------------------------------
//
//  Recursively Count up the total number of child Elements under the specified Node.
//  Process attributes of the node, if any.
//
// ---------------------------------------------------------------------------
static int countChildElements(DOMNode *n, bool printOutEncounteredEles)
{
    DOMNode *child;
    int count = 0;
    if (n) {
        if (n->getNodeType() == DOMNode::ELEMENT_NODE)
        {
            if(printOutEncounteredEles) {
                char *name = XMLString::transcode(n->getNodeName());
                cout <<"----------------------------------------------------------"<<endl;
                cout <<"Encountered Element : "<< name << endl;

                XMLString::release(&name);

                if(n->hasAttributes()) {
                    // get all the attributes of the node
                    DOMNamedNodeMap *pAttributes = n->getAttributes();
                    int nSize = pAttributes->getLength();
                    cout <<"\tAttributes" << endl;
                    cout <<"\t----------" << endl;
                    for(int i=0; i<nSize; ++i) {
                        DOMAttr *pAttributeNode = (DOMAttr*) pAttributes->item(i);
                        // get attribute name
                        char *name = XMLString::transcode(pAttributeNode->getName());

                        cout << "\t" << name << "=";
                        XMLString::release(&name);

                        // get attribute type
                        name = XMLString::transcode(pAttributeNode->getValue());
                        cout << name << endl;
                        XMLString::release(&name);
                    }
                }
            }
            ++count;
        }
        for (child = n->getFirstChild(); child != 0; child=child->getNextSibling())
            count += countChildElements(child, printOutEncounteredEles);
    }
    return count;
}
Пример #30
0
void XercesSequenceBuilder::namespaceEvent(const XMLCh *prefix, const XMLCh *uri)
{
  if(currentParent_ != 0) {
    DOMAttr *attr = document_->createAttributeNS(XMLUni::fgXMLNSURIName, prefix == 0 ? XMLUni::fgXMLNSString : prefix);
    if(prefix != 0) attr->setPrefix(XMLUni::fgXMLNSString);
    attr->setValue(uri);

    currentParent_->getAttributes()->setNamedItemNS(attr);
    currentNode_ = attr;
  } else {
    document_ = new (context_->getMemoryManager()) XPathDocumentImpl(XQillaImplementation::getDOMImplementationImpl(), context_->getMemoryManager());

    DOMXPathNamespace *ns = new (document_, (DOMDocumentImpl::NodeObjectType)XPathNamespaceImpl::XPATH_NAMESPACE_OBJECT)
      XPathNamespaceImpl(prefix, uri, 0, document_);

    seq_.addItem(new XercesNodeImpl(ns, (XercesURIResolver*)context_->getDefaultURIResolver()));
    document_ = 0;
    currentNode_ = 0;
  }
}