* xmlTextWriterStartElement: * @writer: the xmlTextWriterPtr * @name: element name * * Start an xml element. * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */
| 946 | * Returns the bytes written (may be 0 because of buffering) or -1 in case of error |
| 947 | */ |
| 948 | int |
| 949 | xmlTextWriterStartElement(xmlTextWriterPtr writer, const xmlChar * name) |
| 950 | { |
| 951 | int count; |
| 952 | int sum; |
| 953 | xmlLinkPtr lk; |
| 954 | xmlTextWriterStackEntry *p; |
| 955 | |
| 956 | if ((writer == NULL) || (name == NULL) || (*name == '\0')) |
| 957 | return -1; |
| 958 | |
| 959 | sum = 0; |
| 960 | lk = xmlListFront(writer->nodes); |
| 961 | if (lk != 0) { |
| 962 | p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk); |
| 963 | if (p != 0) { |
| 964 | switch (p->state) { |
| 965 | case XML_TEXTWRITER_PI: |
| 966 | case XML_TEXTWRITER_PI_TEXT: |
| 967 | return -1; |
| 968 | case XML_TEXTWRITER_NONE: |
| 969 | break; |
| 970 | case XML_TEXTWRITER_ATTRIBUTE: |
| 971 | count = xmlTextWriterEndAttribute(writer); |
| 972 | if (count < 0) |
| 973 | return -1; |
| 974 | sum += count; |
| 975 | /* fallthrough */ |
| 976 | case XML_TEXTWRITER_NAME: |
| 977 | /* Output namespace declarations */ |
| 978 | count = xmlTextWriterOutputNSDecl(writer); |
| 979 | if (count < 0) |
| 980 | return -1; |
| 981 | sum += count; |
| 982 | count = xmlOutputBufferWriteString(writer->out, ">"); |
| 983 | if (count < 0) |
| 984 | return -1; |
| 985 | sum += count; |
| 986 | if (writer->indent) |
| 987 | count = |
| 988 | xmlOutputBufferWriteString(writer->out, "\n"); |
| 989 | p->state = XML_TEXTWRITER_TEXT; |
| 990 | break; |
| 991 | default: |
| 992 | break; |
| 993 | } |
| 994 | } |
| 995 | } |
| 996 | |
| 997 | p = (xmlTextWriterStackEntry *) |
| 998 | xmlMalloc(sizeof(xmlTextWriterStackEntry)); |
| 999 | if (p == 0) { |
| 1000 | xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY, |
| 1001 | "xmlTextWriterStartElement : out of memory!\n"); |
| 1002 | return -1; |
| 1003 | } |
| 1004 | |
| 1005 | p->name = xmlStrdup(name); |
no test coverage detected