我们正在尝试使用 XDocument 创建具有以下内容的新 XML 文档,而无需查询现有文档:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<idPkg:Story xmlns:idPkg="http://ns.adobe.com/AdobeInDesign/idml/1.0/packaging" DOMVersion="8.0">
<Story Self="xyz">
<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/$ID/NormalParagraphStyle">
<CharacterStyleRange AppliedCharacterStyle="CharacterStyle/$ID/[No character style]">
<Content>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In ut ipsum et libero aliquam venenatis. Vestibulum molestie neque id leo sodales porta. Proin ullamcorper molestie mi a commodo. Aenean mattis tincidunt purus id sagittis. Nam bibendum metus est, id condimentum nisi tristique posuere. Sed interdum sollicitudin tincidunt. Fusce volutpat neque turpis, eget porttitor mauris ultricies quis. Morbi posuere ligula lobortis orci dictum lobortis. Lorem ipsum dolor sit amet, consectetur adipiscing elit. In ut ipsum et libero aliquam venenatis. Vestibulum molestie neque id leo sodales porta. Proin ullamcorper molestie mi a commodo. Aenean mattis tincidunt purus id sagittis. Nam bibendum metus est, id condimentum nisi tristique posuere. Sed interdum sollicitudin tincidunt. Fusce volutpat neque turpis, eget porttitor mauris ultricies quis. Morbi posuere ligula lobortis orci dictum lobortis. Lorem ipsum dolor sit amet, consectetur adipiscing elit. In ut ipsum et libero aliquam venenatis. Vestibulum molestie neque id leo sodales porta. Proin ullamcorper molestie mi a commodo. Aenean mattis tincidunt purus id sagittis. Nam bibendum metus est, id condimentum nisi tristique posuere. Sed interdum sollicitudin tincidunt. Fusce volutpat neque turpis, eget porttitor mauris ultricies quis. Morbi posuere ligula lobortis orci dictum lobortis.</Content>
</CharacterStyleRange>
</ParagraphStyleRange>
</Story>
</idPkg:Story>
我们尝试了以下代码:
Xdocument = new XDocument
{
Declaration = new XDeclaration("1.0", "UTF-8", "yes"),
};
XNamespace schemaLocation = XNamespace.Get("http://www.w3.org/2001/XMLSchema-datatypes");
XNamespace idPkg = "http://ns.adobe.com/AdobeInDesign/idml/1.0/packaging";
Xdocument.Add(new XElement(idPkg + "Story",
new XAttribute("xmlns" + "idPkg", "http://ns.adobe.com/AdobeInDesign/idml/1.0/packaging"),
new XAttribute("DOMVersion", "8.0")),
new XElement(idPkg + "Story"),
new XAttribute("Self", "xyz" + EnumHelper.GetDescription(section)));
当我们运行该方法时,它会出错new XElement(idPkg + "Story"),
,我们会收到以下错误消息:This operation would create an incorrectly structured document.
我们查看了以下问题: Creating XDocument with xsi:schemaLocation namespace