使用BizTalk解析Web service返回的XMLDocument消息

在系统集成过程中,有些系统发布出来的web service会将对象封装成XMLDocument并以字符串形式输出,当使用BizTalk与其他系统交互时,需要在BizTalk一端对XMLDocument格式的消息进行解析或拆分,我们可以采用循环的方式遍历这个XMLDocument消息来实现,也可以在web service一端取消将消息对象封装为XML的步骤,取而代之的是直接返回一个对象,在BizTalk这一端来对该对象进行解析。

在BizTalk中,通过对XMLDocument消息的循环,可以有效地将XML中的schema拆分出来,并将其中的某些字段映射到其他系统或数据库中。

首先我们要创建一个dll的类,来实现对XMLDocument的解析过程

using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.IO;


namespace BizTalkLoopTest
{
    public class Class1
    {
        public static int getLength(XmlDocument xd)
        {
            return xd.ChildNodes[0].ChildNodes.Count;
        }

        public static XmlDocument getInfo(XmlDocument xd,int index)
        {
            XmlDocument xdResult  = new XmlDocument();
            xdResult.InnerXml = "<ns0:Root xmlns:ns0=\"http://BizTalkLoopProject.Schema1\"><info>" + xd.ChildNodes[0].ChildNodes[index].InnerXml + "</info></ns0:Root>";
            return xdResult;
        }
    }
}







原文地址:https://www.cnblogs.com/aiwz/p/6154613.html