부스트의 속성 트리를 사용하여 XML을 읽고 쓰고 있습니다. 스프레드 시트 응용 프로그램을 사용하여 스프레드 시트의 내용을 XML로 저장하려고했습니다.동일한 키를 가진 노드를 속성 트리에 추가
int main(int argc, char const *argv[])
{
boost::property_tree::ptree pt;
pt.put("spreadsheet.cell.name", "a2");
pt.put("spreadsheet.cell.contents", "adsf");
write_xml("output.xml", pt);
boost::property_tree::ptree ptr;
read_xml("output.xml", ptr);
ptr.put("spreadsheet.cell.name", "d6");
ptr.put("spreadsheet.cell.contents", "345");
ptr.put("spreadsheet.cell.name", "d2");
ptr.put("spreadsheet.cell.contents", "=d6");
write_xml("output2.xml", ptr);
return 0;
}
나는 put
방법은 대체를 참조하십시오이 question을 바탕으로 : 내가 쓴 간단한 테스트 프로그램의
<?xml version="1.0" encoding="UTF-8"?>
<spreadsheet>
<cell>
<name>A2</name>
<contents>adsf</contents>
</cell>
<cell>
<name>D6</name>
<contents>345</contents>
</cell>
<cell>
<name>D2</name>
<contents>=d6</contents>
</cell>
</spreadsheet>
이 그래서는 XML에 대해 다음 형식을 사용하도록 요구하고 학교 과제입니다 새로운 노드를 추가하는 대신 해당 노드의 노드. 정확히 내가보고하고있는 기능입니다 :
Output.xml
<?xml version="1.0" encoding="utf-8"?>
<spreadsheet>
<cell>
<name>a2</name>
<contents>adsf</contents>
</cell>
</spreadsheet>
Output2.xml
<?xml version="1.0" encoding="utf-8"?>
<spreadsheet>
<cell>
<name>d2</name>
<contents>=d6</contents>
</cell>
</spreadsheet>
나는이 add_child
방법을 참조 documentation에서 찾고있는 것이다 Add the node at the given path. Create any missing parents. If there already is a node at the path, add another one with the same key.
난 그 방법을 사용하는 방법을 알아낼 수 없다, 누군가가 그것을 사용하는 방법을 설명 할 수 있을까?
원하는 파일 형식을 얻으려면이 문제를 해결하는 더 좋은 방법이 있습니까?
방금 자식 이름으로 셀 이름을 사용할 수 없습니다? 즉, "spreadsheet.cell.d6" ' –
@ k-ballo는 XML 요구 사항을 충족하지 못하기 때문입니다. – Deekor