none
Biztalk Custom disassembler component is failing if there is any xml declaration. RRS feed

  • Question

  • Hi,

    I am using custom disassembler component to split large xml file into small chunks. But if the xml file starts with xml declaration like <?xml version="1.0" encoding="utf-16"?> then it is failing. So how to handle this one in pipeline component. Please help.

    Friday, July 12, 2013 4:21 PM

Answers

  • Ratnak,

    Can you please try the following snippit, It should work for the scenario you described:

    public void Disassemble(IPipelineContext pc, IBaseMessage inmsg)
            {
                Stream sr = inmsg.BodyPart.Data;
                XmlReader xmlReader = XmlReader.Create(sr);
    
                //save and don't generate xml declaration 
                XmlWriterSettings writerSettings = new XmlWriterSettings();
                writerSettings.OmitXmlDeclaration = true;
                StringBuilder stringBuilder = new StringBuilder();
                using (XmlWriter xmlWriter = XmlWriter.Create(stringBuilder, writerSettings))
                {
                    xmlWriter.WriteNode(xmlReader, false);
                }
    
                byte[] byteArray = Encoding.ASCII.GetBytes(stringBuilder.ToString());
                MemoryStream stream = new MemoryStream(byteArray);
    
                inmsg.BodyPart.Data = stream;
            }


    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful.

    • Proposed as answer by Chandra Kumar Friday, July 12, 2013 8:05 PM
    • Marked as answer by Pengzhen Song Thursday, July 25, 2013 11:53 AM
    Friday, July 12, 2013 7:22 PM

All replies

  • Can you provide some detail on exactly what is failing?
    Friday, July 12, 2013 5:03 PM
    Moderator
  • How are you doing chucks ? Are you using XmlDocument ?

    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful.

    Friday, July 12, 2013 6:23 PM
  • Ratnak,

    Can you please try the following snippit, It should work for the scenario you described:

    public void Disassemble(IPipelineContext pc, IBaseMessage inmsg)
            {
                Stream sr = inmsg.BodyPart.Data;
                XmlReader xmlReader = XmlReader.Create(sr);
    
                //save and don't generate xml declaration 
                XmlWriterSettings writerSettings = new XmlWriterSettings();
                writerSettings.OmitXmlDeclaration = true;
                StringBuilder stringBuilder = new StringBuilder();
                using (XmlWriter xmlWriter = XmlWriter.Create(stringBuilder, writerSettings))
                {
                    xmlWriter.WriteNode(xmlReader, false);
                }
    
                byte[] byteArray = Encoding.ASCII.GetBytes(stringBuilder.ToString());
                MemoryStream stream = new MemoryStream(byteArray);
    
                inmsg.BodyPart.Data = stream;
            }


    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful.

    • Proposed as answer by Chandra Kumar Friday, July 12, 2013 8:05 PM
    • Marked as answer by Pengzhen Song Thursday, July 25, 2013 11:53 AM
    Friday, July 12, 2013 7:22 PM
  • Make sure your message encoding matches your XML Declaration.  In the case above your declaration indicates utf-16 (<?xml version="1.0" encoding="utf-16"?>).

    If this doesn't help, can you provide the error or exception you're receiving?


    David Downing... If this answers your question, please Mark as the Answer. If this post is helpful, please vote as helpful.


    Friday, July 12, 2013 9:22 PM