• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1429
  • Last Modified:

System.Xml.XmlException: The ':' character, hexadecimal value 0x3A, cannot be included in a name.

Hi All,

I am really stuck at the moment.. I have been looking this error up on the iternet for ages but cannot see how it fits with what I am doing....

I copied the following code which is supposed to merge PowerPoint files using OpenXML but when running the code I get the following error:

http://openxmldeveloper.org/blog/b/openxmldeveloper/archive/2011/01/28/110420.aspx

Error
System.Xml.XmlException: The ':' character, hexadecimal value 0x3A, cannot be included in a name.

at line..

destSp = destinationPresentationPart.AddPart<SlidePart>(sp, relId);

... which is within the 3rd code snippet in point 7 of the article.

Can anyone suggest when I could change this code to make it work?,,, It appears to be an XML error but I don't have control of the XML a its a MS PowerPoint 2010 file its referring to I believe.

Any help would be much much appreciated... I have spent 2 weeks on Open XML and have found it difficult to pick it up! :-(

I have attached the code too.

Many thanks,

Rit
private void MergePresentationSlides(string sourcePresentation, string destinationPresentation)
        {
            int id = 0;
            
            //Open destination presentation
            using (PresentationDocument myDestDeck = PresentationDocument.Open(destinationPresentation, true))
            {
                PresentationPart destinationPresentationPart = myDestDeck.PresentationPart;

                if (destinationPresentationPart.Presentation.SlideIdList == null)
                {
                    destinationPresentationPart.Presentation.SlideIdList = new SlideIdList();
                }

                using (PresentationDocument mySourceDeck = PresentationDocument.Open(sourcePresentation, false))
                {
                    PresentationPart sourcePresentationPart = mySourceDeck.PresentationPart;

                    //Get unique IDs for the slides master and slide lists for us later.
                    uniqueID = GetMaxSlideMasterID(destinationPresentationPart.Presentation.SlideMasterIdList);
                    uint maxSlideID = GetMaxSlideId(destinationPresentationPart.Presentation.SlideIdList);


                    //Copy each slide in the source presentaiton and order of the destination presentation
                    foreach (SlideId slideId in sourcePresentationPart.Presentation.SlideIdList)
                    {
                        SlidePart sp;
                        SlidePart destSp;
                        SlideMasterPart destMasterPart;
                        string relId;
                        SlideMasterId newsSlideMasterId;
                        SlideId newsSlideId;
                        
                        // Create a unique relationship Id.
                        id++;
                        sp = (SlidePart)sourcePresentationPart.GetPartById(slideId.RelationshipId);
                        relId = sourcePresentation.Remove(sourcePresentation.IndexOf('.')) + id;
                        //Add the slide part to the destination presentation.
                        destSp = destinationPresentationPart.AddPart<SlidePart>(sp, relId);
                        //The master part was added so make sure the relationship is in place
                        destMasterPart = destSp.SlideLayoutPart.SlideMasterPart;
                        destinationPresentationPart.AddPart(destMasterPart);
                        //Add slide master to slide master list
                        uniqueID++;
                        newsSlideMasterId = new SlideMasterId();
                        newsSlideMasterId.RelationshipId = destinationPresentationPart.GetIdOfPart(destMasterPart);
                        newsSlideMasterId.Id = uniqueID;
                        //Add slide to slide list
                        maxSlideID++;
                        newsSlideId = new SlideId();
                        newsSlideId.RelationshipId = relId;
                        newsSlideId.Id = maxSlideID;
                        destinationPresentationPart.Presentation.SlideMasterIdList.Append(newsSlideMasterId);
                        destinationPresentationPart.Presentation.SlideIdList.Append(newsSlideId);

                    }
                    //Make sure all slide IDs are unique
                    FixSlideLayoutIds(destinationPresentationPart);
                }
                //Save the changes to the destination deck
                destinationPresentationPart.Presentation.Save();
            }

        }

Open in new window

0
rito1
Asked:
rito1
1 Solution
 
Jesse HouwingScrum Trainer | Microsoft MVP | ALM Ranger | ConsultantCommented:
Either ID or RelId contains a ':'. A : is used in XML to separate the namespace from the name, and cannot be included into a name because of that.

Can you put a breakpoint on that line in the debugger and check the actual values in there?
0
 
rito1Author Commented:
After using VS debugger I found the culprit.

Thanks,

Rit
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now