LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

CVIXMLSaveDocument format flag broken?

here's my source XML and it's just not giving back the expect behavior when using CVISaveDocument with the format flag or without.
 
<?xml version="1.0" encoding="UTF-8"?>
<!-- This is the B1586 board for the 999C relay. -->
<Board>
 B1586
  <TestData>
    <Test>PP14 to PP27-1
   <hard_ul>20</hard_ul>
   <hard_ll>10</hard_ll>
   <soft_ul>18</soft_ul>
   <soft_ll>12</soft_ll>
   <swmarker>1E3</swmarker>
   <dc_offset>1</dc_offset>
   <swrange>1E3-4E3</swrange>
   <numpoints>5</numpoints>
   <autoretry>0</autoretry>
   <delay>0</delay>
   <connection>IO1_POS</connection>
   <connection>IO2_NEG</connection>
   <connection>SHORT1</connection>
   <knownfailures>D14 Reversed</knownfailures>
   <knownfailures>C24 Shorted</knownfailures>
   <knownfailures>H1-Q8</knownfailures>     
    </Test>
    <Test>PP14 to PP27-2
   <hard_ul>20</hard_ul> 
   <hard_ll>10</hard_ll>
   <soft_ul>18</soft_ul>
   <soft_ll>12</soft_ll>
   <connection>IO2_POS</connection>
   <connection>IO1_NEG</connection>
   <connection>SHORT1</connection>
   <knownfailures>H1-Q8</knownfailures>       
    </Test>  
  </TestData>
</Board>
 
loading and resaving this file, it keeps coming back as follows regardless of the format flag, sorry for the crassness but... WTF?!
 
<?xml version="1.0" encoding="UTF-8"?>
<!-- This is the B1586 board for the 999C relay. -->
<Board>
 B1586
  <TestData>
  <Test>PP14 to PP27-1
   <hard_ul>20</hard_ul><hard_ll>10</hard_ll><soft_ul>18</soft_ul><soft_ll>12</soft_ll><swmarker>1E3</swmarker><dc_offset>1</dc_offset><swrange>1E3-4E3</swrange><numpoints>5</numpoints><autoretry>0</autoretry><delay>0</delay><connection>IO1_POS</connection><connection>IO2_NEG</connection><connection>SHORT1</connection><knownfailures>D14 Reversed</knownfailures><knownfailures>C24 Shorted</knownfailures><knownfailures>H1-Q8</knownfailures></Test>
  <Test>PP14 to PP27-2
   <hard_ul>20</hard_ul><hard_ll>10</hard_ll><soft_ul>18</soft_ul><soft_ll>12</soft_ll><connection>IO2_POS</connection><connection>IO1_NEG</connection><connection>SHORT1</connection><knownfailures>H1-Q8</knownfailures></Test>
 </TestData>
</Board>
0 Kudos
Message 1 of 6
(3,911 Views)

The 'format' flag only works with very simple XML. Without the format flag, the output is completely controlled by the

Microsoft XML DOM parser on your system. On my system, using CVI 8.5, with your XML as input, just calling CVIXMLLoad... and

CVIXMLSave... without the formatting option results in very nice output (almost formatted). With the formatting option, I get

some extra line-breaks. But I do not get the long lines you see.

You may also want to try the XML indenting code in:

http://forums.ni.com/ni/board/message?board.id=180&message.id=33619

0 Kudos
Message 2 of 6
(3,886 Views)
Thank you for the response.  I think the reason that I am seeing this behavior and you are not is because I am deleteing and rebuilding all child nodes of Test before saving.
0 Kudos
Message 3 of 6
(3,879 Views)
So I muxed about with the cvixml.c files etc and completely removed the format flag stuff (in effect) so this behavior is occurring outside the format flag's code and is happening when CVI is writing off the file, also of note, I am essentially "editing" the file, deleteing some nodes and rebuilding them into the same xml file on the HDD, the deleted nodes end up all on the same line, however the unedited nodes maintain thier formatting.
0 Kudos
Message 4 of 6
(3,850 Views)
If the format flag is FALSE, then the output is completely determined by the Microsoft XML DOM (MSXML). I think the DOM may be leaving the line breaks in the existing elements as they were, and this is resulting in only some nodes having line breaks. You should try the indenting code in the previous link I posted - that might take care of this. Another alternative might be to read *all* nodes and remove any line breaks in the value when you are editing the XML - I think this is cumbersome but should also work.
0 Kudos
Message 5 of 6
(3,834 Views)
Thank you Mohan, but I'm already getting rid of newline chars, maybe I'll have to try the indent code, although mine already properly indents  ^_^.
 
  CVIXMLGetElementValueLength (currChildElem, &len);
  elemValue = malloc (len + 1);
  CVIXMLGetElementValue (currChildElem, elemValue);
  RemoveSurroundingWhiteSpace (elemValue);  //no more new line.
 
thank you for the feedback tho, I will certainly focus my search when I get time to get back to this issue.
0 Kudos
Message 6 of 6
(3,801 Views)