problem with createProcessingInstruction - NewSolutionWithData

  • Thread starter Antony Blackwell
  • Start date
A

Antony Blackwell

I have loaded an XML document from a secondary source in Infopath Jscript
with SP1. The resulting GetDOM document no longer has the "InfoPath.Document"
PI in it.
I have tried to use insertBefore with a createProcessingInstruction but this
does not place the PI at the start of the document. It places it after the
first node with the namespaces in "<my:myFields....><mso-" at this stage the
PI is not read and is no use.

Also when trying to create the standard "xml" PI an error message is
generated 'MSXML5.DLL This operation cannot be performed with a Node of type
XMLDECL'

The complete XML minus PI's is passed sucessfully using newsoultionwithdata.
As the data store is Sharepoint the saved XML will not open with Infopath as
the PI is missing.

I have tried to insert the PI in the new document form_load section also
without success.

Does Anyone have a solution or is this a bug?
below is some of the code

var objXMLFileAdapter = XDocument.GetDOM("ptsdata");
objXMLFileAdapter.setProperty("SelectionNamespaces",
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2004-05-29T08:53:22" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003"');
var oOutputXML = objXMLFileAdapter.documentElement;

var oOutputPIXML = oOutputXML.childNodes.item(0);
var oPIText =
objXMLFileAdapter.createProcessingInstruction("mso-application",
"progid=\"InfoPath.Document\"");
oOutputXML.insertBefore(oPIText,oOutputPIXML);
var oPI = objXMLFileAdapter.createProcessingInstruction("xml",
"version=\"1.0\"");
oOutputXML.insertBefore(oPI, oOutputXML.documentElement);
 
A

Antony Blackwell

Hi Greg,

I tried the solution on Infopathdev.com, unfortunately it does not work. I
cut and pasted the script code to the Form_load section and saved the file to
the hard disk. The resulting form had the xml icon and the document was still
missing the PI's.

However, this code will allow me to load an XML doc and insert the Pi's:

********
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.5.0");
var root;
xmlDoc.async = false;
xmlDoc.load("C:\\ptsample.xml");
if (xmlDoc.parseError.errorCode != 0) {
var myErr = xmlDoc.parseError;
} else {
root = xmlDoc.documentElement;
var oPI = xmlDoc.createProcessingInstruction("xml", "version=\"1.0\"
encoding=\"UTF-8\"");
xmlDoc.insertBefore(oPI, root);
var oPIText = xmlDoc.createProcessingInstruction("mso-application",
"progid=\"InfoPath.Document\"");
xmlDoc.insertBefore(oPIText,root);
}

objXMLFileAdapter = xmlDoc;
*******
Also if I use documentElement they disappear again for example:

*******
xmlDoc = xmlDoc.documentElement
*******

with the new code i get an error : stating that MSXML5.dll Access is denied

Greg Collins said:
Check out the following Blog article:
http://www.infopathdev.com/blog/PermaLink.aspx?guid=c86d01e6-3494-4087-aac8-03c26f9c895d

--
Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com



I have loaded an XML document from a secondary source in Infopath Jscript
with SP1. The resulting GetDOM document no longer has the "InfoPath.Document"
PI in it.
I have tried to use insertBefore with a createProcessingInstruction but this
does not place the PI at the start of the document. It places it after the
first node with the namespaces in "<my:myFields....><mso-" at this stage the
PI is not read and is no use.

Also when trying to create the standard "xml" PI an error message is
generated 'MSXML5.DLL This operation cannot be performed with a Node of type
XMLDECL'

The complete XML minus PI's is passed sucessfully using newsoultionwithdata.
As the data store is Sharepoint the saved XML will not open with Infopath as
the PI is missing.

I have tried to insert the PI in the new document form_load section also
without success.

Does Anyone have a solution or is this a bug?
below is some of the code

var objXMLFileAdapter = XDocument.GetDOM("ptsdata");
objXMLFileAdapter.setProperty("SelectionNamespaces",
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2004-05-29T08:53:22" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003"');
var oOutputXML = objXMLFileAdapter.documentElement;

var oOutputPIXML = oOutputXML.childNodes.item(0);
var oPIText =
objXMLFileAdapter.createProcessingInstruction("mso-application",
"progid=\"InfoPath.Document\"");
oOutputXML.insertBefore(oPIText,oOutputPIXML);
var oPI = objXMLFileAdapter.createProcessingInstruction("xml",
"version=\"1.0\"");
oOutputXML.insertBefore(oPI, oOutputXML.documentElement);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top