locked
Generating a XML file with Header RRS feed

  • Question

  • Hi,

    I am trying to create a XML with the following header,

    <?xml version='1.1' encoding='utf-8'?>

    <!DOCTYPE CrtlFile PUBLIC "-//Bank//File21.1//EN""CrtlFile_1_1.dtd">

    This header should be sent in the xml while sending always.

    Can Some one advise me on this.

    Thanks,

    Sarva.


    Tuesday, September 29, 2015 8:44 AM

Answers

  • Try this, and let me know if doesn't work,

    public Microsoft.BizTalk.Message.Interop.IBaseMessage Execute(Microsoft.BizTalk.Component.Interop.IPipelineContext pc, Microsoft.BizTalk.Message.Interop.IBaseMessage inmsg)
    {
    	string messageString = new StreamReader(inmsg.BodyPart.Data).ReadToEnd();
    	messageString = messageString.Trim();
    	Regex doctypePattern = new Regex("<!DOCTYPE.+?>");
    	messageString = doctypePattern.Replace(messageString, string.Empty);
    	MemoryStream memStream = new MemoryStream();
    	byte[] data = Encoding.UTF8.GetBytes(messageString);
    	memStream.Write(data, 0, data.Length);
    	memStream.Seek(0, SeekOrigin.Begin);
    
    	inmsg.BodyPart.Data = memStream;
    	return inmsg;
    }


    Thanks, If my reply is helpful please mark as answer or vote as helpful.

    • Marked as answer by SarvaSetty Wednesday, September 30, 2015 12:24 PM
    Wednesday, September 30, 2015 11:15 AM
    Moderator
  • Hi Kamlesh,

    Thank you for providing me the code which I was looking for,

    I have made some changes to your code and it gave me desired output.

    the following is the code which I have used.

            public Microsoft.BizTalk.Message.Interop.IBaseMessage Execute(Microsoft.BizTalk.Component.Interop.IPipelineContext pc, Microsoft.BizTalk.Message.Interop.IBaseMessage inmsg)
            {
                string messageString = new StreamReader(inmsg.BodyPart.Data).ReadToEnd();
                messageString = messageString.Trim();
                string doctypePattern = "<?xml version=\"1.1\" encoding=\"utf-8\"?> <!DOCTYPE CrtlFile PUBLIC \"-//Bank//File21.1//EN\"\"CrtlFile_1_1.dtd\">";
                //messageString = doctypePattern.Replace(messageString, string.Empty);
                messageString = doctypePattern + messageString;
                messageString = messageString.Replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>","");
                MemoryStream memStream = new MemoryStream();
                byte[] data = Encoding.UTF8.GetBytes(messageString);
                memStream.Write(data, 0, data.Length);
                memStream.Seek(0, SeekOrigin.Begin);
    
                inmsg.BodyPart.Data = memStream;
                return inmsg;
            }

    Thanks,

    Sarva.

    • Marked as answer by SarvaSetty Wednesday, September 30, 2015 12:24 PM
    Wednesday, September 30, 2015 12:24 PM

All replies

  • Hi Sarva,

    You just have to set your own custom xml declaration at design time in your pipeline component

    In the "Add processing instructions text" field you should put

    <?xml version='1.1' encoding='utf-8'?><!DOCTYPE CrtlFile PUBLIC "-//Bank//File21.1//EN""CrtlFile_1_1.dtd">

    Don't forget to set the Add XML Declaration to false

    Refer for more details, http://cherifmahieddine.com/2013/09/23/custom-biztalk-xml-declaration/


    Thanks, If my reply is helpful please mark as answer or vote as helpful.

    Tuesday, September 29, 2015 9:03 AM
    Moderator
  • Hi Kamlesh,

    I have tried your solution,

    I am getting the following error while I build the project,

    Error 1 Component 'XML assembler' properties validation failed. The processing instructions text property must be compliant to the XML standard. C:\Users\xxx\Desktop\VS\BiztalkXMLBuilder\SendPipe.btp 1 1 

    I have added the header in Add Processing Instructions text, and I changed the Add XML Declaration to false.

    Thanks,

    Sarva

    Tuesday, September 29, 2015 9:15 AM
  • May be the processing instruction should be

    <!--DOCTYPE CrtlFile PUBLIC "-//Bank//File21.1//EN""CrtlFile_1_1.dtd"-->


    Regards &lt;br/&gt; When you see answers and helpful posts,&lt;br/&gt; please click Vote As Helpful, Propose As Answer, and/or Mark As Answer

    Tuesday, September 29, 2015 9:27 AM
    Answerer
  • Hi Pi_Xel_Xar ,

    No there is no change in Header, It should be the same as I mentioned in the Question.

    <?xml version='1.1' encoding='utf-8'?>

    <!DOCTYPE CrtlFile PUBLIC "-//Bank//File21.1//EN""CrtlFile_1_1.dtd">

    Thanks,

    Sarva.

    Tuesday, September 29, 2015 9:51 AM
  • Sarva,

    Create a pipeline component to add the <!DOCTYPE declaration in the Encode stage. This should work as long as you don't need anything special from that dtd.


    Thanks, If my reply is helpful please mark as answer or vote as helpful.

    Tuesday, September 29, 2015 9:54 AM
    Moderator
  • The version seems to be unsupported xml version. 1.1. Should not it be 1.0. I am able to get a valid xml with ur headers if i change the version to 1.0. (Browser support)

    You can try setting these in ur map as well to see if that helps. Try setting the xml dec to version1.1 and the instruction in ur map where u create the message.


    Regards &lt;br/&gt; When you see answers and helpful posts,&lt;br/&gt; please click Vote As Helpful, Propose As Answer, and/or Mark As Answer


    Tuesday, September 29, 2015 9:58 AM
    Answerer
  • Hi,

    I We have to send them the XML document of version 1.1 only,

    So I think using a Custom pipeline and changing the version to 1.1 and adding <!Doctype> is only the option,

    I have created a pipeline component for encode stage, wondering what classes or methods to use to change the XML version and adding <!Doctype> tag.

    can some one help me on the code please?

            public Microsoft.BizTalk.Message.Interop.IBaseMessage Execute(Microsoft.BizTalk.Component.Interop.IPipelineContext pc, Microsoft.BizTalk.Message.Interop.IBaseMessage inmsg)
            {
    
                return inmsg;
            }

    Thanks,

    Sarva.

    Wednesday, September 30, 2015 10:34 AM
  • Try this, and let me know if doesn't work,

    public Microsoft.BizTalk.Message.Interop.IBaseMessage Execute(Microsoft.BizTalk.Component.Interop.IPipelineContext pc, Microsoft.BizTalk.Message.Interop.IBaseMessage inmsg)
    {
    	string messageString = new StreamReader(inmsg.BodyPart.Data).ReadToEnd();
    	messageString = messageString.Trim();
    	Regex doctypePattern = new Regex("<!DOCTYPE.+?>");
    	messageString = doctypePattern.Replace(messageString, string.Empty);
    	MemoryStream memStream = new MemoryStream();
    	byte[] data = Encoding.UTF8.GetBytes(messageString);
    	memStream.Write(data, 0, data.Length);
    	memStream.Seek(0, SeekOrigin.Begin);
    
    	inmsg.BodyPart.Data = memStream;
    	return inmsg;
    }


    Thanks, If my reply is helpful please mark as answer or vote as helpful.

    • Marked as answer by SarvaSetty Wednesday, September 30, 2015 12:24 PM
    Wednesday, September 30, 2015 11:15 AM
    Moderator
  • It is set in the map custom header properties, there is a doctype public and doctype system

    Bill Chesnut | Microsoft Integration MVP | Mexia | Melbourne Australia http://www.biztalkbill.com | http://www.mexia.com.au

    Wednesday, September 30, 2015 11:49 AM
  • Hi Kamlesh,

    Thank you for providing me the code which I was looking for,

    I have made some changes to your code and it gave me desired output.

    the following is the code which I have used.

            public Microsoft.BizTalk.Message.Interop.IBaseMessage Execute(Microsoft.BizTalk.Component.Interop.IPipelineContext pc, Microsoft.BizTalk.Message.Interop.IBaseMessage inmsg)
            {
                string messageString = new StreamReader(inmsg.BodyPart.Data).ReadToEnd();
                messageString = messageString.Trim();
                string doctypePattern = "<?xml version=\"1.1\" encoding=\"utf-8\"?> <!DOCTYPE CrtlFile PUBLIC \"-//Bank//File21.1//EN\"\"CrtlFile_1_1.dtd\">";
                //messageString = doctypePattern.Replace(messageString, string.Empty);
                messageString = doctypePattern + messageString;
                messageString = messageString.Replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>","");
                MemoryStream memStream = new MemoryStream();
                byte[] data = Encoding.UTF8.GetBytes(messageString);
                memStream.Write(data, 0, data.Length);
                memStream.Seek(0, SeekOrigin.Begin);
    
                inmsg.BodyPart.Data = memStream;
                return inmsg;
            }

    Thanks,

    Sarva.

    • Marked as answer by SarvaSetty Wednesday, September 30, 2015 12:24 PM
    Wednesday, September 30, 2015 12:24 PM