Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to ignore missing embedded references in malformed .docx documents? #1916

Closed
XomkaEzWin opened this issue Apr 7, 2025 · 4 comments
Assignees

Comments

@XomkaEzWin
Copy link

Hi, I'm following up on my previous issue: [#1912] where I reported a problem with a .docx file that includes broken references in document.xml.rels like:

I was wondering:

Is there any built-in way to ignore such missing relationships or gracefully handle them?

Could someone from the team take a look at the previous issue and advise on the best practice for handling these cases?

When I manually remove the invalid entries, everything works fine, but I'm hoping for a cleaner or automated approach, since I might have to process many such files.

Thanks in advance!

@mkaszewiak mkaszewiak self-assigned this Apr 7, 2025
@mkaszewiak
Copy link
Collaborator

mkaszewiak commented Apr 7, 2025

Hi @XomkaEzWin my apologises for not replying on closed issue but I didn't get notified about your comment probably because the issue was closed.
I don't think there is a way to ignore the relationship but you can remove the relationship. Please have a look here https://www.ericwhite.com/blog/openxmlpackage_deleterelationship/ Its almost end of my shift here but tomorrow GMT I can try to prepare some working sample if you will not be able to figure it out. Thanks

@XomkaEzWin
Copy link
Author

Hi @mkaszewiak thanks a lot for your reply and the helpful link!

We're looking into the option of removing relationships, but simply clearing all of them wouldn't work for our case — we need to preserve valid ones.

Would it be possible to identify only the problematic relationships somehow, so that we could remove just those?
Any pointers or suggestions would be greatly appreciated!

@mkaszewiak
Copy link
Collaborator

mkaszewiak commented Apr 8, 2025

Hi @XomkaEzWin
We have reviewed your request internally and, unfortunately, there is currently no way to achieve this through the OpenXML SDK. The available methods only allow for examining some of the relationships that have existing parts. In other words, whenever you try to get the part by Id (of an invalid relationship), it will result in the same System.IO.Packaging exception.

You might consider using other libraries to unzip the package, manually remove the unwanted relationships from the document.rels.xml file, and then re-zip the package. However, this approach involves a significant amount of extra code.

We can discuss your query internally as a potential feature request, but we cannot commit to anything at this time. This may not be achievable or could require extensive redesign, and it may not be delivered anytime soon.

Best regards, Mariusz

@XomkaEzWin
Copy link
Author

Hi @mkaszewiak .
Thanks a lot for your input and the detailed responses — much appreciated.
It seems that this issue won’t be resolved on either side - so can be closed, but your feedback was still very helpful in clarifying the situation.

Thank you again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants