Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何更改XML文件中的数据?Matlab_Xml_Matlab - Fatal编程技术网

如何更改XML文件中的数据?Matlab

如何更改XML文件中的数据?Matlab,xml,matlab,Xml,Matlab,大家好,我知道有人问了很多关于在Matlab中更改XML内容的问题。但我尝试了这个问题的不同答案(如此呈现),但它们在我的案例中不起作用。这是我的XML文件结构 <annotation> <folder>n02749479</folder> <filename>n02749479_54</filename> <source> <database>ImageNet datab

大家好,我知道有人问了很多关于在Matlab中更改XML内容的问题。但我尝试了这个问题的不同答案(如此呈现),但它们在我的案例中不起作用。这是我的XML文件结构

<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>

n02749479
n02749479_54
ImageNet数据库
500
277
3.
0
n02749479
未指明
0
0
118
69
473
193
我想更改
标记中的标记。我想更改
xmin、ymin、xmax、ymax的值
。我可以获取这些标记的值,但无法设置这些标记的值。
问题:

如何更改上述标记的内容?

Matlab支持将java接口转换为xml。例如,要在
bndbox
中更改
xmin
,您可以执行以下操作:

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);

Matlab支持xml的java接口。例如,要在
bndbox
中更改
xmin
,您可以执行以下操作:

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);