00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00034 #include <string.h>
00035
00036 #include "wbxml.h"
00037
00038
00039
00040
00041
00042
00043 WBXML_DECLARE(WBXMLError) wbxml_conv_wbxml2xml(WB_UTINY *wbxml, WB_ULONG wbxml_len, WB_UTINY **xml, WBXMLConvWBXML2XMLParams *params)
00044 {
00045 WBXMLEncoder *wbxml_encoder = NULL;
00046 WBXMLTree *wbxml_tree = NULL;
00047 WBXMLError ret = WBXML_OK;
00048
00049
00050 if ((wbxml == NULL) || (wbxml_len == 0) || (xml == NULL))
00051 return WBXML_ERROR_BAD_PARAMETER;
00052
00053 *xml = NULL;
00054
00055
00056 ret = wbxml_tree_from_wbxml(wbxml, wbxml_len, params ? params->lang : WBXML_LANG_UNKNOWN, &wbxml_tree);
00057 if (ret != WBXML_OK) {
00058 WBXML_ERROR((WBXML_CONV, "wbxml2xml convertion failed - WBXML Parser Error: %s",
00059 wbxml_errors_string(ret)));
00060
00061 return ret;
00062 }
00063 else {
00064
00065 if ((wbxml_encoder = wbxml_encoder_create()) == NULL) {
00066 wbxml_tree_destroy(wbxml_tree);
00067 return WBXML_ERROR_NOT_ENOUGH_MEMORY;
00068 }
00069
00070
00071 wbxml_encoder_set_tree(wbxml_encoder, wbxml_tree);
00072
00073
00074 if (params == NULL) {
00075
00076
00077
00078 wbxml_encoder_set_xml_gen_type(wbxml_encoder, WBXML_ENCODER_XML_GEN_INDENT);
00079
00080
00081 wbxml_encoder_set_indent(wbxml_encoder, 0);
00082
00083
00084 wbxml_encoder_set_ignore_empty_text(wbxml_encoder, TRUE);
00085 wbxml_encoder_set_remove_text_blanks(wbxml_encoder, TRUE);
00086 }
00087 else {
00088
00089 wbxml_encoder_set_xml_gen_type(wbxml_encoder, params->gen_type);
00090
00091
00092 if (params->gen_type == WBXML_ENCODER_XML_GEN_INDENT)
00093 wbxml_encoder_set_indent(wbxml_encoder, params->indent);
00094
00095
00096 if (params->keep_ignorable_ws) {
00097 wbxml_encoder_set_ignore_empty_text(wbxml_encoder, FALSE);
00098 wbxml_encoder_set_remove_text_blanks(wbxml_encoder, FALSE);
00099 }
00100 else {
00101 wbxml_encoder_set_ignore_empty_text(wbxml_encoder, TRUE);
00102 wbxml_encoder_set_remove_text_blanks(wbxml_encoder, TRUE);
00103 }
00104 }
00105
00106
00107 ret = wbxml_encoder_encode_to_xml(wbxml_encoder, xml);
00108 if (ret != WBXML_OK) {
00109 WBXML_ERROR((WBXML_CONV, "wbxml2xml convertion failed - WBXML Encoder Error: %s",
00110 wbxml_errors_string(ret)));
00111 }
00112
00113
00114 wbxml_encoder_destroy(wbxml_encoder);
00115 wbxml_tree_destroy(wbxml_tree);
00116 return ret;
00117 }
00118 }
00119
00120
00121 WBXML_DECLARE(WBXMLError) wbxml_conv_xml2wbxml(WB_UTINY *xml, WB_UTINY **wbxml, WB_ULONG *wbxml_len, WBXMLConvXML2WBXMLParams *params)
00122 {
00123 #if !defined( HAVE_EXPAT )
00124
00125 return WBXML_ERROR_NO_XMLPARSER;
00126
00127 #else
00128
00129 WBXMLEncoder *wbxml_encoder = NULL;
00130 WBXMLTree *wbxml_tree = NULL;
00131 WBXMLError ret = WBXML_OK;
00132
00133
00134 if ((xml == NULL) || (wbxml == NULL) || (wbxml_len == NULL))
00135 return WBXML_ERROR_BAD_PARAMETER;
00136
00137 *wbxml = NULL;
00138 *wbxml_len = 0;
00139
00140
00141 ret = wbxml_tree_from_xml(xml, &wbxml_tree);
00142 if (ret != WBXML_OK) {
00143 WBXML_ERROR((WBXML_CONV, "xml2wbxml convertion failed - Error: %s",
00144 wbxml_errors_string(ret)));
00145
00146 return ret;
00147 }
00148 else {
00149
00150 if ((wbxml_encoder = wbxml_encoder_create()) == NULL) {
00151 wbxml_tree_destroy(wbxml_tree);
00152 return WBXML_ERROR_NOT_ENOUGH_MEMORY;
00153 }
00154
00155
00156 wbxml_encoder_set_tree(wbxml_encoder, wbxml_tree);
00157
00158
00159 if (params == NULL) {
00160
00161
00162
00163 wbxml_encoder_set_ignore_empty_text(wbxml_encoder, TRUE);
00164
00165
00166 wbxml_encoder_set_remove_text_blanks(wbxml_encoder, TRUE);
00167
00168
00169 wbxml_encoder_set_use_strtbl(wbxml_encoder, TRUE);
00170 }
00171 else {
00172
00173 wbxml_encoder_set_wbxml_version(wbxml_encoder, params->wbxml_version);
00174
00175
00176 if (!params->keep_ignorable_ws) {
00177
00178 wbxml_encoder_set_ignore_empty_text(wbxml_encoder, TRUE);
00179
00180
00181 wbxml_encoder_set_remove_text_blanks(wbxml_encoder, TRUE);
00182 }
00183
00184
00185 wbxml_encoder_set_use_strtbl(wbxml_encoder, params->use_strtbl);
00186 }
00187
00188
00189 ret = wbxml_encoder_encode_to_wbxml(wbxml_encoder, wbxml, wbxml_len);
00190
00191
00192 wbxml_tree_destroy(wbxml_tree);
00193 wbxml_encoder_destroy(wbxml_encoder);
00194
00195 return ret;
00196 }
00197
00198 #endif
00199 }