예제 #1
0
파일: Element.cpp 프로젝트: meh/xmlpp
Node*
Element::_getElementById (const DOMString& id)
{
    for (size_t i = 0; i < _children.length(); i++) {
        NamedNodeMap attrs = _children.item(i)->attributes();

        for (size_t h = 0; h < attrs.length(); h++) {
            Attr* attr = (Attr*) attrs.item(h);

            if (attr->_isId) {
                if (attr->value() == id) {
                    return _children.item(i);
                }
            }
        }
    }

    for (size_t i = 0; i < _children.length(); i++) {
        Node* element = _children.item(i)->_getElementById(id);

        if (element) {
            return element;
        }
    }

    return NULL;
}
예제 #2
0
파일: Element.cpp 프로젝트: meh/xmlpp
DOMString
Element::getAttribute (const DOMString& name)
{
    Attr* attr = (Attr*) _attributes.getNamedItem(name);

    if (attr == NULL) {
        return "";
    }
    else {
        return attr->value();
    }
}
예제 #3
0
파일: Element.cpp 프로젝트: meh/xmlpp
void
Element::setAttribute (const DOMString& name, const DOMString& value) throw()
{
    Attr* attr = (Attr*) _attributes.getNamedItem(name);

    if (attr == NULL) {
        attr = new Attr(this->ownerDocument(), name);
        this->setAttributeNode(attr);
    }

    attr->value(value);
    attr->_ownerElement = this;
}
JSValue JSElement::setAttributeNode(ExecState* exec, const ArgList& args)
{
    ExceptionCode ec = 0;
    Attr* newAttr = toAttr(args.at(0));
    if (!newAttr) {
        setDOMException(exec, TYPE_MISMATCH_ERR);
        return jsUndefined();
    }

    Element* imp = impl();
    if (!allowSettingSrcToJavascriptURL(exec, imp, newAttr->name(), newAttr->value()))
        return jsUndefined();

    JSValue result = toJS(exec, globalObject(), WTF::getPtr(imp->setAttributeNode(newAttr, ec)));
    setDOMException(exec, ec);
    return result;
}
예제 #5
0
파일: Element.cpp 프로젝트: meh/xmlpp
Node*
Element::cloneNode (bool deep)
{
    Element* element = new Element(NULL, this->nodeName());

    for (unsigned long i = 0; i < _attributes.length(); i++) {
        Attr* attr = (Attr*) _attributes.item(i);
        element->setAttribute(attr->name(), attr->value());
    }

    if (deep) {
        for (unsigned long i = 0; i < _children.length(); i++) {
            element->appendChild(_children.item(i)->cloneNode(true));
        }
    }

    return element;
}
예제 #6
0
void DOMSerializer::handleElement(const Element* pElement) const
{
	if (_pContentHandler) 
	{
		AutoPtr<NamedNodeMap> pAttrs = pElement->attributes();
		AttributesImpl saxAttrs;
		for (unsigned long i = 0; i < pAttrs->length(); ++i)
		{
			Attr* pAttr = static_cast<Attr*>(pAttrs->item(i));
			saxAttrs.addAttribute(pAttr->namespaceURI(), pAttr->localName(), pAttr->nodeName(), CDATA, pAttr->value(), pAttr->specified());
		}
		_pContentHandler->startElement(pElement->namespaceURI(), pElement->localName(), pElement->tagName(), saxAttrs);
	}
	iterate(pElement->firstChild());
	if (_pContentHandler)
		_pContentHandler->endElement(pElement->namespaceURI(), pElement->localName(), pElement->tagName());
}