私は次のように xml コンテンツを作成しようとしています。ここでは libxml2 と c++ を使用しています。libxml2 ライブラリ API の上にラッパーを書き、それを使用しようとしています。 .Google で検索して同様の問題を見つけましたが、できませんでした。これについて私を助けてください。前もって感謝します。
<?xml version="1.0" encoding="UTF-8"?>
<Environment>
<PlatformSection>
<Kind>NOVA</Kind>
<Version>2013.1</Version>
<Vendor>Openstack</Vendor>
<Locale>en</Locale>
</PlatformSection>
<PropertySection>
<Property oe:key="com.cisco.csr1000v.mgmt-interface" oe:value="GigabitEthernet1"/>
</PropertySection></Environment>
私のコードは以下のようになります。ここでは、c++ libxml2 xmltextwriter を使用しています。
XmlWriter wtr;
wtr.StartWriting("test.xml");
wtr.StartDocument("1.0","UTF-8");
wtr.StartElement("Environment");
wtr.StartIndenting();
wtr.StartElement("PlatformSection");
wtr.WriteElement("Kind","NOVA");
wtr.WriteElement("Version","2013.1");
wtr.WriteElement("Vendor","Openstack");
wtr.WriteElement("Locale","en");
wtr.EndElement();
wtr.StartElement("PropertySection");
wtr.StartElement("Property");
wtr.AddAttribute("oe:key","com.cisco.csr1000v.mgmt-interface");
wtr.AddAttribute("oe:value","GigabitEthernet1");
wtr.EndElement();
wtr.EndElement();
wtr.freeTextWriter();
どこ
bool AddAttribute(const std::string& attribute_name,
const std::string& attribute_value) {
return xmlTextWriterWriteAttribute(writer_,
BAD_CAST attribute_name.c_str(),
BAD_CAST attribute_value.c_str()) >= 0;
}
次のエラーを与える私のo / p、
namespace error : Namespace prefix oe for key on Property is not defined
<Property oe:key="com.cisco.csr1000v.mgmt-interface" oe:value="GigabitEthernet1"
^
namespace error : Namespace prefix oe for value on Property is not defined
<Property oe:key="com.cisco.csr1000v.mgmt-interface" oe:value="GigabitEthernet1"
^
error : xmlTextWriterWriteDocCallback : XML error 201 !
I/O error : flush error
Entity: line 11: parser error : Extra content at the end of the document
</PropertySection>
^
error : xmlTextWriterWriteDocCallback : XML error 5 !
xml is
<?xml version="1.0" encoding="ISO-8859-1"?>
<Environment>
<PlatformSection>
<Kind>NOVA</Kind>
<Version>2013.1</Version>
<Vendor>Openstack</Vendor>
<Locale>en</Locale>
</PlatformSection>
<PropertySection>
<Property key="com.cisco.csr1000v.mgmt-interface" value="GigabitEthernet1"/>
</PropertySection></Environment>