CustomXmlPart incorrectly created as "customXML" rather than "customXml"
See original GitHub issueDescribe the bug When I create a new CustomXmlPart in an existing document it is created in β./customXML/item[id].xmlβ whereas word created the directory as β./customXmlβ rendering the document incomplete.
Steps to reproduce the behavior:
var xmlPart = """
<?xml version="1.0" encoding="UTF-8"?>
<test:testCustom xmlns:test="http://testag.ch/testCustom">
<test:CMX_LoremIpsum>
<test:Para1>Lorem Ipsum</test:Para1>
<test:Para2>Dolor sit amet</test:Para2>
<test:Para3>Consectetur adipiscing elit</test:Para3>
<test:Para4>den Rest mΓΌsste ich googlen</test:Para4>
</test:CMX_LoremIpsum>
<test:CMX_DummyTexts>
<test:Text1>Some text for Field 'Text1'</test:Text1>
<test:Text2>(γΰ² ηΰ² )γ彑β»ββ»</test:Text2>
</test:CMX_DummyTexts>
</test:testCustom>
""";
var part = Document.GetOrCreateCmiCustomXmlPart();
using var partStream = part.GetStream(FileMode.Create,
FileAccess.ReadWrite);
if (partStream.CanSeek)
partStream.Seek(0, SeekOrigin.Begin);
var doc = XDocument.Parse(xmlPart);
using var xmlWriter = XmlWriter.Create(partStream);
doc.Save(xmlWriter);
public static CustomXmlPart GetOrCreateCustomXmlPart(this WordprocessingDocument wordDoc,
string partId)
{
wordDoc.MainDocumentPart!.TryGetPartById(partId,
out var found);
var part = found as CustomXmlPart;
part ??= wordDoc.MainDocumentPart!.AddCustomXmlPart(CustomXmlPartType.CustomXml,
partId);
var customXmlProps = part.CustomXmlPropertiesPart ?? part.AddNewPart<CustomXmlPropertiesPart>();
customXmlProps.DataStoreItem ??= new DataStoreItem() { ItemId = Guid.NewGuid().ToString("B") };
return part;
}
Observed behavior
AddCustomXmlPart
appears to create a new directory customXML:
βββ [Content_Types].xml
βββ customXml
βΒ Β βββ item1.xml
βΒ Β βββ item2.xml
βΒ Β βββ item3.xml
βΒ Β βββ item4.xml
βΒ Β βββ itemProps1.xml
βΒ Β βββ itemProps2.xml
βΒ Β βββ itemProps3.xml
βΒ Β βββ itemProps4.xml
βΒ Β βββ _rels
βΒ Β βββ item1.xml.rels
βΒ Β βββ item2.xml.rels
βΒ Β βββ item3.xml.rels
βΒ Β βββ item4.xml.rels
βββ customXML
βΒ Β βββ item5.xml
βΒ Β βββ itemProps5.xml
βΒ Β βββ _rels
βΒ Β βββ item5.xml.rels
βββ docProps
βΒ Β βββ app.xml
βΒ Β βββ core.xml
βΒ Β βββ custom.xml
βββ _rels
βββ word
βββ document.xml
βββ fontTable.xml
βββ glossary
βΒ Β βββ document.xml
βΒ Β βββ fontTable.xml
βΒ Β βββ _rels
βΒ Β βΒ Β βββ document.xml.rels
βΒ Β βββ settings.xml
βΒ Β βββ styles.xml
βΒ Β βββ webSettings.xml
βββ _rels
βΒ Β βββ document.xml.rels
βββ settings.xml
βββ styles.xml
βββ theme
βΒ Β βββ theme1.xml
βββ webSettings.xml
12 directories, 32 files
Expected behavior The new files should be created within customXml
.
βββ [Content_Types].xml
βββ customXml
βΒ Β βββ item1.xml
βΒ Β βββ item2.xml
βΒ Β βββ item3.xml
βΒ Β βββ item4.xml
βΒ Β βββ item5.xml
βΒ Β βββ itemProps1.xml
βΒ Β βββ itemProps2.xml
βΒ Β βββ itemProps3.xml
βΒ Β βββ itemProps4.xml
βΒ Β βββ itemProps5.xml
βΒ Β βββ _rels
βΒ Β βββ item1.xml.rels
βΒ Β βββ item2.xml.rels
βΒ Β βββ item3.xml.rels
βΒ Β βββ item4.xml.rels
βΒ Β βββ item5.xml.rels
βββ docProps
βΒ Β βββ app.xml
βΒ Β βββ core.xml
βΒ Β βββ custom.xml
βββ _rels
βββ word
βββ document.xml
βββ fontTable.xml
βββ glossary
βΒ Β βββ document.xml
βΒ Β βββ fontTable.xml
βΒ Β βββ _rels
βΒ Β βΒ Β βββ document.xml.rels
βΒ Β βββ settings.xml
βΒ Β βββ styles.xml
βΒ Β βββ webSettings.xml
βββ _rels
βΒ Β βββ document.xml.rels
βββ settings.xml
βββ styles.xml
βββ theme
βΒ Β βββ theme1.xml
βββ webSettings.xml
10 directories, 32 files
Desktop (please complete the following information):
- OS: Windows Server 2022 / Fedora 37
- Office version -
- .NET Target: .NET Framework 4.8
- DocumentFormat.OpenXml Version: 2.19.0
Additional context Maybe it could be narrowed down to this: https://github.com/dotnet/Open-XML-SDK/blob/d46f92b2963f1c21415be08fb21532306e55db75/test/DocumentFormat.OpenXml.Packaging.Tests/data/PartConstraintData.json#L281
Issue Analytics
- State:
- Created 7 months ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
C# using OpenXML to replace CustomXml not working
The following is the code I'm using to create a new word document from an existing document. What does work is that it...
Read more >Custom XML part is not updated Β· Issue #1643
We can create a custom XML part via customXmlParts.addAsync and then update it. Current Behavior. We cannot updated a custom XML part onceΒ ......
Read more >Custom XML mapped by Aspose.Word removed after ...
I have a problem with mapping custom xml in my worddocument. Everything works fine at first, im creating a StructuredDocumentTag, adding my custom...
Read more >Cannot Bind Content Control to Custom XML - Run-time ...
I have a building block that contains Content Controls. When the Building Block is inserted I want to create a new Custom XML...
Read more >Using custom XML parts in Word add-ins
The name says it all. This method adds a custom XML part to a Word document. ... The method takes the passed Word...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It might prevent some confusion. Regarding
rendering incomplete
it appears that both docx files I used to test had broken bindings which is why they were displayed incomplete@mikeebowen if youβre going to make a change in the schema processing for #1305, perhaps you can throw this one in at the same time?