M
mearvk
I am unable to get Xerces to write out attributes from a struct which
I am able to print out and verify is correct. The structs are defined
below as is subsection of the output.
Here are the structs used:
And here is a sample of the output:
[OUTPUT]
<data_row SSE="137.527403" binary_representation="1010111011111001"
definition_number="44793">
<coefficient index="0" value="-0.000977"/>
<coefficient index="1" value="0.000000"/>
<coefficient index="2" value="0.000000"/>
<coefficient index="3" value="-66123751426.362999"/>
<coefficient index="4" value="0.000088"/>
<coefficient index="5" value="1095801473.097510"/>
<coefficient index="6" value="0.003840"/>
<coefficient index="7" value="-26494374893.985001"/>
<coefficient index="8" value="0.000000"/>
<coefficient index="9" value="0.097907"/>
<coefficient index="10" value="0.004219"/>
<coefficient index="11" value="66123751426.363098"/>
<coefficient index="12" value="0.000000"/>
<coefficient index="13" value="-1095801473.102500"/>
<coefficient index="14" value="0.000000"/>
<coefficient index="15" value="26494374894.009701"/>
</data_row>
<data_row SSE="137.533380" binary_representation=""
definition_number="">
<coefficient index="0" value="-0.001039"/>
<coefficient index="1" value="0.097757"/>
<coefficient index="2" value="758258573.171398"/>
<coefficient index="3" value="-35123845436.044098"/>
<coefficient index="4" value="0.000000"/>
<coefficient index="5" value="0.000000"/>
<coefficient index="6" value="-464164413.890403"/>
<coefficient index="7" value="0.024555"/>
<coefficient index="8" value="0.000000"/>
<coefficient index="9" value="0.000000"/>
<coefficient index="10" value="-758258573.167233"/>
<coefficient index="11" value="35123845436.044197"/>
<coefficient index="12" value="0.000016"/>
<coefficient index="13" value="-0.004898"/>
<coefficient index="14" value="464164413.894253"/>
<coefficient index="15" value="0.000000"/>
</data_row>
<data_row SSE="137.533796" binary_representation="0111111011P>V"
definition_number="32457">
<coefficient index="0" value="-0.001034"/>
<coefficient index="1" value="0.000000"/>
<coefficient index="2" value="0.000000"/>
<coefficient index="3" value="-35209041045.623802"/>
<coefficient index="4" value="0.000000"/>
<coefficient index="5" value="0.000000"/>
<coefficient index="6" value="-425970878.520971"/>
<coefficient index="7" value="0.024583"/>
<coefficient index="8" value="0.000000"/>
<coefficient index="9" value="0.097997"/>
<coefficient index="10" value="0.004175"/>
<coefficient index="11" value="35209041045.623802"/>
<coefficient index="12" value="-0.000016"/>
<coefficient index="13" value="-0.004899"/>
<coefficient index="14" value="425970878.524831"/>
<coefficient index="15" value="0.000000"/>
</data_row>
[/OUTPUT]
Some of the output is correct, some is there but erroneous, some is
missing altogether. Each data_row element should have a
definition_number with some value between 0 and (2^16)-1. The binary
representation is merely the binary representation of the decimal
value. I have spent many hours trying to figure out what the error
is. Again, I am able to print the struct (printDCRD) at the beginning
of the method and verify that the data contained therein is correct
and present.
So, if anyone can lend me some attention cycles, I'd greatly
appreciate it.
Thanks ahead.
I am able to print out and verify is correct. The structs are defined
below as is subsection of the output.
Code:
int DDAS_XML_Handler::writeResultDocument( int job_id, int
num_results, DDAS_CLIENT_RESULT_DATA* results )
{
try
{
DOMElement* data_row;
DOMElement* coeff;
DOMElement* root;
DOMAttr* sse_attr;
DOMAttr* bin_rep_attr;
DOMAttr* def_num_attr;
DOMAttr* index_attr;
DOMAttr* value_attr;
DOMAttr* job_id_attr;
XMLCh* data_row_ch =
XMLString::transcode("data_row");
XMLCh* sse_ch = XMLString::transcode("SSE");
XMLCh* bin_rep_ch =
XMLString::transcode("binary_representation");
XMLCh* def_num_ch =
XMLString::transcode("definition_number");
XMLCh* coeff_ch =
XMLString::transcode("coefficient");
XMLCh* index_ch =
XMLString::transcode("index");
XMLCh* value_ch =
XMLString::transcode("value");
XMLCh* job_id_ch =
XMLString::transcode("jobID");
//printDCRD(results);
//create a DOM
DOMImplementation* impl =
DOMImplementationRegistry::getDOMImplementation(XMLString::transcode("Range"));
DOMDocument* doc = impl->createDocument(0,
XMLString::transcode("job_results"), 0);
//document root
root = doc->getDocumentElement();
//root's job ID attribute
job_id_attr = doc->createAttribute(job_id_ch);
//add the job_id attribute to root tag
char* job_buffer = new char[128];
sprintf( job_buffer, "%i", job_id );
XMLString::trim(job_buffer);
job_id_attr-[QUOTE]
setValue(XMLString::transcode(job_buffer));[/QUOTE]
root->setAttributeNode(job_id_attr);
delete[] job_buffer;
//for each data row
for( int i=0; i<num_results; i++ )
{
data_row = doc-[QUOTE]
createElement(data_row_ch);[/QUOTE]
sse_attr = doc-[QUOTE]
createAttribute(sse_ch);[/QUOTE]
bin_rep_attr = doc-[QUOTE]
createAttribute(bin_rep_ch);[/QUOTE]
def_num_attr = doc-[QUOTE]
createAttribute(def_num_ch);[/QUOTE]
//set SSE value
char* sse_buffer = new char[128];
sprintf( sse_buffer, "%f", results->SSEs[i] );
//set binary representation value
char* br_buffer = new char[128];
sprintf( br_buffer, "%s", results-[QUOTE]
bin_reps[i] );[/QUOTE]
//set defintion number value
char* dn_buffer = new char[128];
sprintf( dn_buffer, "%s", results-[QUOTE]
def_nums[i] );[/QUOTE]
//trim strings
XMLString::trim(sse_buffer);
XMLString::trim(br_buffer);
XMLString::trim(dn_buffer);
//convert to XMLCh*
XMLCh* sse_val =
XMLString::transcode(sse_buffer);
XMLCh* bin_rep_val =
XMLString::transcode(br_buffer);
XMLCh* def_num_val =
XMLString::transcode(dn_buffer);
//set attr values
sse_attr ->setValue(sse_val);
bin_rep_attr->setValue(bin_rep_val);
def_num_attr->setValue(def_num_val);
//append attribute nodes to data row
data_row->setAttributeNode(sse_attr);
data_row->setAttributeNode(bin_rep_attr);
data_row->setAttributeNode(def_num_attr);
//append data row to root
root->appendChild(data_row);
//free memory
delete[] sse_buffer;
delete[] br_buffer;
delete[] dn_buffer;
XMLString::release(&sse_val);
XMLString::release(&bin_rep_val);
XMLString::release(&def_num_val);
//handle coefficients on a per data row basis
[QUOTE=" for( unsigned int j=0; j"]
size; j++)[/QUOTE]
{
//create coefficient element
coeff = doc->createElement(coeff_ch);
//create attribute nodes
index_attr = doc-[QUOTE]
createAttribute(index_ch);[/QUOTE]
value_attr = doc-[QUOTE]
createAttribute(value_ch);[/QUOTE]
//request some space for conversion
char* index_buffer = new char[128];
char* value_buffer = new char[128];
//convert from numeric to char*
sprintf( index_buffer, "%i", results-[QUOTE]
coefficients[i].index[j] );[/QUOTE]
sprintf( value_buffer, "%f", results-[QUOTE]
coefficients[i].values[j] );[/QUOTE]
//remove whitespace
XMLString::trim(index_buffer);
XMLString::trim(value_buffer);
//create values as XMLCh*
XMLCh* index_val =
XMLString::transcode(index_buffer);
XMLCh* value_val =
XMLString::transcode(value_buffer);
//set values
index_attr->setValue(index_val);
value_attr->setValue(value_val);
coeff->setAttributeNode(index_attr);
coeff->setAttributeNode(value_attr);
//append coefficient to data row
data_row->appendChild(coeff);
//free memory
delete[] index_buffer;
delete[] value_buffer;
}//end inner for loop
}//end outer for loop
//DOM serializer
DOMWriter* writer = ((DOMImplementationLS*)impl)-[QUOTE]
createDOMWriter();[/QUOTE]
//request some space for URL
char* buffer = new char[512];
//create URL based on job ID
sprintf( buffer, "%sjob_%u_results.xml",
DDAS_RESULT_URL, job_id );
//remove whitespace
XMLString::trim(buffer);
//create URL as XMLCh*
XMLCh* url_ch = XMLString::transcode(buffer);
//set output type
LocalFileFormatTarget local_file( url_ch );
//set some formatting options
if (writer-[QUOTE]
canSetFeature(XMLUni::fgDOMWRTDiscardDefaultContent, true))[/QUOTE]
writer-[QUOTE]
setFeature(XMLUni::fgDOMWRTDiscardDefaultContent, true); if (writer-
canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true))[/QUOTE]
writer-[QUOTE]
setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);[/QUOTE]
//actually write the root node to file
writer->writeNode(&local_file, *root);
//free resources
writer ->release();
doc ->release();
delete[] buffer;
return 1;
}
catch( XMLException& e)
{
char* message =
XMLString::transcode( e.getMessage() );
cerr << "The following error occurred during
the DOM creation: " << message << endl;
XMLString::release( &message );
}
}
Here are the structs used:
Code:
struct REGRESSION_COEFFICIENTS
{
//which column are talking about
int* index;
//the value of the linear coefficient
double* values;
//the size of the struct
unsigned int size;
};
///A struct used to hold the client result data
struct DDAS_CLIENT_RESULT_DATA
{
/// The binary representation of the definition number -
serves to disambiguate endianess
char** bin_reps;
/// The decimal representation of the combination of
independent variables used in this regression (1011 base 2 == 11 base
10)
char** def_nums;
/// The sum of squared error for the linear regression
double* SSEs;
/// How many results are contained in the struct
unsigned int size;
//regression coefficients
REGRESSION_COEFFICIENTS* coefficients;
};
And here is a sample of the output:
[OUTPUT]
<data_row SSE="137.527403" binary_representation="1010111011111001"
definition_number="44793">
<coefficient index="0" value="-0.000977"/>
<coefficient index="1" value="0.000000"/>
<coefficient index="2" value="0.000000"/>
<coefficient index="3" value="-66123751426.362999"/>
<coefficient index="4" value="0.000088"/>
<coefficient index="5" value="1095801473.097510"/>
<coefficient index="6" value="0.003840"/>
<coefficient index="7" value="-26494374893.985001"/>
<coefficient index="8" value="0.000000"/>
<coefficient index="9" value="0.097907"/>
<coefficient index="10" value="0.004219"/>
<coefficient index="11" value="66123751426.363098"/>
<coefficient index="12" value="0.000000"/>
<coefficient index="13" value="-1095801473.102500"/>
<coefficient index="14" value="0.000000"/>
<coefficient index="15" value="26494374894.009701"/>
</data_row>
<data_row SSE="137.533380" binary_representation=""
definition_number="">
<coefficient index="0" value="-0.001039"/>
<coefficient index="1" value="0.097757"/>
<coefficient index="2" value="758258573.171398"/>
<coefficient index="3" value="-35123845436.044098"/>
<coefficient index="4" value="0.000000"/>
<coefficient index="5" value="0.000000"/>
<coefficient index="6" value="-464164413.890403"/>
<coefficient index="7" value="0.024555"/>
<coefficient index="8" value="0.000000"/>
<coefficient index="9" value="0.000000"/>
<coefficient index="10" value="-758258573.167233"/>
<coefficient index="11" value="35123845436.044197"/>
<coefficient index="12" value="0.000016"/>
<coefficient index="13" value="-0.004898"/>
<coefficient index="14" value="464164413.894253"/>
<coefficient index="15" value="0.000000"/>
</data_row>
<data_row SSE="137.533796" binary_representation="0111111011P>V"
definition_number="32457">
<coefficient index="0" value="-0.001034"/>
<coefficient index="1" value="0.000000"/>
<coefficient index="2" value="0.000000"/>
<coefficient index="3" value="-35209041045.623802"/>
<coefficient index="4" value="0.000000"/>
<coefficient index="5" value="0.000000"/>
<coefficient index="6" value="-425970878.520971"/>
<coefficient index="7" value="0.024583"/>
<coefficient index="8" value="0.000000"/>
<coefficient index="9" value="0.097997"/>
<coefficient index="10" value="0.004175"/>
<coefficient index="11" value="35209041045.623802"/>
<coefficient index="12" value="-0.000016"/>
<coefficient index="13" value="-0.004899"/>
<coefficient index="14" value="425970878.524831"/>
<coefficient index="15" value="0.000000"/>
</data_row>
[/OUTPUT]
Some of the output is correct, some is there but erroneous, some is
missing altogether. Each data_row element should have a
definition_number with some value between 0 and (2^16)-1. The binary
representation is merely the binary representation of the decimal
value. I have spent many hours trying to figure out what the error
is. Again, I am able to print the struct (printDCRD) at the beginning
of the method and verify that the data contained therein is correct
and present.
So, if anyone can lend me some attention cycles, I'd greatly
appreciate it.
Thanks ahead.