将数据库中的数据取出然后转换成为Xml形式的解析1.列表

接口

image

协议

Request中的Body部分为

image

Response中的Body部分为

image

image

示例为

image

image

转换后的Xml

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Adapter.WebUI.Interface;
using Common.Utils;
using System.Xml.Linq;
using Adapter.DataProvider.Interface;
using Adapter.DataProvider.Common;
using Common.Utils.Helper;

namespace Adapter.Impl
{
    public class SelectInfoQueryProcess : IProcess
    {
        /// <summary>
        /// 根据用户ID查询所关联用户的工单信息列表
        /// </summary>
        /// <param name="header"></param>
        /// <param name="body"></param>
        /// <returns></returns>
        public Result<string> Process(string header, XElement body)
        {
            try
            {
                ISelectInfoDataProvider provider = DataProviderFactory.CreateSelectInfoDataProvider();

                string customerID = body.Element("CustomerID").Value;
                string currentPage = body.Element("CurrentPage").Value;
                string pageSize = body.Element("PageSize").Value;
                IList<SelectInfo> lstServiceInfo = provider.GetSelectInfoListByCustomerId(customerID,currentPage,pageSize);

                XElement xeBody = new XElement("Body",
                    new XElement("CategoryListPage",
                        new XElement("ListCount", ""),
                        new XElement("ListType", ""),
                        new XElement("CategoryList", "")));

                foreach (SelectInfo sObj in lstServiceInfo)
                {
                    xeBody.Element("CategoryListPage").Element("CategoryList").Add(
                                        new XElement("ListItem",
                                            new XElement("WO_ID", sObj.WO_ID), //工单号
                                            new XElement("WO_STATUS_NAME", sObj.WO_STATUS_NAME),//完成状态
                                            new XElement("WO_STATUS", sObj.WO_STATUS),//完成状体编号
                                            new XElement("TargetUri", "")));
                }

                return new Result<string> { Code = 200, Message = "", State = xeBody.ToString() };

            }
            catch (Exception ex)
            {
                LogHelper.Error("SelectInfoListQueryProcess $ Process", ex);
                return new Result<string> { Code = (ushort)StatusCode._523, Message = "OA获取数据失败", State = string.Empty };
            }
        }
    }
}

转载于:https://www.cnblogs.com/doubleyan/archive/2011/03/25/1995309.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要将解析后的XML数据存入达梦数据库,可以按照以下步骤进行: 1. 使用XML解析器(如Java的DOM或SAX解析器)读取XML文件,并将其解析成程序可用的数据格式,例如Java的Document对象。 2. 遍历解析后的数据,提取需要存入数据库数据,并将其转换为达梦数据库数据格式,例如Java的PreparedStatement对象。 3. 使用JDBC连接到达梦数据库,并将转换后的数据插入到数据库,例如Java的executeUpdate()方法。 下面是一个Java示例代码,演示了如何将解析后的XML数据存入达梦数据库: ```java import java.sql.*; import javax.xml.parsers.*; import org.w3c.dom.*; public class XmlToDm { public static void main(String[] args) { try { // 解析XML文件 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse("data.xml"); // 连接到达梦数据库 Class.forName("dm.jdbc.driver.DmDriver"); Connection conn = DriverManager.getConnection("jdbc:dm://localhost:5236", "user", "password"); // 提取需要存入数据库数据 NodeList nodes = doc.getElementsByTagName("person"); for (int i = 0; i < nodes.getLength(); i++) { Element person = (Element) nodes.item(i); String name = person.getAttribute("name"); int age = Integer.parseInt(person.getAttribute("age")); // 将数据转换为达梦数据库数据格式 PreparedStatement stmt = conn.prepareStatement("INSERT INTO person (name, age) VALUES (?, ?)"); stmt.setString(1, name); stmt.setInt(2, age); // 插入数据到达梦数据库 int rows = stmt.executeUpdate(); System.out.println(rows + " row(s) inserted."); } // 关闭数据库连接 conn.close(); } catch (Exception e) { e.printStackTrace(); } } } ``` 在上面的示例代码,我们首先使用Java内置的XML解析解析了名为"data.xml"的XML文件,并遍历了其的"person"元素,提取了"name"和"age"属性的值,并将其转换为达梦数据库数据格式。接着,我们使用JDBC连接到达梦数据库,并将转换后的数据插入到"person"表。最后,我们关闭了数据库连接。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值