Beispiel #1
0
void
sd_xmlElementAdd (
    sd_xmlElement element,
    sd_xmlNode    child)
{
    assert(element);
    assert(child);

    switch ( child->kind ) {
        case SD_XMLNODE_KIND_ELEMENT:
            if ( !element->children ) {
                element->children = sd_listNew();
            }
            if ( element->children ) {
                sd_listAppend(element->children, child);
                sd_xmlElement(child)->parent = element;
            }
            break;
        case SD_XMLNODE_KIND_ATTRIBUTE:
            if ( !element->attributes ) {
                element->attributes = sd_listNew();
            }
            if ( element->attributes ) {
                sd_listAppend(element->attributes, child);
            }
            break;
        case SD_XMLNODE_KIND_DATA:
            assert(!element->data);
            element->data = child;
            break;
        default:
            assert(0);
            break;
    }
}
Beispiel #2
0
static sd_xmlParserElement
sd_xmlParseElement (
    sd_xmlParser  parser,
    c_char      **str)
{
    sd_xmlParserElement   element;
    sd_xmlParserAttribute attribute;
    c_bool                ready   = TRUE;
    c_bool                noError = TRUE;

    element = sd_xmlParserElementNew();

    if ( element ) {
        if ( sd_xmlStringGetIdent(str, &element->name) ) {
            if ( !sd_xmlStringIsEmpty(str) ) {
                element->attributes = sd_listNew();
                if ( element->attributes ) {
                    ready = FALSE;
                } else {
                    noError = FALSE;
                }
            } else {
                ready = TRUE;
            }
        } else {
            SET_XMLPARSER_ERROR(parser, INVALID_XML_FORMAT);
        }
    }

    while ( !ready && noError ) {
        if ( !sd_xmlStringIsEmpty(str) ) {
            attribute = sd_xmlParseAttribute(parser, str);
            if ( attribute ) {
                sd_listAppend(element->attributes, attribute);
            } else {
                noError = FALSE;
            }
        } else {
            ready = TRUE;
        }
    }

    if ( !noError ) {
        sd_xmlParserElementFree(element);
        element = NULL;
    }

    return element;
}