2017-08-16 25 views
2

我已經使用blender-python創建了一個XML文件(註釋),但問題是當我用它與Matlab代碼讀取它時,它會給我以下錯誤:Python - 攪拌器XML註釋文件(不適用於matlab代碼)

Error in VOCxml2struct>parse (line 10) 
if ~isempty(parent)&&xml(ind)~='<' 

這個函數

res=[]; 

if ~isempty(parent)&&xml(ind)~='<' 

i=findchar(xml,ind,'<'); 

res=trim(xml(ind:i-1)); 

ind=i; 

[tag,ind]=gettag(xml,i); 

if ~strcmp(tag,['/' parent]) 

    error('<%s> closed with <%s>',parent,tag); 
end 

這是一個有點混亂因爲從Pascal_Voc數據集的XML文件就很好地工作相同的代碼,當你看到這兩個XML文件他們看起來一樣,我創造了這個要求ed標籤手動和以下是我的blender-python代碼,希望有一個建議,我可以修復它。

謝謝大家的時間。

with open("000007.xml", "w", encoding="utf-8") as file: 
    file.write ("<annotation>\n") 
    file.write (" <folder>VOC2007</folder>\n") 
    file.write (" <filename>" + '000007.jpg' + "</filename>\n") 
    file.write (" <source>\n") 
    file.write ("  <database>The VOC2007 Database</database>\n") 
    file.write ("  <annotation>PASCAL VOC2007</annotation>\n") 
    file.write ("  <image>flickr</image>\n") 
    file.write ("  <flickrid>194179466</flickrid>\n") 
    file.write (" </source>\n") 
    file.write (" <owner>\n") 
    file.write ("  <flickrid>monsieurrompu</flickrid>\n") 
    file.write ("  <name>Thom Zemanek</name>\n") 
    file.write (" </owner>\n") 
    file.write (" </size>\n") 
    file.write ("  <width>500</width>\n") 
    file.write ("  <height>333</height>\n") 
    file.write ("  <depth>3</depth>\n") 
    file.write (" </size>\n") 
    file.write (" <segmented>0</segmented>\n") 
    file.write (" <object>\n") 
    file.write ("  <name>car</name>\n") 
    file.write ("  <pose>Unspecified</pose>\n") 
    file.write ("  <truncated>1</truncated>\n") 
    file.write ("  <difficult>0</difficult>\n") 
    file.write ("  <bndbox>") 
    file.write ("\n   <xmin>" + '141' + "</xmin>") 
    file.write ("\n   <ymin>" + '50' + "</ymin>") 
    file.write ("\n   <xmax>" + '500' + "</xmax>") 
    file.write ("\n   <ymax>" + '330' + "</ymax>") 
    file.write ("\n  </bndbox>\n") 
    file.write (" </object>\n") 
    file.write ("</annotation>\n") 

回答

2

Question ... when you see both XML files they look identical

不要相信你的眼睛使用一個diff PROGRAMM比較!
使用XML驗證像xmlvalidation.com

不知道它是否涉及到Matlab錯誤,但你的代碼和therfore產生的XML有以下錯誤:

# Missing Header 
<?xml version="1.0" encoding="UTF-8"?> 

# First has to be <size> not closing 
file.write (" </size>\n") 

想想使用xml Python模塊來創建XML