Why new slides are not added to presentaion.xml sldIdList?

Home Forums PresentationML Why new slides are not added to presentaion.xml sldIdList?

This topic contains 4 replies, has 3 voices, and was last updated by  sliu 8 years, 9 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #3255

    sliu
    Participant

    Hi Eric,

    I added some new slides and modified the xml of PresentationPart.GetXDocument() to add new slide ids. At the end, I called PresentationPart.PutXDocument() to save it to presentation.xml. But when the presentation was created, I saw presentation.xml has only one slide. But presentation.xml.rels has my 3 slide references there, and under slides folder there are 3 slide#.xml files. Do you know why presentation.xml wasn’t updated?

    I ran PresentationBuilder01, it seems like PresentationPart.PutXDocument() works fine there. Why not in my project?

    Thanks in advance!!!

    #3257

    Eric White
    Keymaster

    Hi,

    You are taking the right approach – after adding the slides, you must GetXDocument on the presentation part, add the slide references, and call PutXDocument.

    I think you have to look for a bug somewhere – dump out the XDocument immediately before you call PutXDocument, make sure that you are putting the content that you want to put.

    Another thought – make a super small example that simply gets, changes, and puts the presentation part, make sure that you can do this operation in isolation. You need not create a valid presentation – just look at the results in the Open XML Package Editor Power Tool.

    Typically, when I see the case where parts are not properly updated, it is because of not properly using the ‘using’ statement to deal with disposable objects, but because you are using GetXDocument and PutXDocument, you are bypassing that whole issue.

    There must be a bug somewhere, I think.

    #3276

    sliu
    Participant

    Hi Eric,

    I found what causes the problem, but I don’t know why.

    int Cx = doc.PresentationPart.Presentation.SlideSize.Cx;
    int Cy = doc.PresentationPart.Presentation.SlideSize.Cy;

    XDocument pDoc = doc.PresentationPart.GetXDocument();
    pDoc.Root.Descendants(P.sldId).First().Attribute(NoNamespace.id).Value = “260”;

    doc.PresentationPart.PutXDocument();

    If you run this code, presentation.xml is not modified and the first slide id is not changed from 256 to 260. If you comment out the first 2 lines, the change is saved. I don’t know why getting slide size prevents updating presentation.xml.

    #3278

    Eric White
    Keymaster

    Ok, I now understand exactly what is going on. I’ll explain:

    There are two object models that you can use to modify the markup in Open XML:
    – The strongly-typed object model of the Open-Xml-Sdk. This includes the classes you are using when getting the slide size. This also includes, for instance, the Paragraph, Run, and Text classes that we see in WordprocessingML.
    – LINQ to XML, which is the best programming model that I know of for modifying and transforming XML.

    One issue with the strongly-typed OM is that its API does not work for functional construction and certain types of functional transforms. At the time that they were designing that API, I tried my best to get them to fix this, but was not able to convince them (primarily because the designers of the SDK were not schooled in functional programming). I also had plans to fix this as part of my job as maintainer of the open source Open-Xml-Sdk, but it looks like this plan is not going to happen.

    There is magic caching that goes on in the strongly-typed OM of the Open-Xml-Sdk that conflicts with LINQ to XML. I disagree with the decision to have magic caching, but this decision is not reversible.

    Because of the deficiencies in the strongly-typed OM of the Open-Xml-Sdk, I wrote the Open-Xml-PowerTools using LINQ to XML.

    Anyway, key point is that when you open an Open XML document using the Open-Xml-Sdk, you should not use both the strongly-typed OM and LINQ to XML on the same open document. And because Open-Xml-PowerTools uses LINQ to XML, then should not mix use of the Open-Xml-PowerTools and the strongly-typed OM on the same open document.

    If I need to use both APIs, I close and re-open the document, so that I never use both APIs on the same open document.

    I know this is an abysmal state of affairs. Truly I wanted to fix this, but I have never been given leave to do so by the folks in charge of the SDK. Of course, now that the Open-Xml-Sdk is open source, I could certainly fork it, and fix this. However, I also have to focus on providing a livelihood for my family, so can’t do this pro bono. I have contemplated fixing this (along with fixing many other things, and enhancing the SDK in interesting ways) and releasing an Open-Xml-Sdk-Pro, which would be a commercial product, but this hasn’t been attractive enough to impel me to do so.

    This is the explanation for what you are seeing.

    #3301

    sliu
    Participant

    Ok, I didn’t know I cannot use both models on one open document. I can handle it to just use one model. I prefer Linq to Xml model, it is much easier to deal with modifying the content of the presentation.

    Thanks for the explanation!!!

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.