Adding Namespace to root node

Hi 

I need to add namespace to root node.

Currently

<CreateJob Version="14.2">

Has to be

<CreateJob xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Version="14.2">

I tried to do it manually, but i couldn't.

Any suggestions

July 14th, 2015 9:18am

The ESB Toolkit has a Pipeline Component for this purpose:

Microsoft.Practices.ESB.Namespace.PipelineComponents.AddNamespace

You could also write your own Pipeline Component, that appends the namespace and then execute it in the Decode-Stage of your Receive Pipeline, so that the Namespace is appended before the message hits the Disassemble Stage.

Morten la Cour



Free Windows Admin Tool Kit Click here and download it now
July 14th, 2015 9:41am

Hi,

You can use custom pipeline component that will add the namespace to your Root node, you can define the namespace at Runtime also and load that using property bag property of custom pipeline components.

pleaser refer this will solve your issue:- https://code.msdn.microsoft.com/Biztalk-change-RootNode-c19c84ee

Regards,

Sharad

July 14th, 2015 9:58am

Can you explain a bit about why?

Anyway, those namespaces in you example are xsd specific so you should not be using them for an instance document.

What you should have is something like:

<ns0:CreateJob xnlns:ns0="http://MyOrg/CreateJob" Version="14.2">

The ESB Toolkit comes with a Pipeline Component the Add Namespaces.  You don't need to install the whole thing, just GAC that one Assembly.

Free Windows Admin Tool Kit Click here and download it now
July 14th, 2015 10:19am

The ESB Toolkit has a Pipeline Component for this purpose:

Microsoft.Practices.ESB.Namespace.PipelineComponents.AddNamespace

You could also write your own Pipeline Component, that appends the namespace and then execute it in the Decode-Stage of your Receive Pipeline, so that the Namespace is appended before the message hits the Disassemble Stage.

Morten la Cour



July 14th, 2015 1:39pm

The ESB Toolkit has a Pipeline Component for this purpose:

Microsoft.Practices.ESB.Namespace.PipelineComponents.AddNamespace

You could also write your own Pipeline Component, that appends the namespace and then execute it in the Decode-Stage of your Receive Pipeline, so that the Namespace is appended before the message hits the Disassemble Stage.

Morten la Cour



Free Windows Admin Tool Kit Click here and download it now
July 14th, 2015 1:39pm

The ESB Toolkit has a Pipeline Component for this purpose:

Microsoft.Practices.ESB.Namespace.PipelineComponents.AddNamespace

You could also write your own Pipeline Component, that appends the namespace and then execute it in the Decode-Stage of your Receive Pipeline, so that the Namespace is appended before the message hits the Disassemble Stage.

Morten la Cour



July 14th, 2015 1:39pm

You can either use ESB toolkit pipeline component or you can use custom pipeline component as well to add namespace to message .

Code like below

 public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)
        {
           
            System.IO.Stream originalStream = pInMsg.BodyPart.GetOriginalDataStream();

            
            XDocument xDoc;
            using (XmlReader reader = XmlReader.Create(originalStream))
            {
                reader.MoveToContent();
                xDoc = XDocument.Load(reader);
            }
            xDoc.Root.RemoveAttributes();
            xDoc.Root.Add(new XAttribute(XNamespace.Xmlns + "ns0", Namespace));
            xDoc.Root.Name = xDoc.Root.GetNamespaceOfPrefix("ns0") + Rootnode;

            byte[] output = System.Text.Encoding.ASCII.GetBytes(xDoc.ToString());
            MemoryStream memoryStream = new MemoryStream();
            memoryStream.Write(output, 0, output.Length);
            memoryStream.Position = 0;
            pInMsg.BodyPart.Data = memoryStream;

            return pInMsg;
        }

Thanks

Abhishek

Free Windows Admin Tool Kit Click here and download it now
July 14th, 2015 1:59pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics