XML 代码:

<?xml version="1.0" encoding="utf-8" ?>
<ChartSet  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:noNamespaceSchemaLocation="../ChartSchema.xsd">
  <Chart Title="XXXXXXX情况" ChartType="Line">
    <AxisX Title="" XField="rq"></AxisX>
    <AxisY Title="" Unit="次数" UnitT="符合率(%)">
      <YChild Name="事故预报" Color="Blue" XField="rq" YField="BNYBHJ"/>

<YChild Name="{Year}" Color="Blue" XField="rq" YField="BENYEAR"/>
      <YChild Name="预报准确" Color="Orange" XField="rq" YField="BNYBZQ"/>
      <YChild Name="预报符合率" Color="Orange" XField="rq" YField="BNYBFHL" TWOY="true"/>
    </AxisY>
    <Command XField="rq" YFields="BNYBHJ,BNYBZQ,BNYBFHL">
      <CommandText>
        <![CDATA[
                    select
                   t.bnybhj as BNYBHJ,
                   t.bnybfh as BNYBZQ,
                   t.bnybfhl as BNYBFHL,

        t.bnybfhl as BENYEAR,
                   substr(t.reportdate, 0, 4) || '年' as rq
                    from  table  t
                    where t.reportdate between '{strBeginRepordate}' and '{Reportdate}'

and t.name='{Name}'
                   order by t.reportdate
          
          
          
        ]]>
      </CommandText>
    </Command>
  </Chart>
</ChartSet>

XML文件 与  ChartSchema.xsd 文件在一个文件夹下

XML文件标签引用于 xsi:noNamespaceSchemaLocation="../ChartSchema.xsd">

标签:ChartSet  Chart Command  CommandText  XField  YFields  AxisY  AxisX  Title  …… ……

ChartSchema.xsd 代码如下:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="ChartSchema" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">

<!--图表集-->
  <xs:element name="ChartSet">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="Chart" maxOccurs="unbounded" minOccurs="1" />
      </xs:sequence>
      <xs:attribute name="GroupID" type="xs:int" />
      <xs:attribute name="GroupName" type="xs:string" />
    </xs:complexType>
  </xs:element>

<!--图表-->
  <xs:element name="Chart">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="AxisX" maxOccurs="1" minOccurs="1" />
        <xs:element ref="AxisY" minOccurs="1" />
        <xs:element ref="Command" maxOccurs="1" minOccurs="1"/>
      </xs:sequence>
      <xs:attribute name ="Title" type="xs:string"></xs:attribute>
      <xs:attribute name ="ChartType">
        <xs:simpleType>
          <xs:restriction base="xs:string">
            <!--折线图-->
            <xs:enumeration value="Line" />
            <!--柱状图-->
            <xs:enumeration value="Column" />
            <!--饼图-->
            <xs:enumeration value="Pie" />
          </xs:restriction>
        </xs:simpleType>
      </xs:attribute>
    </xs:complexType>
  </xs:element>

<xs:element name="AxisX">
    <xs:complexType>
      <xs:attribute name="Title" type="xs:string"></xs:attribute>
      <xs:attribute name="XField" type="xs:string"></xs:attribute>
    </xs:complexType>
  </xs:element>

<xs:element name="AxisY">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="YChild" maxOccurs="unbounded" minOccurs="1" />
      </xs:sequence>
      <xs:attribute name="Title" type="xs:string"></xs:attribute>
      <xs:attribute name="Unit" type="xs:string"></xs:attribute>
      <xs:attribute name="UnitT" type="xs:string"></xs:attribute>
    </xs:complexType>
  </xs:element>

<!--数据访问命令-->
  <xs:element name="Command">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="CommandText" type="xs:string"></xs:element>
      </xs:sequence>
      <xs:attribute name="XField" type="xs:string" />
      <xs:attribute name="YFields" type="xs:string" />
    </xs:complexType>
  </xs:element>

<!--图表序列(即图表数据对象)-->
  <xs:element name="YChild">
    <xs:complexType>
      <xs:attribute name="Name" type="xs:string" />
      <xs:attribute name="XField" type="xs:string" />
      <xs:attribute name="YField" type="xs:string" />
      <xs:attribute name="TWOY" type="xs:boolean" />
      <xs:attribute name="Color">
        <xs:simpleType>
          <xs:restriction base="xs:string">
            <xs:enumeration value="Red" />
            <xs:enumeration value="Green" />
            <xs:enumeration value="Yellow" />
            <xs:enumeration value="Blue" />
            <xs:enumeration value="Orange" />
            <xs:enumeration value="Navy" />
            <xs:enumeration value="Chocolate" />
            <xs:enumeration value="Black" />
            <xs:enumeration value="Pink" />
          </xs:restriction>
        </xs:simpleType>
      </xs:attribute>
    </xs:complexType>
  </xs:element>

</xs:schema>

WCF 解析xml 文件方法 如下:

private ListItem AnalyzeXML(string XMLCode, string Reportdate, string ChartName, string OildomName)
        {
            IDataBase oDB = DBFactory.GetDBInstance();
            ListItem liChart = new ListItem();
            XmlDocument config;
            string basePath = System.AppDomain.CurrentDomain.BaseDirectory + "Silverlight\\Config\\SCYX\\";
            string configPath = basePath + XMLCode;
            if (!System.IO.File.Exists(configPath))
            {
                throw new Exception("指定配置文件不存在!");
            }
            config = new XmlDocument();
            config.Load(configPath);

XmlNode rootNode = config.SelectSingleNode("/ChartSet");
            if (rootNode == null)
            {
                throw new Exception("图集合的配置不存在!");
            }
            for (int i = 0; i < rootNode.ChildNodes.Count; i++)
            {
                try
                {
                    DataTable dt;
                    XmlNode ChartNode = rootNode.ChildNodes[i];
                    if (ChartNode == null)
                    {
                        throw new Exception("图的配置不存在!");
                    }
                    #region 获取Chart基本信息
                    if (ChartNode == null)
                    {
                        throw new Exception("图的配置不存在!");
                    }
                    liChart.ChartName = ChartName;
                    liChart.Title = ChartNode.Attributes["Title"].Value;
                    liChart.Title = liChart.Title.Replace("{Date}", Reportdate);
                    liChart.Title = liChart.Title.Replace("{Name}", OildomName);
                    liChart.ChartType = ChartNode.Attributes["ChartType"].Value;
                    #endregion

#region 获取Command信息
                    XmlNode xnCommand = ChartNode.SelectSingleNode("Command");
                    string sSQL = "";
                    if (xnCommand == null && xnCommand.ChildNodes.Count == 0)
                    {
                        throw new Exception("未找到配置数据SQL");
                    }
                    else
                    {
                        // string strBeginRepordate = Reportdate.Substring(0, 6) + "01";//月初
                        //string strEndRepordate = DateTime.ParseExact(strBeginRepordate, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture).AddMonths(1).AddDays(-1).ToString("yyyyMMdd");//月末
                        string strBeginRepordate = DateTime.ParseExact(Reportdate, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture).AddMonths(-1).ToString("yyyyMMdd");//当前日期前一个月
                        sSQL = (xnCommand.ChildNodes[0]).InnerText;
                        sSQL = sSQL.Replace("{Reportdate}", Reportdate);
                        sSQL = sSQL.Replace("{strBeginRepordate}", strBeginRepordate);
                        sSQL = sSQL.Replace("{Name}", OildomName);
                        dt = oDB.GetDataTable(sSQL);
                    }
                    #endregion

#region 获取AxisX信息
                    XmlNode xnAxisX = ChartNode.SelectSingleNode("AxisX");
                    string[] sXAXIS = new string[dt.Rows.Count];
                    for (int h = 0; h < dt.Rows.Count; h++)
                    {
                        sXAXIS[h] = dt.Rows[h][xnAxisX.Attributes["XField"].Value].ToString();
                    }
                    liChart.XAXIS = sXAXIS;
                    #endregion

#region 获取AxisY信息
                    XmlNode xnAxisY = ChartNode.SelectSingleNode("AxisY");
                    if (xnAxisY.Attributes["Unit"] != null)
                        liChart.YUint = xnAxisY.Attributes["Unit"].Value;
                    string strYear = Reportdate.Substring(0, 4);//本年
                    string strBegReportDate = DateTime.ParseExact(Reportdate, "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture).AddYears(-1).ToString("yyyyMMdd").Substring(0, 4);//上一年
                    for (int j = 0; j < xnAxisY.ChildNodes.Count; j++)
                    {
                        XmlNode xnYChild = xnAxisY.ChildNodes[j];
                        YAXIS oYAXIS = new YAXIS();
                        oYAXIS.Name = xnYChild.Attributes["Name"].Value;
                        oYAXIS.Name = oYAXIS.Name.Replace("{Year-1}", strBegReportDate);
                        oYAXIS.Name = oYAXIS.Name.Replace("{Year}", strYear);
                        oYAXIS.Color = xnYChild.Attributes["Color"].Value;
                        oYAXIS.XField = xnYChild.Attributes["XField"].Value;
                        oYAXIS.YField = xnYChild.Attributes["YField"].Value;
                        double[] sYAXIS = new double[dt.Rows.Count];
                        for (int k = 0; k < dt.Rows.Count; k++)
                        {
                            sYAXIS[k] = Convert.ToDouble(dt.Rows[k][oYAXIS.YField]);
                        }
                        oYAXIS.YValue = sYAXIS;
                        liChart.YAXISs.Add(oYAXIS);
                    }
                    #endregion
                }
                catch (Exception e)
                {
                    throw new Exception("获取配置文件失败!" + e.Message);
                }
            }

return liChart;
        }

XML配置silverlight ,wcf 解析xml的更多相关文章

  1. Spring的配置文件ApplicationContext.xml配置头文件解析

    Spring的配置文件ApplicationContext.xml配置头文件解析 原创 2016年12月16日 14:22:43 标签: spring配置文件 5446 spring中的applica ...

  2. python XML文件解析:用xml.dom.minidom来解析xml文件

    python解析XML常见的有三种方法: 一是xml.dom.*模块,是W3C DOM API的实现,若需要处理DOM API则该模块很合适, 二是xml.sax.*模块,它是SAX API的实现,这 ...

  3. Python3使用xml.dom.minidom和xml.etree模块儿解析xml文件,封装函数

    总结了一下使用Python对xml文件的解析,用到的模块儿如下: 分别从xml字符串和xml文件转换为xml对象,然后解析xml内容,查询指定信息字段. from xml.dom.minidom im ...

  4. Java解析XML文档——dom解析xml

    一.前言 用Java解析XML文档,最常用的有两种方法:使用基于事件的XML简单API(Simple API for XML)称为SAX和基于树和节点的文档对象模型(Document Object M ...

  5. CSS控制XML与通过js解析xml然后通过html显示xml中的数据

    使用CSS控制XML的显示 book.css bookname{ display:block;color:Red} author{ display:block;font-style:italic} p ...

  6. DOM生成XML文档与解析XML文档(JUNIT测试)

    package cn.liuning.test; import java.io.File; import java.io.IOException; import javax.xml.parsers.D ...

  7. webservice04#对象与xml转换-jaxb#Stax解析xml#新建修改xml

    1,Student类 package com.yangw.xml; import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement / ...

  8. 遍历文件 创建XML对象 方法 python解析XML文件 提取坐标计存入文件

    XML文件??? xml即可扩展标记语言,它可以用来标记数据.定义数据类型,是一种允许用户对自己的标记语言进行定义的源语言. 里面的标签都是可以随心所欲的按照他的命名规则来定义的,文件名为roi.xm ...

  9. XML专题:使用NSXMLParser解析xml文件

    使用NSXMLParser解析xml文件 1. 设置委托对象,开始解析     NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data ...

随机推荐

  1. OpenGL ES 2.0 顶点着色器的妙用

    1.飘扬的旗帜(水面起伏) 基本原理 绘制一帧画面时由顶点着色器根据一定的规则变换各个顶点的位置,即可得到旗帜迎风飘扬的效果. 为了使旗帜的飘动过程比较平滑,采用基于正弦曲线的顶点位置变换规则.

  2. 利用css3-animation来制作逐帧动画

    前言 趁着还没有元旦之前先码一篇文章,不然到时候估计又被各种虐了,所以趁现在还有力气先来一篇.今天来聊聊css3中的动画属性animation,对这个属性懵懂是在很早的时候有前辈用这个 animati ...

  3. Python 多线程 队列 示例

    Python3,开一个线程,间隔1秒把一个递增的数字写入队列,再开一个线程,从队列中取出数字并打印到终端 #! /usr/bin/env python3 import time import thre ...

  4. uc/os 笔记(转)

    1.uC/OS-II中使用互斥信号对象应该注意 互斥信号对象(Mutual Exclusion Semaphore)简称Mutex,是uC/OS-II的内核对象之一,用于管理那些需要独占访问的资源,并 ...

  5. 使用C# DES解密java DES加密的字符串

    转自 microAllen   最近需要使用C#的DES解密工具类解密字符串,但是要解密的字符串是使用java进行DES加密的,去网上查了关于C#和java关于DES加密解密的资料,发现可以相互加密解 ...

  6. Effective Java Item4:Enforce noninstantiability with a private constructor

    Item4:Enforce noninstantiability with a private constructor 通过构造私有化,禁止对象被实例化. public class UtilClass ...

  7. Codeforces 163A Substring and Subsequence

    http://codeforces.com/problemset/problem/163/A?mobile=true 题目大意:给出两个串,问a的连续子串和b的子串(可以不连续)相同的个数. 思路:在 ...

  8. UVA11922--Permutation Transformer (伸展树Splay)

    题意:m条操作指令,对于指令 a  b 表示取出第a~b个元素,翻转后添加到排列的尾部. 水题卡了一个小时,一直过不了样例.  原来是 dfs输出的时候 忘记向下传递标记了. #include < ...

  9. c++命名空间using

    #include<iostream> namespace run1 { ; } namespace run2 { ; void show() { std::cout << x ...

  10. phpcms:六、频道页(category.html)

    1.当前栏目的ID:{$catid}标题样式:{title_style($v[style])}(在添加内容或编辑内容的时候,标题右边 有一个选择颜色的块).{str_cut(strip_tags($v ...