1293 lines
47 KiB
C#
1293 lines
47 KiB
C#
|
|
using System;
|
|||
|
|
using System.Xml;
|
|||
|
|
using CYQ.Data.Table;
|
|||
|
|
using System.Text.RegularExpressions;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using CYQ.Data.Tool;
|
|||
|
|
using System.Text;
|
|||
|
|
|
|||
|
|
namespace CYQ.Data.Xml
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// Xml/Html<6D><6C><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public partial class XHtmlAction : XHtmlBase
|
|||
|
|
{
|
|||
|
|
#region <EFBFBD><EFBFBD><EFBFBD>캯<EFBFBD><EFBFBD>
|
|||
|
|
/// <summary>
|
|||
|
|
/// Ĭ<>Ϲ<EFBFBD><CFB9>캯<EFBFBD><ECBAAF>[<5B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƿռ<C6BF><D5BC><EFBFBD>Xml]
|
|||
|
|
/// </summary>
|
|||
|
|
public XHtmlAction()
|
|||
|
|
: base()
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD>캯<EFBFBD><ECBAAF>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="isForHtml">trueʱ<65><CAB1><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>html<6D><6C><EFBFBD><EFBFBD><EFBFBD>ƿռ<C6BF>(http://www.w3.org/1999/xhtml)</param>
|
|||
|
|
public XHtmlAction(bool isForHtml)
|
|||
|
|
: base()
|
|||
|
|
{
|
|||
|
|
if (isForHtml)
|
|||
|
|
{
|
|||
|
|
base.LoadNameSpace(htmlNameSpace);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD>캯<EFBFBD><ECBAAF>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="isForHtml">trueʱ<65><CAB1><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>html<6D><6C><EFBFBD><EFBFBD><EFBFBD>ƿռ<C6BF>(http://www.w3.org/1999/xhtml)</param>
|
|||
|
|
/// <param name="isNoClone">trueʱ<65>ĵ<EFBFBD>ӦΪֻ<CEAA><D6BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>ͬһ<CDAC><D2BB><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD>ã<EFBFBD>falseʱ<65>ĵ<EFBFBD><C4B5><EFBFBD>д<EFBFBD><D0B4>ÿ<EFBFBD>λ<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>¡һ<C2A1><D2BB><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD>ء<EFBFBD></param>
|
|||
|
|
public XHtmlAction(bool isForHtml, bool isNoClone)
|
|||
|
|
: base()
|
|||
|
|
{
|
|||
|
|
if (isForHtml)
|
|||
|
|
{
|
|||
|
|
base.LoadNameSpace(htmlNameSpace);
|
|||
|
|
}
|
|||
|
|
IsNoClone = isNoClone;
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD>캯<EFBFBD><ECBAAF>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="nameSpaceUrl"><3E><>Xml<6D><6C><EFBFBD><EFBFBD><EFBFBD>ƿռ<C6BF>[<5B><><EFBFBD><EFBFBD>]</param>
|
|||
|
|
public XHtmlAction(string nameSpaceUrl)
|
|||
|
|
: base()
|
|||
|
|
{
|
|||
|
|
base.LoadNameSpace(nameSpaceUrl);
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region <EFBFBD><EFBFBD>ѯ
|
|||
|
|
/// <summary>
|
|||
|
|
/// GetByID or GetByName
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="idOrName">id or name</param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public XmlNode Get(string idOrName)
|
|||
|
|
{
|
|||
|
|
return Get(idOrName, null);
|
|||
|
|
}
|
|||
|
|
public XmlNode Get(string idOrName, XmlNode parentNode)
|
|||
|
|
{
|
|||
|
|
XmlNode node = GetByID(idOrName, parentNode);
|
|||
|
|
if (node == null)
|
|||
|
|
{
|
|||
|
|
node = GetByName(idOrName, parentNode);
|
|||
|
|
if (node == null)
|
|||
|
|
{
|
|||
|
|
switch (idOrName.ToLower())
|
|||
|
|
{
|
|||
|
|
case "head":
|
|||
|
|
case "body":
|
|||
|
|
case "title":
|
|||
|
|
case "form":
|
|||
|
|
case "style":
|
|||
|
|
case "meta":
|
|||
|
|
case "link":
|
|||
|
|
case "script":
|
|||
|
|
XmlNodeList xList = GetList(idOrName.ToLower(), parentNode);
|
|||
|
|
if (xList != null)
|
|||
|
|
{
|
|||
|
|
node = xList[0];
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return node;
|
|||
|
|
}
|
|||
|
|
public XmlNode GetByID(string id)
|
|||
|
|
{
|
|||
|
|
return Fill(GetXPath("*", "id", id), null);
|
|||
|
|
}
|
|||
|
|
public XmlNode GetByID(string id, XmlNode parentNode)
|
|||
|
|
{
|
|||
|
|
return Fill(GetXPath("*", "id", id), parentNode);
|
|||
|
|
}
|
|||
|
|
public XmlNode GetByName(string name)
|
|||
|
|
{
|
|||
|
|
return Fill(GetXPath("*", "name", name), null);
|
|||
|
|
}
|
|||
|
|
public XmlNode GetByName(string name, XmlNode parentNode)
|
|||
|
|
{
|
|||
|
|
return Fill(GetXPath("*", "name", name), parentNode);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public XmlNode Get(string tag, string attr, string value, XmlNode parentNode)
|
|||
|
|
{
|
|||
|
|
return Fill(GetXPath(tag, attr, value), parentNode);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public XmlNodeList GetList(string tag, string attr, string value)
|
|||
|
|
{
|
|||
|
|
return Select(GetXPath(tag, attr, value), null);
|
|||
|
|
}
|
|||
|
|
public XmlNodeList GetList(string tag, string attr, string value, XmlNode parentNode)
|
|||
|
|
{
|
|||
|
|
return Select(GetXPath(tag, attr, value), parentNode);
|
|||
|
|
}
|
|||
|
|
public XmlNodeList GetList(string tag, string attr)
|
|||
|
|
{
|
|||
|
|
return Select(GetXPath(tag, attr, null), null);
|
|||
|
|
}
|
|||
|
|
public XmlNodeList GetList(string tag, string attr, XmlNode parentNode)
|
|||
|
|
{
|
|||
|
|
return Select(GetXPath(tag, attr, null), parentNode);
|
|||
|
|
}
|
|||
|
|
public XmlNodeList GetList(string tag)
|
|||
|
|
{
|
|||
|
|
return Select(GetXPath(tag, null, null), null);
|
|||
|
|
}
|
|||
|
|
public XmlNodeList GetList(string tag, XmlNode parentNode)
|
|||
|
|
{
|
|||
|
|
return Select(GetXPath(tag, null, null), parentNode);
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
public void CreateNodeTo(XmlNode parentNode, string tag, string text, params string[] attrAndValue)
|
|||
|
|
{
|
|||
|
|
if (parentNode != null)
|
|||
|
|
{
|
|||
|
|
parentNode.AppendChild(CreateNode(tag, text, attrAndValue));
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
public XmlNode CreateNode(string tag, string text, params string[] attrAndValue)
|
|||
|
|
{
|
|||
|
|
XmlElement xElement = Create(tag);
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
xElement.InnerXml = text;
|
|||
|
|
}
|
|||
|
|
catch
|
|||
|
|
{
|
|||
|
|
xElement.InnerXml = SetCDATA(text);
|
|||
|
|
}
|
|||
|
|
if (attrAndValue != null && attrAndValue.Length % 2 == 0)
|
|||
|
|
{
|
|||
|
|
string attr = "", value = "";
|
|||
|
|
for (int i = 0; i < attrAndValue.Length; i++)
|
|||
|
|
{
|
|||
|
|
attr = attrAndValue[i];
|
|||
|
|
i++;
|
|||
|
|
value = attrAndValue[i];
|
|||
|
|
xElement.SetAttribute(attr, value);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return xElement as XmlNode;
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
public void AppendNode(XmlNode parentNode, XmlNode childNode)
|
|||
|
|
{
|
|||
|
|
if (parentNode != null && childNode != null)
|
|||
|
|
{
|
|||
|
|
parentNode.AppendChild(childNode);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD>ӽڵ<D3BD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="position">parentNode<64>ĵ<EFBFBD>N<EFBFBD><4E><EFBFBD>ӽڵ<D3BD>֮<EFBFBD><D6AE></param>
|
|||
|
|
public void AppendNode(XmlNode parentNode, XmlNode childNode, int position)
|
|||
|
|
{
|
|||
|
|
if (parentNode != null && childNode != null)// A B
|
|||
|
|
{
|
|||
|
|
if (parentNode.ChildNodes.Count == 0 || position >= parentNode.ChildNodes.Count)
|
|||
|
|
{
|
|||
|
|
parentNode.AppendChild(childNode);
|
|||
|
|
}
|
|||
|
|
else if (position == 0)
|
|||
|
|
{
|
|||
|
|
InsertBefore(childNode, parentNode.ChildNodes[0]);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
InsertAfter(childNode, parentNode.ChildNodes[position - 1]);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region ɾ<EFBFBD><EFBFBD>
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>/<2F><><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="OldNode"></param>
|
|||
|
|
public void Clear(XmlNode node)
|
|||
|
|
{
|
|||
|
|
node.RemoveAll();
|
|||
|
|
}
|
|||
|
|
public void Remove(XmlNode node)
|
|||
|
|
{
|
|||
|
|
if (node != null)
|
|||
|
|
{
|
|||
|
|
node.ParentNode.RemoveChild(node);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
public void Remove(string idOrName)
|
|||
|
|
{
|
|||
|
|
XmlNode node = Get(idOrName);
|
|||
|
|
if (node != null)
|
|||
|
|
{
|
|||
|
|
node.ParentNode.RemoveChild(node);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
public void RemoveAllChild(XmlNode node)
|
|||
|
|
{
|
|||
|
|
RemoveChild(node, 0);
|
|||
|
|
}
|
|||
|
|
public void RemoveAllChild(string idOrName)
|
|||
|
|
{
|
|||
|
|
RemoveChild(idOrName, 0);
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>Ƴ<EFBFBD><C6B3>ӽڵ<D3BD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="id"><3E>ڵ<EFBFBD><DAB5><EFBFBD>ID</param>
|
|||
|
|
/// <param name="start"><3E>ӵڼ<D3B5><DABC><EFBFBD><EFBFBD>ӽڵ㿪ʼɾ<CABC><C9BE>[<5B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0<EFBFBD><30>ʼ]</param>
|
|||
|
|
public void RemoveChild(string idOrName, int start)
|
|||
|
|
{
|
|||
|
|
XmlNode node = Get(idOrName);
|
|||
|
|
if (node != null)
|
|||
|
|
{
|
|||
|
|
RemoveChild(node, start);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>Ƴ<EFBFBD><C6B3>ӽڵ<D3BD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="node"><3E>ڵ<EFBFBD></param>
|
|||
|
|
/// <param name="start"><3E>ӵڼ<D3B5><DABC><EFBFBD><EFBFBD>ӽڵ㿪ʼɾ<CABC><C9BE>[<5B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0<EFBFBD><30>ʼ]</param>
|
|||
|
|
public void RemoveChild(XmlNode node, int start)
|
|||
|
|
{
|
|||
|
|
if (start == 0)
|
|||
|
|
{
|
|||
|
|
node.InnerXml = "";
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
if (node.ChildNodes.Count > start) //1<><31><EFBFBD>ӽڵ<D3BD>, 0
|
|||
|
|
{
|
|||
|
|
for (int i = node.ChildNodes.Count - 1; i >= start; i--)
|
|||
|
|
{
|
|||
|
|
node.RemoveChild(node.ChildNodes[i]);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="ids"></param>
|
|||
|
|
public void RemoveAttrList(params string[] attrNames)
|
|||
|
|
{
|
|||
|
|
XmlNodeList nodeList = null;
|
|||
|
|
foreach (string name in attrNames)
|
|||
|
|
{
|
|||
|
|
nodeList = GetList("*", name);
|
|||
|
|
if (nodeList != null && nodeList.Count > 0)
|
|||
|
|
{
|
|||
|
|
for (int i = 0; i < nodeList.Count; i++)
|
|||
|
|
{
|
|||
|
|
nodeList[i].Attributes.Remove(nodeList[i].Attributes[name]);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD>Ƴ<EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="attrName"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
|
|||
|
|
/// <param name="excludeSetType"><3E>ų<EFBFBD><C5B3>Ľڵ<C4BD><DAB5><EFBFBD><EFBFBD><EFBFBD></param>
|
|||
|
|
public void RemoveAttrList(string attrName, SetType excludeSetType)
|
|||
|
|
{
|
|||
|
|
XmlNodeList nodeList = GetList("*", attrName);
|
|||
|
|
if (nodeList != null && nodeList.Count > 0)
|
|||
|
|
{
|
|||
|
|
XmlNode node = null;
|
|||
|
|
string setType = excludeSetType.ToString().ToLower();
|
|||
|
|
for (int i = 0; i < nodeList.Count; i++)
|
|||
|
|
{
|
|||
|
|
node = nodeList[i];
|
|||
|
|
if (node.Name != setType)
|
|||
|
|
{
|
|||
|
|
node.Attributes.Remove(node.Attributes[attrName]);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>Ƴ<EFBFBD>ע<EFBFBD>ͽڵ<CDBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="node"><3E>Ƴ<EFBFBD><C6B3>˽ڵ<CBBD><DAB5><EFBFBD>ע<EFBFBD><D7A2><EFBFBD>ı<EFBFBD></param>
|
|||
|
|
public void RemoveCommentNode(XmlNode node)
|
|||
|
|
{
|
|||
|
|
if (node != null)
|
|||
|
|
{
|
|||
|
|
XmlNodeList xmlNodeList = Select("//comment()", node);
|
|||
|
|
|
|||
|
|
foreach (XmlNode xNode in xmlNodeList)
|
|||
|
|
{
|
|||
|
|
xNode.ParentNode.RemoveChild(xNode);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>Ƴ<EFBFBD>ע<EFBFBD>ͽڵ<CDBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public override void RemoveCommentNode()
|
|||
|
|
{
|
|||
|
|
RemoveCommentNode(XmlDoc.DocumentElement);
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>/<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD>ڵ㽻<DAB5><E3BDBB>λ<EFBFBD><CEBB>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="XNodeFirst"><3E><>һ<EFBFBD><D2BB><EFBFBD>ڵ<EFBFBD></param>
|
|||
|
|
/// <param name="XNodeLast"><3E>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD>ڵ<EFBFBD></param>
|
|||
|
|
public void InterChange(XmlNode xNodeFirst, XmlNode xNodeLast)
|
|||
|
|
{
|
|||
|
|
if (xNodeFirst != null && xNodeLast != null)
|
|||
|
|
{
|
|||
|
|
if (xNodeFirst.ParentNode != null && xNodeLast.ParentNode != null)
|
|||
|
|
{
|
|||
|
|
xNodeFirst.ParentNode.ReplaceChild(xNodeLast.Clone(), xNodeFirst);
|
|||
|
|
xNodeLast.ParentNode.ReplaceChild(xNodeFirst.Clone(), xNodeLast);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
_XmlDocument.DocumentElement.ReplaceChild(xNodeLast.Clone(), xNodeFirst);
|
|||
|
|
_XmlDocument.DocumentElement.ReplaceChild(xNodeFirst.Clone(), xNodeLast);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
public void ReplaceNode(XmlNode newNode, string oldNodeIDorName)
|
|||
|
|
{
|
|||
|
|
ReplaceNode(newNode, Get(oldNodeIDorName));
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>ڵ<EFBFBD><DAB5>滻[֧<><D6A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD>滻]
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="NewXNode"></param>
|
|||
|
|
/// <param name="OldXNode"></param>
|
|||
|
|
public void ReplaceNode(XmlNode newNode, XmlNode oldNode)
|
|||
|
|
{
|
|||
|
|
if (newNode != null && oldNode != null)
|
|||
|
|
{
|
|||
|
|
if (newNode.Name == oldNode.Name) // <20>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC>
|
|||
|
|
{
|
|||
|
|
oldNode.RemoveAll();//<2F><><EFBFBD>վɽڵ<C9BD>
|
|||
|
|
oldNode.InnerXml = newNode.InnerXml;
|
|||
|
|
XmlAttributeCollection attrs = newNode.Attributes;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
if (attrs != null && attrs.Count > 0)
|
|||
|
|
{
|
|||
|
|
for (int i = 0; i < attrs.Count; i++)
|
|||
|
|
{
|
|||
|
|
((XmlElement)oldNode).SetAttribute(attrs[i].Name, attrs[i].Value);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
XmlNode xNode = CreateNode(newNode.Name, newNode.InnerXml);//<2F>ȴ<EFBFBD><C8B4><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ڵ㡣
|
|||
|
|
XmlAttributeCollection attrs = newNode.Attributes;
|
|||
|
|
if (attrs != null && attrs.Count > 0)
|
|||
|
|
{
|
|||
|
|
for (int i = 0; i < attrs.Count; i++)
|
|||
|
|
{
|
|||
|
|
((XmlElement)xNode).SetAttribute(attrs[i].Name, attrs[i].Value);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
oldNode.ParentNode.InsertAfter(xNode, oldNode);//<2F><><EFBFBD>ھɽڵ<C9BD><DAB5><EFBFBD><EFBFBD>档
|
|||
|
|
Remove(oldNode);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>ڵ<EFBFBD>֮<EFBFBD><D6AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[֧<><D6A7><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>֮<EFBFBD><D6AE><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD>]
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="NewNode">Ҫ<><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>½ڵ<C2BD></param>
|
|||
|
|
/// <param name="RefNode"><3E>ڴ˽ڵ<CBBD><DAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>NewNode<64>ڵ<EFBFBD></param>
|
|||
|
|
public void InsertAfter(XmlNode newNode, XmlNode refNode)
|
|||
|
|
{
|
|||
|
|
XmlNode xDocNode = CreateNode(newNode.Name, "");
|
|||
|
|
ReplaceNode(newNode, xDocNode);
|
|||
|
|
refNode.ParentNode.InsertAfter(xDocNode, refNode);
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>ڵ<EFBFBD>֮ǰ<D6AE><C7B0><EFBFBD><EFBFBD>[֧<><D6A7><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>֮<EFBFBD><D6AE><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD>]
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="NewNode">Ҫ<><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>½ڵ<C2BD></param>
|
|||
|
|
/// <param name="RefNode"><3E>ڴ˽ڵ<CBBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>NewNode<64>ڵ<EFBFBD></param>
|
|||
|
|
public void InsertBefore(XmlNode newNode, XmlNode refNode)
|
|||
|
|
{
|
|||
|
|
XmlNode xDocNode = CreateNode(newNode.Name, "");
|
|||
|
|
ReplaceNode(newNode, xDocNode);
|
|||
|
|
refNode.ParentNode.InsertBefore(xDocNode, refNode);
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region <EFBFBD>ڵ<EFBFBD><EFBFBD>ж<EFBFBD>
|
|||
|
|
public bool Contains(string idOrName)
|
|||
|
|
{
|
|||
|
|
return Get(idOrName) != null;
|
|||
|
|
}
|
|||
|
|
public bool Contains(string idOrName, XmlNode parentNode)
|
|||
|
|
{
|
|||
|
|
return Get(idOrName, parentNode) != null;
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>/ȡֵ
|
|||
|
|
|
|||
|
|
public bool HasAttr(string idOrName, string attrName)
|
|||
|
|
{
|
|||
|
|
return GetAttrValue(idOrName, attrName) != string.Empty;
|
|||
|
|
}
|
|||
|
|
public bool HasAttr(XmlNode node, string attrName)
|
|||
|
|
{
|
|||
|
|
return GetAttrValue(node, attrName) != string.Empty;
|
|||
|
|
}
|
|||
|
|
public string GetAttrValue(string idOrName, string attrName, params string[] defaultValue)
|
|||
|
|
{
|
|||
|
|
XmlNode node = Get(idOrName);
|
|||
|
|
return GetAttrValue(node, attrName, defaultValue);
|
|||
|
|
}
|
|||
|
|
public string GetAttrValue(XmlNode node, string attrName, params string[] defaultValue)
|
|||
|
|
{
|
|||
|
|
if (node != null)
|
|||
|
|
{
|
|||
|
|
switch (attrName)
|
|||
|
|
{
|
|||
|
|
case "InnerText":
|
|||
|
|
if (!string.IsNullOrEmpty(node.InnerText))
|
|||
|
|
{
|
|||
|
|
return node.InnerText;
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
case "InnerXml":
|
|||
|
|
if (!string.IsNullOrEmpty(node.InnerXml))
|
|||
|
|
{
|
|||
|
|
return node.InnerXml;
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
default:
|
|||
|
|
if (node.Attributes != null && node.Attributes[attrName] != null)
|
|||
|
|
{
|
|||
|
|
return node.Attributes[attrName].Value;
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
if (defaultValue.Length > 0)
|
|||
|
|
{
|
|||
|
|
return defaultValue[0];
|
|||
|
|
}
|
|||
|
|
return string.Empty;
|
|||
|
|
}
|
|||
|
|
public void RemoveAttr(string idOrName, params string[] attrNames)
|
|||
|
|
{
|
|||
|
|
XmlNode node = Get(idOrName);
|
|||
|
|
RemoveAttr(node, attrNames);
|
|||
|
|
}
|
|||
|
|
public void RemoveAttr(XmlNode node, params string[] attrNames)
|
|||
|
|
{
|
|||
|
|
if (node != null && node.Attributes != null)
|
|||
|
|
{
|
|||
|
|
foreach (string name in attrNames)
|
|||
|
|
{
|
|||
|
|
if (node.Attributes[name] != null)
|
|||
|
|
{
|
|||
|
|
node.Attributes.Remove(node.Attributes[name]);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|
|||
|
|
private bool _IsCurrentLang = true;
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>û<EFBFBD><C3BB><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public bool IsCurrentLang
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
return _IsCurrentLang;
|
|||
|
|
}
|
|||
|
|
set
|
|||
|
|
{
|
|||
|
|
_IsCurrentLang = value;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>Ƿ<EFBFBD><C7B7><EFBFBD>ʼ<EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Էָ<D4B7>(<28>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>[#langsplit])
|
|||
|
|
/// </summary>
|
|||
|
|
public bool IsUseLangSplit = true;
|
|||
|
|
|
|||
|
|
private string SetValue(string sourceValue, string newValue, bool addCData)
|
|||
|
|
{
|
|||
|
|
if (string.IsNullOrEmpty(newValue))
|
|||
|
|
{
|
|||
|
|
return sourceValue;
|
|||
|
|
}
|
|||
|
|
newValue = newValue.Replace(ValueReplace.Source, sourceValue);
|
|||
|
|
if (IsUseLangSplit)
|
|||
|
|
{
|
|||
|
|
int split = newValue.IndexOf(ValueReplace.LangSplit);
|
|||
|
|
if (split > -1)
|
|||
|
|
{
|
|||
|
|
newValue = _IsCurrentLang ? newValue.Substring(0, split) : newValue.Substring(split + ValueReplace.LangSplit.Length);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
if (addCData)
|
|||
|
|
{
|
|||
|
|
newValue = SetCDATA(newValue);
|
|||
|
|
}
|
|||
|
|
return newValue;
|
|||
|
|
}
|
|||
|
|
private void SetAttrValue(XmlNode node, string key, string value)
|
|||
|
|
{
|
|||
|
|
if (node == null || node.Attributes == null)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
if (node.Attributes[key] == null)
|
|||
|
|
{
|
|||
|
|
XmlAttribute attr = _XmlDocument.CreateAttribute(key);
|
|||
|
|
node.Attributes.Append(attr);
|
|||
|
|
}
|
|||
|
|
value = SetValue(node.Attributes[key].InnerXml, value, false);
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
node.Attributes[key].Value = value;
|
|||
|
|
}
|
|||
|
|
catch
|
|||
|
|
{
|
|||
|
|
node.Attributes[key].Value = SetCDATA(value);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// Ϊ<>ڵ㸳ֵ[ͨ<><CDA8>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>values<65>и<EFBFBD>ֵ]
|
|||
|
|
/// </summary>
|
|||
|
|
public void Set(XmlNode node, SetType setType, params string[] values)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
if (node != null && values != null)
|
|||
|
|
{
|
|||
|
|
switch (setType)
|
|||
|
|
{
|
|||
|
|
case SetType.InnerText:
|
|||
|
|
string value = SetValue(node.InnerText, values[0], false);
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
node.InnerText = value;
|
|||
|
|
}
|
|||
|
|
catch
|
|||
|
|
{
|
|||
|
|
node.InnerText = SetCDATA(value);
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
case SetType.InnerXml:
|
|||
|
|
node.InnerXml = SetValue(node.InnerXml, values[0], true);
|
|||
|
|
break;
|
|||
|
|
case SetType.Value:
|
|||
|
|
case SetType.Href:
|
|||
|
|
case SetType.Src:
|
|||
|
|
case SetType.Class:
|
|||
|
|
case SetType.Disabled:
|
|||
|
|
case SetType.ID:
|
|||
|
|
case SetType.Name:
|
|||
|
|
case SetType.Visible:
|
|||
|
|
case SetType.Title:
|
|||
|
|
case SetType.Style:
|
|||
|
|
string key = setType.ToString().ToLower();
|
|||
|
|
SetAttrValue(node, key, values[0]);
|
|||
|
|
break;
|
|||
|
|
case SetType.Custom:
|
|||
|
|
for (int i = 0; i < values.Length; i++)
|
|||
|
|
{
|
|||
|
|
if (i > 0 && i % 2 == 1)
|
|||
|
|
{
|
|||
|
|
key = values[i - 1].ToLower();
|
|||
|
|
switch (key)
|
|||
|
|
{
|
|||
|
|
case "innertext":
|
|||
|
|
Set(node, SetType.InnerText, values[i]);
|
|||
|
|
break;
|
|||
|
|
case "innerhtml":
|
|||
|
|
case "innerxml":
|
|||
|
|
Set(node, SetType.InnerXml, values[i]);
|
|||
|
|
break;
|
|||
|
|
default:
|
|||
|
|
SetAttrValue(node, key, values[i]);
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
break;
|
|||
|
|
case SetType.A:
|
|||
|
|
node.InnerXml = SetValue(node.InnerXml, values[0], true);
|
|||
|
|
if (values.Length > 1)
|
|||
|
|
{
|
|||
|
|
SetAttrValue(node, "href", values[1]);
|
|||
|
|
if (values.Length > 2)
|
|||
|
|
{
|
|||
|
|
SetAttrValue(node, "title", values[2]);
|
|||
|
|
if (values.Length > 3)
|
|||
|
|
{
|
|||
|
|
SetAttrValue(node, "target", values[3]);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
case SetType.Select:
|
|||
|
|
if (node.InnerXml.Contains(AppConfig.XHtml.CDataLeft))//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>
|
|||
|
|
{
|
|||
|
|
string innerHtml = node.InnerXml.Replace(string.Format("value=\"{0}\"", values[0]), string.Format("selected=\"selected\" value=\"{0}\"", values[0]));
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
node.InnerXml = innerHtml;
|
|||
|
|
}
|
|||
|
|
catch
|
|||
|
|
{
|
|||
|
|
node.InnerXml = SetCDATA(innerHtml);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
foreach (XmlNode option in node.ChildNodes)
|
|||
|
|
{
|
|||
|
|
if (option.Attributes["value"] != null && (option.Attributes["value"].Value == values[0] || option.Attributes["value"].Value.Split(',')[0] == values[0]))
|
|||
|
|
{
|
|||
|
|
SetAttrValue(option, "selected", "selected");
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
case SetType.Checked:
|
|||
|
|
if (node.Name == "input" && node.Attributes["type"].Value == "radio")
|
|||
|
|
{
|
|||
|
|
values[0] = "1";
|
|||
|
|
}
|
|||
|
|
switch (values[0].ToLower())
|
|||
|
|
{
|
|||
|
|
case "1":
|
|||
|
|
case "true":
|
|||
|
|
case "check":
|
|||
|
|
case "checked":
|
|||
|
|
key = setType.ToString().ToLower();
|
|||
|
|
SetAttrValue(node, key, key);
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
public void Set(string idOrName, SetType setType, params string[] values)
|
|||
|
|
{
|
|||
|
|
Set(null, idOrName, setType, values);
|
|||
|
|
}
|
|||
|
|
public void Set(XmlNode parentNode, string idOrName, SetType setType, params string[] values)
|
|||
|
|
{
|
|||
|
|
XmlNode node = Get(idOrName, parentNode);
|
|||
|
|
Set(node, setType, values);
|
|||
|
|
}
|
|||
|
|
public void Set(string idOrName, string value)
|
|||
|
|
{
|
|||
|
|
Set(null, idOrName, value);
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>Խڵ㸳ֵ<E3B8B3><D6B5><EFBFBD>˷<EFBFBD><CBB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>hidden<65><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ؽڵ㸳ֵ<E3B8B3><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ط<EFBFBD><D8B7><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="idOrName"></param>
|
|||
|
|
/// <param name="value"></param>
|
|||
|
|
public void Set(XmlNode parentNode, string idOrName, string value)
|
|||
|
|
{
|
|||
|
|
XmlNode node = Get(idOrName, parentNode);
|
|||
|
|
if (node != null)
|
|||
|
|
{
|
|||
|
|
SetType setType = SetType.InnerXml;
|
|||
|
|
switch (node.Name)
|
|||
|
|
{
|
|||
|
|
case "input":
|
|||
|
|
switch (GetAttrValue(node, "type"))
|
|||
|
|
{
|
|||
|
|
case "hidden":
|
|||
|
|
return;//<2F>˷<EFBFBD><CBB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
case "checkbox":
|
|||
|
|
setType = SetType.Checked; break;
|
|||
|
|
case "image":
|
|||
|
|
setType = SetType.Src; break;
|
|||
|
|
case "radio"://<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
|
|||
|
|
XmlNodeList nodeList = GetList("input", "type", "radio");
|
|||
|
|
for (int i = 0; i < nodeList.Count; i++)
|
|||
|
|
{
|
|||
|
|
if (GetAttrValue(nodeList[i], "name") == idOrName)
|
|||
|
|
{
|
|||
|
|
RemoveAttr(nodeList[i], "checked");
|
|||
|
|
if (GetAttrValue(nodeList[i], "value") == value)
|
|||
|
|
{
|
|||
|
|
node = nodeList[i];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
setType = SetType.Checked; break;
|
|||
|
|
default:
|
|||
|
|
setType = SetType.Value;
|
|||
|
|
break;
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
case "select":
|
|||
|
|
setType = SetType.Select; break;
|
|||
|
|
case "a":
|
|||
|
|
setType = SetType.Href; break;
|
|||
|
|
case "img":
|
|||
|
|
setType = SetType.Src; break;
|
|||
|
|
}
|
|||
|
|
//try
|
|||
|
|
//{
|
|||
|
|
Set(node, setType, value);
|
|||
|
|
//}
|
|||
|
|
//catch (Exception err)
|
|||
|
|
//{
|
|||
|
|
|
|||
|
|
// throw;
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region <EFBFBD><EFBFBD>д<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>OutXml
|
|||
|
|
public override string OutXml
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
if (_XmlDocument != null)
|
|||
|
|
{
|
|||
|
|
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD>clearflag<EFBFBD><EFBFBD>ǩ
|
|||
|
|
string key = "clearflag";
|
|||
|
|
XmlNodeList xnl = GetList("*", key);
|
|||
|
|
if (xnl != null)
|
|||
|
|
{
|
|||
|
|
XmlNode xNode = null;
|
|||
|
|
for (int i = xnl.Count - 1; i >= 0; i--)
|
|||
|
|
{
|
|||
|
|
xNode = xnl[i];
|
|||
|
|
switch (GetAttrValue(xnl[i], key))
|
|||
|
|
{
|
|||
|
|
case "0":
|
|||
|
|
RemoveAttr(xNode, key);
|
|||
|
|
xNode.InnerXml = "";
|
|||
|
|
break;
|
|||
|
|
case "1":
|
|||
|
|
Remove(xNode);
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
string xml = _XmlDocument.InnerXml.Replace(".dtd\"[]>", ".dtd\">");
|
|||
|
|
if (xml.IndexOf(" xmlns=") > -1)
|
|||
|
|
{
|
|||
|
|
xml = xml.Replace(" xmlns=\"\"", string.Empty).Replace(" xmlns=\"" + xnm.LookupNamespace(PreXml) + "\"", string.Empty);
|
|||
|
|
}
|
|||
|
|
string html = ClearCDATA(xml);
|
|||
|
|
if (!string.IsNullOrEmpty(docTypeHtml))
|
|||
|
|
{
|
|||
|
|
html = html.Replace(docTypeHtml, "<!DOCTYPE html>");
|
|||
|
|
}
|
|||
|
|
html = html.Replace(">", ">").Replace("<", "<").Replace("&", "&");//html<6D><6C>ǩ<EFBFBD><C7A9><EFBFBD>š<EFBFBD>
|
|||
|
|
if (dicForAutoSetValue != null && dicForAutoSetValue.Count > 0 && html.Contains("${")) // <20>滻<EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>ǩ<EFBFBD><C7A9>
|
|||
|
|
{
|
|||
|
|
#region <EFBFBD>滻<EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǩ
|
|||
|
|
MatchCollection matchs = Regex.Matches(html, @"\$\{([\S\s]*?)\}", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
|||
|
|
if (matchs != null && matchs.Count > 0)
|
|||
|
|
{
|
|||
|
|
List<string> keys = new List<string>(matchs.Count);
|
|||
|
|
foreach (Match match in matchs)
|
|||
|
|
{
|
|||
|
|
string value = match.Groups[0].Value;
|
|||
|
|
if (!keys.Contains(value))
|
|||
|
|
{
|
|||
|
|
keys.Add(value);
|
|||
|
|
string[] items = match.Groups[1].Value.Trim().Split('#', '-');
|
|||
|
|
string pre = items.Length > 1 ? items[0] : "";
|
|||
|
|
string columnName = items.Length > 1 ? items[1] : items[0];
|
|||
|
|
if (dicForAutoSetValue.ContainsKey(pre))
|
|||
|
|
{
|
|||
|
|
MDataCell matchCell = dicForAutoSetValue[pre][columnName];
|
|||
|
|
if (matchCell != null)
|
|||
|
|
{
|
|||
|
|
html = html.Replace(value, matchCell.ToString());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
keys.Clear();
|
|||
|
|
keys = null;
|
|||
|
|
}
|
|||
|
|
dicForAutoSetValue.Clear();
|
|||
|
|
dicForAutoSetValue = null;
|
|||
|
|
matchs = null;
|
|||
|
|
#endregion
|
|||
|
|
}
|
|||
|
|
return html;
|
|||
|
|
}
|
|||
|
|
return string.Empty;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//<2F><>չ<EFBFBD><D5B9><EFBFBD><EFBFBD>
|
|||
|
|
public partial class XHtmlAction
|
|||
|
|
{
|
|||
|
|
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
MDataRow _Row;
|
|||
|
|
MDataTable _Table;
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
#region <EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD>MDataTable<6C>Ķ<EFBFBD><C4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="data"></param>
|
|||
|
|
public void LoadData(object anyObjToTable)
|
|||
|
|
{
|
|||
|
|
LoadData(MDataTable.CreateFrom(anyObjToTable));
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// װ<><D7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>SetForeach<63><68><EFBFBD><EFBFBD>ʹ<EFBFBD>ã<EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public void LoadData(MDataTable table)
|
|||
|
|
{
|
|||
|
|
_Table = table;
|
|||
|
|
if (_Table.Rows.Count > 0)
|
|||
|
|
{
|
|||
|
|
_Row = _Table.Rows[0];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
public delegate string SetForeachEventHandler(string text, MDictionary<string, string> values, int rowIndex);
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD>SetForeach<63><68><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õĸ<C3B5>ʽ<EFBFBD><CABD><EFBFBD>¼<EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public event SetForeachEventHandler OnForeach;
|
|||
|
|
public void SetForeach()
|
|||
|
|
{
|
|||
|
|
if (_Table != null)
|
|||
|
|
{
|
|||
|
|
XmlNode node = Get(_Table.TableName + "View");
|
|||
|
|
if (node == null)
|
|||
|
|
{
|
|||
|
|
node = Get("defaultView");
|
|||
|
|
}
|
|||
|
|
if (node != null)
|
|||
|
|
{
|
|||
|
|
SetForeach(node, node.InnerXml);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
public void SetForeach(string idOrName, SetType setType, params object[] formatValues)
|
|||
|
|
{
|
|||
|
|
string text = string.Empty;
|
|||
|
|
XmlNode node = Get(idOrName);
|
|||
|
|
if (node == null)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
switch (setType)
|
|||
|
|
{
|
|||
|
|
case SetType.InnerText:
|
|||
|
|
text = node.InnerText;
|
|||
|
|
break;
|
|||
|
|
case SetType.InnerXml:
|
|||
|
|
text = node.InnerXml;
|
|||
|
|
break;
|
|||
|
|
case SetType.Value:
|
|||
|
|
case SetType.Href:
|
|||
|
|
case SetType.Src:
|
|||
|
|
case SetType.Class:
|
|||
|
|
case SetType.Disabled:
|
|||
|
|
case SetType.ID:
|
|||
|
|
case SetType.Name:
|
|||
|
|
case SetType.Visible:
|
|||
|
|
case SetType.Title:
|
|||
|
|
case SetType.Style:
|
|||
|
|
string key = setType.ToString().ToLower();
|
|||
|
|
if (node.Attributes[key] != null)
|
|||
|
|
{
|
|||
|
|
text = node.Attributes[key].Value;
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
SetForeach(node, text, formatValues);
|
|||
|
|
}
|
|||
|
|
public void SetForeach(string idOrName, string text, params object[] formatValues)
|
|||
|
|
{
|
|||
|
|
XmlNode node = Get(idOrName);
|
|||
|
|
SetForeach(node, text, formatValues);
|
|||
|
|
}
|
|||
|
|
public void SetForeach(XmlNode node, string text, params object[] formatValues)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
|||
|
|
if (node == null || _Table == null || _Table.Rows.Count == 0) { return; }
|
|||
|
|
RemoveAttr(node, "clearflag");
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
int fvLen = formatValues.Length;
|
|||
|
|
int colLen = _Table.Columns.Count;
|
|||
|
|
StringBuilder innerXml = new StringBuilder();
|
|||
|
|
if (string.IsNullOrEmpty(text))
|
|||
|
|
{
|
|||
|
|
if (node.Name == "select")
|
|||
|
|
{
|
|||
|
|
text = "<option value=\"{0}\">{1}</option>";
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ
|
|||
|
|
for (int i = 0; i < colLen; i++)
|
|||
|
|
{
|
|||
|
|
if (i == 0)
|
|||
|
|
{
|
|||
|
|
innerXml.Append(_Table.Columns[i].ColumnName);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
innerXml.Append(" - " + _Table.Columns[i].ColumnName);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
innerXml.Append("<hr />");
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region <EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><EFBFBD><EFBFBD>Ĭ<EFBFBD>ϲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Table<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
StringBuilder sb = new StringBuilder();
|
|||
|
|
int min = fvLen == 0 ? colLen : Math.Min(fvLen, colLen);
|
|||
|
|
for (int i = 0; i < min; i++)
|
|||
|
|
{
|
|||
|
|
if (i == 0)
|
|||
|
|
{
|
|||
|
|
sb.Append("{0}");
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
sb.Append(" - {" + i + "}");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
sb.Append("<hr />");
|
|||
|
|
text = sb.ToString();
|
|||
|
|
#endregion
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
if (fvLen == 0)
|
|||
|
|
{
|
|||
|
|
formatValues = new object[colLen];
|
|||
|
|
}
|
|||
|
|
MDictionary<string, string> values = new MDictionary<string, string>(formatValues.Length, StringComparer.OrdinalIgnoreCase);
|
|||
|
|
// object[] values = new object[formatValues.Length];//<2F><><EFBFBD>ڸ<EFBFBD>ʽ<EFBFBD><CABD>{0}<7D><>{1}<7D><>ռλ<D5BC><CEBB>
|
|||
|
|
|
|||
|
|
//foreach (MDataRow row in _Table.Rows)
|
|||
|
|
string newText = text;
|
|||
|
|
MDataCell cell;
|
|||
|
|
for (int k = 0; k < _Table.Rows.Count; k++)
|
|||
|
|
{
|
|||
|
|
for (int i = 0; i < formatValues.Length; i++)
|
|||
|
|
{
|
|||
|
|
#region <EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>а<EFBFBD>ֵ<EFBFBD>ŵ<EFBFBD>values<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
if (formatValues[i] == null)
|
|||
|
|
{
|
|||
|
|
formatValues[i] = i;
|
|||
|
|
}
|
|||
|
|
cell = _Table.Rows[k][formatValues[i].ToString()];
|
|||
|
|
if (cell == null && string.Compare(formatValues[i].ToString(), "row", true) == 0) // <20><><EFBFBD><EFBFBD><EFBFBD>Ժ<EFBFBD><D4BA><EFBFBD><EFBFBD>Լ<EFBFBD>Ҳû<D2B2><C3BB><EFBFBD><EFBFBD><EFBFBD>Ƚ<EFBFBD>row<6F><77>Ϊ<EFBFBD><CEAA>ʲô
|
|||
|
|
{
|
|||
|
|
values.Add(formatValues[i].ToString(), (k + 1).ToString());
|
|||
|
|
//values[i] = k + 1;//Ҳû<D2B2><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊɶֵ<C9B6><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD>ҿ<EFBFBD><D2BF><EFBFBD><EFBFBD>ѵ<EFBFBD><D1B5><EFBFBD><EFBFBD>кţ<D0BA><C5A3><EFBFBD><EFBFBD><EFBFBD>¥<EFBFBD><C2A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>书<EFBFBD>ܣ<EFBFBD>
|
|||
|
|
}
|
|||
|
|
else if (cell != null)
|
|||
|
|
{
|
|||
|
|
values.Add(cell.ColumnName, cell.StringValue);
|
|||
|
|
//values[i] = cell.Value;
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
}
|
|||
|
|
if (OnForeach != null)
|
|||
|
|
{
|
|||
|
|
newText = OnForeach(text, values, k);//<2F><><EFBFBD><EFBFBD>ÿһ<C3BF>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>text<78><74>
|
|||
|
|
}
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
string tempText = newText;
|
|||
|
|
int j = 0;
|
|||
|
|
foreach (KeyValuePair<string, string> kv in values)
|
|||
|
|
{
|
|||
|
|
tempText = tempText.Replace("{" + j + "}", kv.Value);//<2F><>ʽ<EFBFBD><CABD>{0}<7D><>{1}<7D><>ռλ<D5BC><CEBB>
|
|||
|
|
j++;
|
|||
|
|
}
|
|||
|
|
//for (int j = 0; j < values.Length; j++)
|
|||
|
|
//{
|
|||
|
|
// tempText = tempText.Replace("{" + j + "}", Convert.ToString(values[j]));//<2F><>ʽ<EFBFBD><CABD>{0}<7D><>{1}<7D><>ռλ<D5BC><CEBB>
|
|||
|
|
//}
|
|||
|
|
if (tempText.Contains("${"))
|
|||
|
|
{
|
|||
|
|
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǩռλ<EFBFBD><EFBFBD>
|
|||
|
|
MatchCollection matchs = Regex.Matches(tempText, @"\$\{([\S\s]*?)\}", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
|||
|
|
if (matchs != null && matchs.Count > 0)
|
|||
|
|
{
|
|||
|
|
MDataCell matchCell = null;
|
|||
|
|
string columnName = null, value = null;
|
|||
|
|
List<string> keys = new List<string>(matchs.Count);
|
|||
|
|
foreach (Match match in matchs)
|
|||
|
|
{
|
|||
|
|
value = match.Groups[0].Value;
|
|||
|
|
columnName = match.Groups[1].Value.Trim();
|
|||
|
|
if (!keys.Contains(value))
|
|||
|
|
{
|
|||
|
|
keys.Add(value);
|
|||
|
|
if (value.Contains(columnName))//ֵ<><D6B5><EFBFBD>ܱ<EFBFBD><DCB1><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡֵ<C8A1><D6B5>
|
|||
|
|
{
|
|||
|
|
tempText = tempText.Replace(value, values[columnName]);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
matchCell = _Table.Rows[k][columnName];
|
|||
|
|
if (matchCell != null)
|
|||
|
|
{
|
|||
|
|
tempText = tempText.Replace(value, matchCell.ToString());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
keys.Clear();
|
|||
|
|
keys = null;
|
|||
|
|
}
|
|||
|
|
matchs = null;
|
|||
|
|
#endregion
|
|||
|
|
}
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>${}<7D>
|
|||
|
|
innerXml.Append(tempText);
|
|||
|
|
// innerXml += tempText;//string.Format(newText, values);
|
|||
|
|
}
|
|||
|
|
catch (Exception err)
|
|||
|
|
{
|
|||
|
|
Log.WriteLogToTxt(err);
|
|||
|
|
}
|
|||
|
|
finally
|
|||
|
|
{
|
|||
|
|
values.Clear();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
node.InnerXml = innerXml.ToString();
|
|||
|
|
}
|
|||
|
|
catch
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
node.InnerXml = SetCDATA(innerXml.ToString());
|
|||
|
|
}
|
|||
|
|
catch (Exception err)
|
|||
|
|
{
|
|||
|
|
Log.WriteLogToTxt(err);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
finally
|
|||
|
|
{
|
|||
|
|
if (OnForeach != null)
|
|||
|
|
{
|
|||
|
|
OnForeach = null;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݺ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD>MDatarow<6F><77><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>CMS<4D>滻<EFBFBD><E6BBBB>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="autoSetValuePre"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>ǰ<C7B0><D7BA><EFBFBD>磺"txt#",<2C><><EFBFBD><EFBFBD>ǰ<C7B0><D7BA>""<22><><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><F3A3ACBD>ڻ<EFBFBD>ȡOutXml<6D><6C><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ</param>
|
|||
|
|
public void LoadData(object anyObjToRow, string autoSetValuePre)
|
|||
|
|
{
|
|||
|
|
LoadData(MDataRow.CreateFrom(anyObjToRow), autoSetValuePre);
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// װ<><D7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>SetFor<6F><72><EFBFBD><EFBFBD>ʹ<EFBFBD>û<EFBFBD>CMS<4D>滻<EFBFBD><E6BBBB>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="autoSetValuePre"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>ǰ<C7B0><D7BA><EFBFBD>磺"txt#",<2C><><EFBFBD><EFBFBD>ǰ<C7B0><D7BA>""<22><><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><F3A3ACBD>ڻ<EFBFBD>ȡOutXml<6D><6C><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ</param>
|
|||
|
|
public void LoadData(MDataRow row, string autoSetValuePre)
|
|||
|
|
{
|
|||
|
|
if (autoSetValuePre != null)
|
|||
|
|
{
|
|||
|
|
autoSetValuePre = autoSetValuePre.TrimEnd('#', '-');
|
|||
|
|
if (dicForAutoSetValue == null)
|
|||
|
|
{
|
|||
|
|
dicForAutoSetValue = new Dictionary<string, MDataRow>(6);
|
|||
|
|
}
|
|||
|
|
if (!dicForAutoSetValue.ContainsKey(autoSetValuePre))
|
|||
|
|
{
|
|||
|
|
dicForAutoSetValue.Add(autoSetValuePre, row);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
_Row = row;
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// װ<><D7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>SetFor<6F><72><EFBFBD><EFBFBD>ʹ<EFBFBD>ã<EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="row"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
|
|||
|
|
public void LoadData(MDataRow row)
|
|||
|
|
{
|
|||
|
|
_Row = row;
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// Ϊ<>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD>LoadData<74><61>ʹ<EFBFBD>á<EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="id"><3E>ڵ<EFBFBD><DAB5><EFBFBD>ID</param>
|
|||
|
|
public void SetFor(string idOrName)
|
|||
|
|
{
|
|||
|
|
SetFor(idOrName, SetType.InnerXml);
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// Ϊ<>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD>LoadData<74><61>ʹ<EFBFBD>á<EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="setType"><3E>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
|
|||
|
|
public void SetFor(string idOrName, SetType setType)
|
|||
|
|
{
|
|||
|
|
SetFor(idOrName, setType, GetRowValue(idOrName));
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// Ϊ<>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD>LoadData<74><61>ʹ<EFBFBD>á<EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="values">setTypeΪCustomʱ<6D><CAB1><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD>硰"href","http://www.cyqdata.com","target","_blank"<22><></param>
|
|||
|
|
public void SetFor(string idOrName, SetType setType, params string[] values)
|
|||
|
|
{
|
|||
|
|
int i = setType == SetType.Custom ? 1 : 0;
|
|||
|
|
for (; i < values.Length; i++)
|
|||
|
|
{
|
|||
|
|
if (values[i].Contains(ValueReplace.New))
|
|||
|
|
{
|
|||
|
|
values[i] = values[i].Replace(ValueReplace.New, GetRowValue(idOrName));
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
Set(Get(idOrName), setType, values);
|
|||
|
|
}
|
|||
|
|
private string GetRowValue(string idOrName)
|
|||
|
|
{
|
|||
|
|
string rowValue = "";
|
|||
|
|
if (_Row != null)
|
|||
|
|
{
|
|||
|
|
MDataCell cell = _Row[idOrName];
|
|||
|
|
if (cell == null && idOrName.Length > 3)
|
|||
|
|
{
|
|||
|
|
cell = _Row[idOrName.Substring(3)];
|
|||
|
|
}
|
|||
|
|
if (cell != null)
|
|||
|
|
{
|
|||
|
|
rowValue = cell.IsNull ? "" : cell.StringValue;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return rowValue;
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region תJson
|
|||
|
|
/// <summary>
|
|||
|
|
/// תJson
|
|||
|
|
/// </summary>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public string ToJson()
|
|||
|
|
{
|
|||
|
|
return ToJson(XmlDoc.DocumentElement, true);
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// תJson
|
|||
|
|
/// <param name="parent"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ڵ㣨Ĭ<E3A3A8>ϸ<EFBFBD><CFB8>ڵ㣩</param>
|
|||
|
|
/// <param name="isWithAttr"><3E>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵҲ<D6B5><D2B2><EFBFBD><EFBFBD></param>
|
|||
|
|
/// </summary>
|
|||
|
|
public string ToJson(XmlNode parent, bool isWithAttr)
|
|||
|
|
{
|
|||
|
|
parent = parent ?? XmlDoc.DocumentElement;
|
|||
|
|
if (parent == null)
|
|||
|
|
{
|
|||
|
|
return string.Empty;
|
|||
|
|
}
|
|||
|
|
JsonHelper js = new JsonHelper(false, false);
|
|||
|
|
js.Add(parent.Name, GetChildJson(parent, isWithAttr), true);
|
|||
|
|
js.AddBr();
|
|||
|
|
return js.ToString();
|
|||
|
|
}
|
|||
|
|
private string GetChildJson(XmlNode parent, bool isWithAttr)
|
|||
|
|
{
|
|||
|
|
JsonHelper js = new JsonHelper(false, false);
|
|||
|
|
if (isWithAttr && parent.Attributes != null && parent.Attributes.Count > 0)
|
|||
|
|
{
|
|||
|
|
foreach (XmlAttribute item in parent.Attributes)
|
|||
|
|
{
|
|||
|
|
js.Add(item.Name, item.Value);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
if (parent.HasChildNodes)
|
|||
|
|
{
|
|||
|
|
XmlNode x0 = parent.ChildNodes[0];
|
|||
|
|
int childCount = parent.ChildNodes.Count;
|
|||
|
|
if (x0.NodeType != XmlNodeType.Element && childCount == 1)
|
|||
|
|
{
|
|||
|
|
js.Add(parent.Name, parent.InnerText);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
Dictionary<string, string> jsonDic = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
|||
|
|
foreach (XmlNode item in parent.ChildNodes)
|
|||
|
|
{
|
|||
|
|
string childJson = GetChildJson(item, isWithAttr);
|
|||
|
|
if (!jsonDic.ContainsKey(item.Name))
|
|||
|
|
{
|
|||
|
|
jsonDic.Add(item.Name, childJson);
|
|||
|
|
}
|
|||
|
|
else // <20>ظ<EFBFBD><D8B8><EFBFBD>TagName
|
|||
|
|
{
|
|||
|
|
jsonDic[item.Name] = "[" + jsonDic[item.Name].TrimStart('[').TrimEnd(']') + "," + childJson + "]";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
foreach (KeyValuePair<string, string> kv in jsonDic)
|
|||
|
|
{
|
|||
|
|
js.Add(kv.Key, kv.Value, true);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
js.AddBr();
|
|||
|
|
return js.ToString();
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|