0

Hi i know there have been asked many questions regarding changing content of XML in Matlab. But i tried different answers to this question(present on SO) but they did not work in my case. Here is my XML file structure

<annotation>
    <folder>n02749479</folder>
    <filename>n02749479_54</filename>
    <source>
        <database>ImageNet database</database>
    </source>
    <size>
        <width>500</width>
        <height>277</height>
        <depth>3</depth>
    </size>
    <segmented>0</segmented>
    <object>
        <name>n02749479</name>
        <pose>Unspecified</pose>
        <truncated>0</truncated>
        <difficult>0</difficult>
        <bndbox>
            <xmin>118</xmin>
            <ymin>69</ymin>
            <xmax>473</xmax>
            <ymax>193</ymax>
        </bndbox>
    </object>
</annotation>

I want to change the tags in <bndbox> tag. I want to change values ofxmin,ymin,xmax,ymax. I am able to get the values of these tags but i am unable to set values of these tags.
Question:
How to change content of tags mentioned above?

1

1 Answer 1

2

Matlab supporst java interface to xml. For example to change xmin in bndbox you could do:

xmlfile = fullfile('/tmp/test.xml');

DOMnode = xmlread(xmlfile);
bndbox_elem = DOMnode.getElementsByTagName('bndbox');
xmin_elem = bndbox_elem.item(0).getElementsByTagName('xmin');
xmin_elem.item(0).setTextContent('3233')

xmlwrite('/tmp/test2.xml',DOMnode);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.