XML file generation in matlab

10 views (last 30 days)
Permvir Singh
Permvir Singh on 5 Mar 2020
Commented: Permvir Singh on 5 Mar 2020
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?
  7 Comments
Guillaume
Guillaume on 5 Mar 2020
Edited: Guillaume on 5 Mar 2020
"The RB_Array is the array of 9 elements [...] These blocks are fixed, and can not be changed. [...]"
Yes, I understood that and I understand that it is preset. What I was saying is that you probably have an error in your construction of the RB_Array because you've declared it as int32 instead of uint32. I've given you an example that easily demonstrates the problem using your code. If you try your code with input
rb2 = [31, 63, 95, 127];
You'll get as output:
>> dec2hex(RB_Array)
ans =
9×8 char array
'7FFFFFFF'
'7FFFFFFF'
'7FFFFFFF'
'7FFFFFFF'
'00000000'
'00000000'
'00000000'
'00000000'
'00000000'
whereas it should be
>> dec2hex(accumarray(floor(rb2(:)/32)+1, mod(rb2(:), 32), [9, 1], @(v) sum(2.^unique(v))))
ans =
9×8 char array
'80000000'
'80000000'
'80000000'
'80000000'
'00000000'
'00000000'
'00000000'
'00000000'
'00000000'
edit: I see you've fixed the bug in your new comment. Still as you can see above, the calculation can be done in just one line.
Permvir Singh
Permvir Singh on 5 Mar 2020
Thank you very much for the support. Lots of appreciation.

Sign in to comment.

Accepted Answer

Guillaume
Guillaume on 5 Mar 2020
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

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!