Ejemplo n.º 1
0
/*
 * call-seq:
 *  value=(content)
 *
 * Set the value for this Attr to +content+
 */
static VALUE set_value(VALUE self, VALUE content)
{
  xmlAttrPtr attr;
  Data_Get_Struct(self, xmlAttr, attr);

  if(attr->children) xmlFreeNodeList(attr->children);

  attr->children = attr->last = NULL;

  if(content) {
    xmlChar *buffer;
    xmlNode *tmp;

    /* Encode our content */
    buffer = xmlEncodeEntitiesReentrant(attr->doc, (unsigned char *)StringValuePtr(content));

    attr->children = xmlStringGetNodeList(attr->doc, buffer);
    attr->last = NULL;
    tmp = attr->children;

    /* Loop through the children */
    for(tmp = attr->children; tmp; tmp = tmp->next) {
      tmp->parent = (xmlNode *)attr;
      tmp->doc = attr->doc;
      if(tmp->next == NULL) attr->last = tmp;
    }

    /* Free up memory */
    xmlFree(buffer);
  }

  return content;
}
Ejemplo n.º 2
0
// -------------------------------------------------------------------------------------
// Sets new value from escaped XML character data that may contain entity references.
//
// The value as if it is an escaped contents from XML file.
// If the value contains entity references, then the resulting
// content of the attribute is a list of TXmlEngTextNode and EntityRefeerence nodes.
// Predefined entities are converted into characters they represent.
//
// @see    TXmlEngAttr::SetValueL(TStringArg)
// -------------------------------------------------------------------------------------
//
EXPORT_C void TXmlEngAttr::SetEscapedValueL(
    const TDesC8& aNewValue)
    {
    if (!LIBXML_ATTRIBUTE) 
    	{
    	User::Leave(KXmlEngErrNullNode);
    	}
    //
    xmlAttrPtr prop = LIBXML_ATTRIBUTE;
    xmlNodePtr new_ch;
    if (!aNewValue.Length())
        {
        prop->last = NULL;
        new_ch = NULL;
        }
    else
        {
        xmlChar* value = xmlCharFromDesC8L(aNewValue);
        new_ch = xmlStringGetNodeList(LIBXML_ATTRIBUTE->doc, value);
        delete value;
        TEST_OOM_FLAG;

        // Set parent property on all child nodes and find pointer to the last node
        xmlNodePtr tmp = new_ch;
        while (tmp)
            {
            tmp->parent = (xmlNodePtr) prop;
            if (!(tmp->next))
                prop->last = tmp;
            tmp = tmp->next;
            }
        }   
    xmlFreeNodeList(prop->children);
    prop->children = new_ch;
    }