diff --git a/src/scripting/toplevel/XML.cpp b/src/scripting/toplevel/XML.cpp index a2c60cc49f..a31ae54afa 100644 --- a/src/scripting/toplevel/XML.cpp +++ b/src/scripting/toplevel/XML.cpp @@ -564,7 +564,11 @@ _NR XML::getVariableByMultiname(const multiname& name, GET_VARIABLE_OP } bool isAttr=name.isAttribute; + //Normalize the name to the string form const tiny_string normalizedName=name.normalizedName(); + //TODO: support namespaces + assert_and_throw(name.ns.size()>0 && name.ns[0].name==""); + const char *buf=normalizedName.raw_buf(); if(!normalizedName.empty() && normalizedName.charAt(0)=='@') { @@ -574,13 +578,9 @@ _NR XML::getVariableByMultiname(const multiname& name, GET_VARIABLE_OP if(isAttr) { //Lookup attribute - //TODO: support namespaces - assert_and_throw(name.ns.size()>0 && name.ns[0].name==""); - if(normalizedName.empty()) return _MR(getAllAttributes()); - //Normalize the name to the string form assert(node); //To have attributes we must be an Element xmlpp::Element* element=dynamic_cast(node); @@ -606,9 +606,6 @@ _NR XML::getVariableByMultiname(const multiname& name, GET_VARIABLE_OP else { //Lookup children - //TODO: support namespaces - assert_and_throw(name.ns.size()>0 && name.ns[0].name==""); - //Normalize the name to the string form assert(node); const xmlpp::Node::NodeList& children=node->get_children(buf); xmlpp::Node::NodeList::const_iterator it=children.begin(); @@ -634,6 +631,34 @@ _NR XML::getVariableByMultiname(const multiname& name, GET_VARIABLE_OP } } +void XML::setVariableByMultiname(const multiname& name, ASObject* o) +{ + bool isAttr=name.isAttribute; + //Normalize the name to the string form + const tiny_string normalizedName=name.normalizedName(); + //TODO: support namespaces + assert_and_throw(name.ns.size()>0 && name.ns[0].name==""); + + const char *buf=normalizedName.raw_buf(); + if(!normalizedName.empty() && normalizedName.charAt(0)=='@') + { + isAttr=true; + buf+=1; + } + if(isAttr) + { + //To have attributes we must be an Element + xmlpp::Element* element=dynamic_cast(node); + assert_and_throw(element); + element->set_attribute(name.name_s, o->toString()); + } + else + { + xmlpp::Element* child=node->add_child(name.name_s); + child->add_child_text(o->toString()); + } +} + bool XML::hasPropertyByMultiname(const multiname& name, bool considerDynamic) { if(node==NULL || considerDynamic == false) diff --git a/src/scripting/toplevel/XML.h b/src/scripting/toplevel/XML.h index 0f4186c101..27360c027d 100644 --- a/src/scripting/toplevel/XML.h +++ b/src/scripting/toplevel/XML.h @@ -81,6 +81,7 @@ friend class XMLList; void getDescendantsByQName(const tiny_string& name, const tiny_string& ns, XMLVector& ret); _NR getVariableByMultiname(const multiname& name, GET_VARIABLE_OPTION opt); bool hasPropertyByMultiname(const multiname& name, bool considerDynamic); + void setVariableByMultiname(const multiname& name, ASObject* o); tiny_string toString(); void toXMLString_priv(xmlBufferPtr buf); bool hasSimpleContent() const;