예제 #1
0
파일: Element.cpp 프로젝트: 119/vdc
Element::Element(Document* pOwnerDocument, const Element& element): 
	AbstractContainerNode(pOwnerDocument, element),
	_name(pOwnerDocument->namePool().insert(element._name)),
	_pFirstAttr(0)
{
	Attr* pAttr = element._pFirstAttr;
	while (pAttr)
	{
		Attr* pClonedAttr = static_cast<Attr*>(pAttr->copyNode(false, pOwnerDocument));
		setAttributeNode(pClonedAttr);
		pClonedAttr->release();
		pAttr = static_cast<Attr*>(pAttr->_pNext);
	}
}
예제 #2
0
파일: Element.cpp 프로젝트: 119/vdc
void Element::setAttribute(const XMLString& name, const XMLString& value)
{
	Attr* pAttr = getAttributeNode(name);
	if (pAttr)
	{
		pAttr->setValue(value);
	}
	else
	{
		pAttr = ownerDocument()->createAttribute(name);
		pAttr->setValue(value);
		setAttributeNode(pAttr);
		pAttr->release();
	}
}
예제 #3
0
파일: Element.cpp 프로젝트: 119/vdc
void Element::setAttributeNS(const XMLString& namespaceURI, const XMLString& qualifiedName, const XMLString& value)
{
	Attr* pAttr = getAttributeNodeNS(namespaceURI, qualifiedName);
	if (pAttr)
	{
		pAttr->setValue(value);
	}
	else
	{
		pAttr = _pOwner->createAttributeNS(namespaceURI, qualifiedName);
		pAttr->setValue(value);
		setAttributeNodeNS(pAttr);
		pAttr->release();
	}
}
예제 #4
0
void ElementTest::testAttrMapNS()
{
	AutoPtr<Document> pDoc = new Document;
	AutoPtr<Element> pElem = pDoc->createElementNS("urn:ns1", "elem");

	AutoPtr<NamedNodeMap> pNNM = pElem->attributes();
	assert (pNNM->length() == 0);
	
	pElem->setAttributeNS("urn:ns1", "a1", "v1");
	assert (pNNM->length() == 1);
	assert (pNNM->item(0)->nodeName() == "a1");
	assert (pNNM->getNamedItemNS("urn:ns1", "a1")->nodeName() == "a1");

	pElem->setAttributeNS("urn:ns1", "a2", "v2");
	assert (pNNM->length() == 2);
	assert (pNNM->item(0)->nodeName() == "a1");
	assert (pNNM->getNamedItem("a1")->nodeName() == "a1");
	assert (pNNM->item(1)->nodeName() == "a2");
	assert (pNNM->getNamedItem("a2")->nodeName() == "a2");
	
	Attr* pAttr = pDoc->createAttributeNS("urn:ns2", "a3");
	pNNM->setNamedItem(pAttr);
	pAttr->release();
	
	assert (pNNM->length() == 3);
	assert (pNNM->item(0)->nodeName() == "a1");
	assert (pNNM->getNamedItemNS("urn:ns1", "a1")->nodeName() == "a1");
	assert (pNNM->item(1)->nodeName() == "a2");
	assert (pNNM->getNamedItemNS("urn:ns1", "a2")->nodeName() == "a2");
	assert (pNNM->item(2)->nodeName() == "a3");
	assert (pNNM->getNamedItemNS("urn:ns2", "a3")->nodeName() == "a3");

	pNNM->removeNamedItemNS("urn:ns1", "a2");
	assert (pNNM->length() == 2);
	assert (!pElem->hasAttributeNS("urn:ns1", "a2"));
	
	pNNM->removeNamedItemNS("urn:ns2", "a3");
	assert (pNNM->length() == 1);
	assert (!pElem->hasAttributeNS("urn:ns2", "a3"));
	
	pElem->removeAttributeNS("urn:ns1", "a1");
	assert (pNNM->length() == 0);
}