MATLAB: XML file generation in matlab

printinting issuexml generation

I am trying to generate xml file dynamically. I am having an issue in printing the desired values.
RB_Array = 2147483647 0 0 0 0 0 0 0 0 C =DFFE0000
RB_Array = 2147483647 1 0 0 0 0 0 0 0 C =00000001
I have generated these two RB_Array with two associated using bitwise operation in matlab, and hexadecimal values stored in C.
if RB_Array(1,1)==0
rb_node.setTextContent('00000000');
else
rb_node.setTextContent(num2str(C));
end
I am having an output as <rb-assign block="0-31">00000001</rb-assign>. Instead of 00000001, I want to print DFFE0000. How can I do that?

Best Answer

First, whenever you copy/paste code multiple times and only change an index each time you need to realise that you need to replace that with a loop.
Secondly, I don't understand why you discriminate between RB_Array(i) being equal to 0 or not. In either case, dec2hex(RB_Array(i), 8) is what you want to output.
I've not tried to understand the bug in your code, the following will do what you want in a lot less lines:
%this part unchanged
docNode = com.mathworks.xml.XMLUtils.createDocument('scenario');
scenario = docNode.getDocumentElement;
cell_node = docNode.createElement('cells');
docNode.getDocumentElement.appendChild(cell_node);
slot_node = docNode.createElement('slot');
docNode.getDocumentElement.appendChild(slot_node);
slot_node.setAttribute('number','1');
cell_node.appendChild(slot_node);
ue_node = docNode.createElement('ue');
docNode.getDocumentElement.appendChild(ue_node);
ue_node.setAttribute('id','1');
slot_node.appendChild(ue_node);
dl_node = docNode.createElement('dl-dci');
docNode.getDocumentElement.appendChild(dl_node);
dl_node.setAttribute('format', '1-1');
ue_node.appendChild(dl_node);
%your rb2 input
rb2 = [17 18 19 20 21 22 23 24 25 26 27 28 28 30 31 32];
%calculation of RB_Array and creation of xml elements
RB_Array = uint32(accumarray(floor(rb2(:)/32)+1, mod(rb2(:), 32), [9, 1], @(v) sum(2.^unique(v))));
for row = 1:numel(RB_Array)
rb_node = docNode.createElement('rb-assign');
rb_node.setAttribute('block', sprintf('%d-%d', (row-1)*32, row*32-1));
docNode.getDocumentElement.appendChild(rb_node);
rb_node.setTextContent(dec2hex(RB_Array(row), 8));
dl_node.appendChild(rb_node);
end