本文整理汇总了C#中System.Xml.XmlDocument.CreateNavigator方法的典型用法代码示例。如果您正苦于以下问题:C# System.Xml.XmlDocument.CreateNavigator方法的具体用法?C# System.Xml.XmlDocument.CreateNavigator怎么用?C# System.Xml.XmlDocument.CreateNavigator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlDocument
的用法示例。
在下文中一共展示了System.Xml.XmlDocument.CreateNavigator方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreatePagination
public string CreatePagination(int CurrentPage, int PageSize, int DataCount, int PageCount)
{
if (_type != PageDataType.DataTable && _type != PageDataType.Xml) {
throw new Exception("only DataTable or XPathDocument can be create pagination");
}
_pagination = string.Empty;
if (PageCount % 2 == 0) { throw new Exception("PageCount should just odd"); }
int PageMax = Convert.ToInt32(Math.Ceiling(Convert.ToDecimal(DataCount) / Convert.ToDecimal(PageSize)));
int PageIndex = CurrentPage + 1;
StringBuilder _tempsb = new StringBuilder();
int pagestart = PageIndex - Convert.ToInt32(Math.Floor(PageCount / 2f));
int pageend = PageIndex + Convert.ToInt32(Math.Floor(PageCount / 2f));
if (PageMax < 0) {
throw new Exception("PageMax less the 0");
} else if (PageMax <= 1) {
_pagination = "<Pages Max=\"1\" Current=\"1\"><Page Index=\"1\" /></Pages>";
} else if (PageMax <= PageCount) {
pagestart = 1;
pageend = PageMax;
} else {
int temp = 0;
if (pagestart < 1) {
temp = 1 - pagestart;
pagestart = 1;
pageend += temp;
}
if (pageend > PageMax) {
temp = pageend - PageMax;
pageend = PageMax;
pagestart -= temp;
}
if (pagestart < 1) { pagestart = 1; }
}
if (string.IsNullOrEmpty(_pagination)) {
_tempsb.Append(string.Format("<Pages Max=\"{0}\" Current=\"{1}\">", PageMax, PageIndex));
for (int i = pagestart; i <= pageend; i++) {
_tempsb.Append(string.Format("<Page Index=\"{0}\" />", i));
}
_tempsb.Append("</Pages>");
_pagination = _tempsb.ToString();
}
if (_type == PageDataType.Xml && !_pageable) {
System.Xml.XPath.XPathNavigator _xPathNavigator = _dataXml.CreateNavigator();
System.Xml.XmlDocument _xmlDocument = new System.Xml.XmlDocument();
_xmlDocument.LoadXml(_xPathNavigator.OuterXml);
_xPathNavigator = _xmlDocument.CreateNavigator();
_xPathNavigator.MoveToFirstChild();
_xPathNavigator.AppendChild(_pagination);
_dataXml = new System.Xml.XPath.XPathDocument(new System.IO.StringReader(_xPathNavigator.OuterXml));
}
_pageable = true;
return _pagination;
}
示例2: ReturnApplicationLogItem
/// <summary>
/// Return a specific application log by Id.
/// </summary>
/// <param name="context">
/// An System.Web.HttpContext object that provides references to the intrinsic server objects (for example, Request, Response, Session, and
/// Server) used to service HTTP requests.
/// </param>
/// <param name="itemId">Id of the application log to return.</param>
private void ReturnApplicationLogItem(HttpContext context, int itemId)
{
var config = CoreWebConfiguration.Configuration.ApplicationLogRssFeed;
var connectionStringName = config.ConnectionString.Name;
if (string.IsNullOrWhiteSpace(connectionStringName))
{
connectionStringName = DefaultConnectionStringName;
}
var connectionString = ConfigurationManager.ConnectionStrings[connectionStringName];
var applicationLogRepository = new ApplicationLogRepository(connectionString.ConnectionString);
var log = applicationLogRepository.GetById(itemId);
var xmlDocument = new System.Xml.XmlDocument();
var xmlNavigator = xmlDocument.CreateNavigator();
using (var writer = xmlNavigator.AppendChild())
{
var serializer = new DataContractSerializer(typeof(ApplicationLogDao));
serializer.WriteObject(writer, log);
}
if (null != log.Data.FirstChild)
{
var dataElement = xmlDocument.CreateElement("Data", xmlDocument.FirstChild.NamespaceURI);
var importedElement = xmlDocument.ImportNode(log.Data.FirstChild, true);
dataElement.AppendChild(importedElement);
xmlDocument.FirstChild.AppendChild(dataElement);
}
context.Response.ContentType = "text/xml";
context.Response.Output.Write(xmlDocument.InnerXml);
context.Response.StatusCode = (int) HttpStatusCode.OK;
context.Response.Flush();
}