[patch] Attr values as Text nodes
Harri Porten
porten at kde.org
Sat Mar 22 22:33:16 GMT 2008
Hi!
A comment in the AttrImpl::setValue() function suggested to create a text
child node for the value - as suggested by the DOM spec. I don't have know
what the spec'ed behavior for the initial Attr node would be. But it makes
sense that the value should be represented as a text node right away. Test
10 of Acid 3 expects this too and it makes some sense.
The attached patch makes the Attr node have a text child node right away.
Could be done lazily? Dunno.
I have also attached the relevant part of Acid 3 and a small addition of
mine testing for empty/missing attribute values.
Harri.
-------------- next part --------------
Index: xml/dom_elementimpl.cpp
===================================================================
--- xml/dom_elementimpl.cpp (revision 788487)
+++ xml/dom_elementimpl.cpp (working copy)
@@ -73,6 +73,8 @@
if (m_prefix)
m_prefix->ref();
m_specified = true; // we don't yet support default attributes
+
+ createTextChild();
}
AttrImpl::~AttrImpl()
@@ -82,6 +84,17 @@
m_prefix->deref();
}
+void AttrImpl::createTextChild()
+{
+ // add a text node containing the attribute value
+ if (m_value->length() > 0) {
+ TextImpl* textNode = ownerDocument()->createTextNode(m_value);
+ int exceptioncode;
+ appendChild(textNode, exceptioncode);
+ assert(exceptioncode == 0);
+ }
+}
+
DOMString AttrImpl::nodeName() const
{
return name();
@@ -120,6 +133,16 @@
return getDocument()->getName(NamespaceId, m_attrId >> 16);
}
+void AttrImpl::removeChild(NodeImpl *oldChild, int &exceptioncode)
+{
+ // unset attribute value
+ m_value->deref();
+ m_value = new DOMStringImpl(0, 0);
+ m_value->ref();
+
+ NodeBaseImpl::removeChild(oldChild, exceptioncode);
+}
+
DOMString AttrImpl::localName() const
{
if (m_htmlCompat)
@@ -152,8 +175,6 @@
{
exceptioncode = 0;
- // ### according to the DOM docs, we should create an unparsed Text child
- // node here
// do not interprete entities in the string, its literal!
// NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly
@@ -171,6 +192,10 @@
if (m_value == v.implementation())
return;
+ int e = 0;
+ removeChildren();
+ appendChild(ownerDocument()->createTextNode(v.implementation()), e);
+
if (m_element && m_attrId == ATTR_ID)
m_element->updateId(m_value, v.implementation());
Index: xml/dom_elementimpl.h
===================================================================
--- xml/dom_elementimpl.h (revision 788487)
+++ xml/dom_elementimpl.h (working copy)
@@ -60,6 +60,7 @@
private:
AttrImpl(const AttrImpl &other);
AttrImpl &operator = (const AttrImpl &other);
+ void createTextChild();
public:
// DOM methods & attributes for Attr
@@ -77,6 +78,7 @@
virtual DOMString prefix() const;
virtual void setPrefix(const DOMString &_prefix, int &exceptioncode );
virtual DOMString namespaceURI() const;
+ virtual void removeChild (NodeImpl *oldChild, int &exceptioncode);
virtual DOMString localName() const;
virtual DOMString nodeValue() const;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.kde.org/mailman/private/kfm-devel/attachments/20080322/3eb34dbf/attachment.html>
More information about the kfm-devel
mailing list