none
InsertXML from another file "XML markup cannot be inserted in the specified location" RRS feed

  • Question

  • Hi,

    I grab the xml from one document with doc.Content.WordOpenXML() and then dump it into a database. I then open another file and attempt to insert the xml with doc.Content.InsertXML(xmlFromDatabase) and recieve the following error:

    "XML markup cannot be inserted in the specified location"

    Steps I have already taken to check this problem:

    • The XML can be inserted back into the origional document with doc.Paragraphs(1).InsertXML() OK.
    • The second document still throws the same issue if inserted into a paragraph rather than the full content range.
    • The XML being read by the second document has been verified to be the same as the XML found in the origional document.
    • Have sent the data from the origional document to the database and back to the same origional document and was able to successfully insert the xml to the first paragraph.

    Is there something I'm missing, or does it seem insertxml can not read xml from another document? If so is there some work around by editing the xml or something?


    Wednesday, March 19, 2014 2:11 AM

Answers

  • Thanks for your helpful response Eugene, in the end I found it was a problem with the encoding in the database. Changed it to utf8-bin and it worked.
    Tuesday, April 8, 2014 12:29 AM

All replies

  • Hello Nathan,

    Could you please specify the Word version including its build number?

    I see the following entry on the Issues that are fixed in Word 2003 by Office 2003 Service Pack 1 page:

    You receive an error message when you programmatically use the InsertXML method to  insert a text fragment into an XML file

    When you programmatically use the InsertXML method to insert a text fragment into an XML file, you may receive the following error message:

    XML markup cannot be inserted in the specified location.

    Read more about this in the Getting error "XML markup" in few machines forum thread.

    Wednesday, March 19, 2014 7:16 AM
  • I am using:

    • Word 2013 (15.0.4551.1006) MSO (15.9.4551.1007) 32-bit
    • Visual Studio 2013 Version 12.0.21005.1 REL
    • Microsoft .NET Framework Version 4.5.50938

    Edit: As you can see from the deleted post, I tried running a loop on insertXML until successful as per their suggestions in one of your links. It worked for a single sentence but not for anything more than that which is pretty important.

    Edit2: Done a few more tests it seems certain tags are causing the issue. This is what I've found:

    Allowed
    tables
    multiple paragraphs
    bookmarks
    formatting

    Not Allowed
    groupcontentcontrol
    images

    Is this a known limitation?


    Wednesday, March 19, 2014 11:37 PM
  • Nathan,

    Not sure. Only official representatives can give the definitive answer whether this is a bug or feature.

    But, as a workaround, you can use Open XML SDK for creating/editing documents on the fly. Read more about this in the Pushing Data from a Database into a Word Document article.

    Thursday, March 20, 2014 6:48 AM
  • Thanks for your helpful response Eugene, in the end I found it was a problem with the encoding in the database. Changed it to utf8-bin and it worked.
    Tuesday, April 8, 2014 12:29 AM