@@ -1429,88 +1429,76 @@ SXE_METHOD(asXML)
1429
1429
xmlOutputBufferPtr outbuf ;
1430
1430
xmlChar * strval ;
1431
1431
int strval_len ;
1432
- char * filename ;
1432
+ char * filename = NULL ;
1433
1433
size_t filename_len ;
1434
1434
1435
- if (ZEND_NUM_ARGS () > 1 ) {
1435
+ if (zend_parse_parameters ( ZEND_NUM_ARGS (), "|p" , & filename , & filename_len ) == FAILURE ) {
1436
1436
RETURN_FALSE ;
1437
1437
}
1438
1438
1439
- if (ZEND_NUM_ARGS () == 1 ) {
1440
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "p" , & filename , & filename_len ) == FAILURE ) {
1441
- RETURN_FALSE ;
1442
- }
1443
-
1444
- sxe = Z_SXEOBJ_P (ZEND_THIS );
1445
- GET_NODE (sxe , node );
1446
- node = php_sxe_get_first_node (sxe , node );
1447
-
1448
- if (node ) {
1449
- if (node -> parent && (XML_DOCUMENT_NODE == node -> parent -> type )) {
1450
- int bytes ;
1451
- bytes = xmlSaveFile (filename , (xmlDocPtr ) sxe -> document -> ptr );
1452
- if (bytes == -1 ) {
1453
- RETURN_FALSE ;
1454
- } else {
1455
- RETURN_TRUE ;
1456
- }
1457
- } else {
1458
- outbuf = xmlOutputBufferCreateFilename (filename , NULL , 0 );
1459
-
1460
- if (outbuf == NULL ) {
1461
- RETURN_FALSE ;
1462
- }
1463
-
1464
- xmlNodeDumpOutput (outbuf , (xmlDocPtr ) sxe -> document -> ptr , node , 0 , 0 , NULL );
1465
- xmlOutputBufferClose (outbuf );
1466
- RETURN_TRUE ;
1467
- }
1468
- } else {
1469
- RETURN_FALSE ;
1470
- }
1471
- }
1472
-
1473
1439
sxe = Z_SXEOBJ_P (ZEND_THIS );
1474
1440
GET_NODE (sxe , node );
1475
1441
node = php_sxe_get_first_node (sxe , node );
1476
1442
1477
- if (node ) {
1443
+ if (!node ) {
1444
+ RETURN_FALSE ;
1445
+ }
1446
+
1447
+ if (filename ) {
1478
1448
if (node -> parent && (XML_DOCUMENT_NODE == node -> parent -> type )) {
1479
- xmlDocDumpMemoryEnc ((xmlDocPtr ) sxe -> document -> ptr , & strval , & strval_len , (const char * ) ((xmlDocPtr ) sxe -> document -> ptr )-> encoding );
1480
- if (!strval ) {
1481
- RETVAL_FALSE ;
1449
+ int bytes ;
1450
+ bytes = xmlSaveFile (filename , (xmlDocPtr ) sxe -> document -> ptr );
1451
+ if (bytes == -1 ) {
1452
+ RETURN_FALSE ;
1482
1453
} else {
1483
- RETVAL_STRINGL (( char * ) strval , strval_len ) ;
1454
+ RETURN_TRUE ;
1484
1455
}
1485
- xmlFree (strval );
1486
1456
} else {
1487
- char * return_content ;
1488
- size_t return_len ;
1489
- /* Should we be passing encoding information instead of NULL? */
1490
- outbuf = xmlAllocOutputBuffer (NULL );
1457
+ outbuf = xmlOutputBufferCreateFilename (filename , NULL , 0 );
1491
1458
1492
1459
if (outbuf == NULL ) {
1493
1460
RETURN_FALSE ;
1494
1461
}
1495
1462
1496
- xmlNodeDumpOutput (outbuf , (xmlDocPtr ) sxe -> document -> ptr , node , 0 , 0 , (const char * ) ((xmlDocPtr ) sxe -> document -> ptr )-> encoding );
1497
- xmlOutputBufferFlush (outbuf );
1463
+ xmlNodeDumpOutput (outbuf , (xmlDocPtr ) sxe -> document -> ptr , node , 0 , 0 , NULL );
1464
+ xmlOutputBufferClose (outbuf );
1465
+ RETURN_TRUE ;
1466
+ }
1467
+ }
1468
+
1469
+ if (node -> parent && (XML_DOCUMENT_NODE == node -> parent -> type )) {
1470
+ xmlDocDumpMemoryEnc ((xmlDocPtr ) sxe -> document -> ptr , & strval , & strval_len , (const char * ) ((xmlDocPtr ) sxe -> document -> ptr )-> encoding );
1471
+ if (!strval ) {
1472
+ RETVAL_FALSE ;
1473
+ } else {
1474
+ RETVAL_STRINGL ((char * )strval , strval_len );
1475
+ }
1476
+ xmlFree (strval );
1477
+ } else {
1478
+ char * return_content ;
1479
+ size_t return_len ;
1480
+ /* Should we be passing encoding information instead of NULL? */
1481
+ outbuf = xmlAllocOutputBuffer (NULL );
1482
+
1483
+ if (outbuf == NULL ) {
1484
+ RETURN_FALSE ;
1485
+ }
1486
+
1487
+ xmlNodeDumpOutput (outbuf , (xmlDocPtr ) sxe -> document -> ptr , node , 0 , 0 , (const char * ) ((xmlDocPtr ) sxe -> document -> ptr )-> encoding );
1488
+ xmlOutputBufferFlush (outbuf );
1498
1489
#ifdef LIBXML2_NEW_BUFFER
1499
- return_content = (char * )xmlOutputBufferGetContent (outbuf );
1500
- return_len = xmlOutputBufferGetSize (outbuf );
1490
+ return_content = (char * )xmlOutputBufferGetContent (outbuf );
1491
+ return_len = xmlOutputBufferGetSize (outbuf );
1501
1492
#else
1502
- return_content = (char * )outbuf -> buffer -> content ;
1503
- return_len = outbuf -> buffer -> use ;
1493
+ return_content = (char * )outbuf -> buffer -> content ;
1494
+ return_len = outbuf -> buffer -> use ;
1504
1495
#endif
1505
- if (!return_content ) {
1506
- RETVAL_FALSE ;
1507
- } else {
1508
- RETVAL_STRINGL (return_content , return_len );
1509
- }
1510
- xmlOutputBufferClose (outbuf );
1496
+ if (!return_content ) {
1497
+ RETVAL_FALSE ;
1498
+ } else {
1499
+ RETVAL_STRINGL (return_content , return_len );
1511
1500
}
1512
- } else {
1513
- RETVAL_FALSE ;
1501
+ xmlOutputBufferClose (outbuf );
1514
1502
}
1515
1503
}
1516
1504
/* }}} */
0 commit comments