ねえ、たとえば(このリソース、ライブラリに基づい<Category />て)空のタグをどのように書くことができるのか疑問に思っています。今のところ、if条件を適用してから、それ以外の場合は無視して作成する必要があります。DocumentBuilderFactoryjavax.xml.parsers.*;if object.getCategory() != nullCategory Tag
//add the Category
if(excel.getCategory() != null){
Element Category = doc.createElement("category");
Category.appendChild(doc.createTextNode(excel.getCategory()));
Rows.appendChild(Category);
}
そしてスキーマ
<xs:complexType name="data">
<xs:all>
<xs:element name="Category" type="xs:string" minOccurs="1" />
<!-- other columns.. -->
</xs:all>
</xs:complexType>
また、nullのtextnodeを追加すると、エラーtransformer.transform(source, result);のヒープが返されることに気づきました。NullExceptionTextNodeが意図的に空のままになっていることを知るようにトランスフォーマーを構成する方法はありますか?<Category />次に、またはを作成します<Category></Category>。