We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

SaveFormat.Xml NullReferenceException

Trying to use SaveFormat.Xml always results in a NullReferenceException - “Object reference not set to an instance of an object”. Any other SaveFormat works as expected. Code as follows:

Dim asposeDoc As New Aspose.Words.Document(wordDocumentPath)
Dim stream As System.IO.MemoryStream = New System.IO.MemoryStream
asposeDoc.Save(stream, Aspose.Words.SaveFormat.Pdf)
Dim pdf As New Aspose.Pdf.Document(stream)
If pdf IsNot Nothing Then pdf.Save(xmlFilePath, SaveFormat.Xml)

If a different SaveFormat is chosen (Doc, XPS etc.) then the code works fine. I’m just testing it with a very simple Word document only containing some ‘lorem ipsum…’ text and nothing else. I’m using the current Words and PDF DLLs. Can you let me know if I am doing something wrong or if there is a bug? Thanks.

Hi Roger,
Thanks for your interest in our products.
Using Aspose.Pdf, SaveFormat does not allow to save file in XML format directly, the valid formats are (Doc, Xps and Html). You can convert an FDF file to XML format using Aspose.Pdf. For more details, please visit: Converting an FDF to XML format
Please feel free to contact support in case you need any further assistance.
Thanks & Regards,

Thank you, Rashid.

Following on from that then, are you able to tell me how to go from an Aspose.Words document to an XML template? In the article Use Aspose.Word to Create XML Template there seems to be a step missing between having a Word document and having an XML template for a PDF (it goes from Sample.doc to Sample.xml with no demonstration of how to do so).

Thanks.

Hi Roger,
Thank you for sharing the feedback.
As per provided detail, You can firstly use Aspose.Word to edit the appearance and then save it as XML. After a litter modification, you can finally save this XML file as a PDF document. However, using Aspose.Pdf you can convert an XML file in PDF format but you are trying to save the resultant file in XML format that’s why you were facing exception.
Moreover, if you want to know about the demonstration from Sample.doc to Sample.xml. As your this request is related to Aspose.Words, I am moving your request in Aspose.Words forum. My colleagues from Aspose.Words component team will answer you shortly.
We apologize for your inconvenience.
Thanks & Regards,

Hi Roger,
Thank you for inquiry. Please follow up the code snippet to convert Word document in xml format. Moreover please view details here.

Document document = new Document("c:\\temp\\Test.doc");
document.Save("c:\\temp\\TestOut.xml", SaveFormat.WordML);

In case of any ambiguity, please let me know.

Hi there,

Thanks for your inquiry.

Could you please clarify why you need to convert a document into XML format? From what I understand this format is only used with converting to PDF. In such a case you can just use Aspose.Words to convert to PDF directly.

Thanks,

Hi there,

As per my earlier post, I want to create an XML Template, as your article says can be done: Use Aspose.Word to Create XML Template but it misses out the step of getting from Word to the XML Template. It looks from the article like the XML corresponds with the Aspose.Pdf.xsd schema. However, the XML generated by saving as WordML looks nothing like this.

I want to create an XML Template that can be used for making different PDFs: Use Xml as Template.

Thanks.

Thank you, Imran, but this does not produce an XML Template as I want. The article suggests Word can be used to make a Template corresponding to the Aspose.pdf.xsd schema, which can then be used to generate different PDFs. Saving as WordML produces something very different as far as I can see.

Thanks.

Hi there,

Thanks for your inquiry.

I’m afraid only very old versions of Aspose.Words provide the ability to save a document in the Aspose.Pdf XML format. This format was removed and replaced by our own rendering engine which renders the documents to PDF without the use of Aspose.Pdf.

I’m afraid I’m still not quite clear why you need to use the XML intermediate format. You can simply design the template in the form of a word document still and then using Aspose.Words convert that to PDF directly. Why do you need the XML format inbetween?

Thanks,

Hi Adam,

I want to do it for the reasons set out in the articles Use Xml as Template and Use Aspose.Word to Create XML Template. An XML Template can be re-used across different documents and I can add data into the Template before making the PDF. It would be nice to use Word to make the basic layout of the Template without coding all the XML by hand (again as the article says can be done). Those two articles were only edited last month: if it’s not possible to use Word to make a Template, perhaps the article needs to be edited again to say this?

Thanks.

Hi there,

Thanks for this additional information.

I understand you want to use the XML as a template and to merge data into this template dynamically, however there is no need to convert to Aspose.Pdf XML format in order to achieve this unless you really need to have it in this format for some reason (which from your description I don’t think you require).

Using Aspose.Words you can create your template in full detail as a word document and then merge data into the template dynamically by using mail merge: https://docs.aspose.com/words/net/mail-merge-and-reporting/. You can then convert this to PDF or any other format as shown here: https://docs.aspose.com/words/net/file-formats-and-conversions/

Also, I apologise that the last edit date confused you. This date is recent as we just migrated to a new documentation system and all pages were recently edited. I will inform the support developer for Aspose.Pdf that this article is out dated.

Thanks,

Thanks Adam. I just thought using an XML Template would be a neat way of generating PDF forms and documents on the fly and that the XML could be tweaked without needing to use Word at all once the template had been set up.

I was thinking along these lines: use Word to create a form; make an XML Template based on that form; subsequently just use a text editor for minor edits and changes in the XML; use the XML to generate PDFs. It may be that it’s unnecessary, but I’m trying to see what’s possible!

Thanks again.