private static System.Xml.XmlDocument CreateFileExpirationsFile(System.Xml.XmlDocument doc, ref SQLOptions o) { string FileName = GetCacheFilePath("cache_expirations"); if (doc == null) { doc = new System.Xml.XmlDocument(); System.Xml.XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "ASCII", "yes"); doc.AppendChild(dec); System.Xml.XmlElement ele = doc.CreateElement("SQLHelper_FileExpirations"); doc.AppendChild(ele); } //General.IO.IOTools.QueueWriteFile(doc,FileName, "cache_expirations", new General.IO.IOTools.QueueWriteFileCompletedCallback(CreateFileExpirationsFileCallback)); try { o.WriteToLog("saving cache_expirations.xml"); doc.Save(FileName); } catch (System.UnauthorizedAccessException) { o.WriteToLog("failure to save cache_expirations.xml"); //DO NOTHING } return(doc); }
public TraceToXML(Point beginPoint, String penColor, String penWidth) { this.beginPoint = beginPoint; //创建 XML 对象 xmlDocument = new XmlDocument(); //声明 XML xmlDeclare = xmlDocument.CreateXmlDeclaration("1.0", "utf-8", null); //创建根节点 elementRoot = xmlDocument.CreateElement("Trace"); xmlDocument.AppendChild(elementRoot); //创建第一个节点 //创建节点 Section elementSection = xmlDocument.CreateElement("Section"); elementSection.SetAttribute("penColor", penColor); elementSection.SetAttribute("penWidth", penWidth); elementRoot.AppendChild(elementSection); //创建 Section 的子节点 Point XmlElement elementPoint = xmlDocument.CreateElement("Point"); elementPoint.SetAttribute("time", "0"); XmlElement elementX = xmlDocument.CreateElement("X"); elementX.InnerText = beginPoint.X.ToString(); elementPoint.AppendChild(elementX); XmlElement elementY = xmlDocument.CreateElement("Y"); elementY.InnerText = beginPoint.Y.ToString(); elementPoint.AppendChild(elementY); elementSection.AppendChild(elementPoint); }
public static System.Xml.XmlDocument GenXmlDocument(string root, out System.Xml.XmlElement rootnode) { System.Xml.XmlDocument doc = new XmlDocument(); System.Xml.XmlDeclaration declare = doc.CreateXmlDeclaration("1.0", "UTF-8", null); doc.InsertBefore(declare, doc.DocumentElement); rootnode = doc.CreateElement(root); doc.AppendChild(rootnode); return(doc); }
public void InnerAndOuterXml () { declaration = document.CreateXmlDeclaration ("1.0", null, null); AssertEquals (String.Empty, declaration.InnerXml); AssertEquals ("<?xml version=\"1.0\"?>", declaration.OuterXml); declaration = document.CreateXmlDeclaration ("1.0", "doesn't check", null); AssertEquals (String.Empty, declaration.InnerXml); AssertEquals ("<?xml version=\"1.0\" encoding=\"doesn't check\"?>", declaration.OuterXml); declaration = document.CreateXmlDeclaration ("1.0", null, "yes"); AssertEquals (String.Empty, declaration.InnerXml); AssertEquals ("<?xml version=\"1.0\" standalone=\"yes\"?>", declaration.OuterXml); declaration = document.CreateXmlDeclaration ("1.0", "foo", "no"); AssertEquals (String.Empty, declaration.InnerXml); AssertEquals ("<?xml version=\"1.0\" encoding=\"foo\" standalone=\"no\"?>", declaration.OuterXml); }
public static void Load() { doc = new XmlDocument(); try { int foo = 0; int bar = foo / foo; doc.Load("http://localhost/Abimn/news.xml"); } catch { docLoaded = false; LoadFinished = true; return; } declaration = doc.CreateXmlDeclaration("1.0", "utf-8", null); docLoaded = true; LoadFinished = true; }
/// <summary> /// 传入俩个List 一个为xml节点,一个为节点值,最后返回生成的xml /// </summary> /// <param name="xmlNode"></param> /// <param name="nodeVale"></param> /// <returns></returns> public static string ListToXml(List <string> xmlNode, List <string> nodeVale) { string strXml = ""; XmlDocument xml = new XmlDocument(); System.Xml.XmlDeclaration dec = xml.CreateXmlDeclaration("1.0", "utf-8", null); xml.AppendChild(dec); System.Xml.XmlElement ele = xml.CreateElement("NEWDATASET"); for (int i = 0; i < xmlNode.Count; i++) { XmlElement _ele = xml.CreateElement(xmlNode[i]); _ele.InnerText = nodeVale[i]; ele.AppendChild(_ele); } xml.AppendChild(ele); return(strXml = xml.InnerXml.ToString()); }
/// <summary> /// 保存排序规则 /// </summary> /// <param name="strpath"></param>文件绝对路径 /// <param name="className"></param>根节点 /// <param name="node"></param>打印类型的节点 /// <param name="sortName"></param>排序的列名 /// <param name="sortOrder"></param>排序(升降) public void SaveNode(string strpath, string className, string node, string sortName, string sortOrder) { XmlDocument xd = new XmlDocument();//创建文 if (System.IO.File.Exists(strpath)) { System.IO.StreamReader sr = new System.IO.StreamReader(strpath); string strXml = sr.ReadToEnd().Trim(); sr.Close(); if (strXml.Length > 0) { xd.Load(strpath);//加载文档 XmlNode xmlNode = xd.SelectSingleNode("//" + node); if (xmlNode != null) { xmlNode.InnerText = sortName.Trim(); XmlElement xmlele = (XmlElement)xmlNode; xmlele.SetAttribute("sortOrder", sortOrder); } else { XmlNode root1 = xd.DocumentElement; System.Xml.XmlElement ele2 = xd.CreateElement(node); ele2.InnerText = sortName.Trim(); ele2.SetAttribute("sortOrder", sortOrder); root1.AppendChild(ele2); } } else { System.Xml.XmlDeclaration dec = xd.CreateXmlDeclaration("1.0", "utf-8", null); xd.AppendChild(dec); System.Xml.XmlElement ele = xd.CreateElement(className); ele.SetAttribute("Version", "1"); xd.AppendChild(ele); System.Xml.XmlElement ele2 = xd.CreateElement(node); ele2.InnerText = sortName.Trim(); ele2.SetAttribute("sortOrder", sortOrder); ele.AppendChild(ele2); } } else { System.Xml.XmlDeclaration dec = xd.CreateXmlDeclaration("1.0", "utf-8", null); xd.AppendChild(dec); System.Xml.XmlElement ele = xd.CreateElement(className); ele.SetAttribute("Version", "1"); xd.AppendChild(ele); System.Xml.XmlElement ele2 = xd.CreateElement(node); ele2.InnerText = sortName.Trim(); ele2.SetAttribute("sortOrder", sortOrder); ele.AppendChild(ele2); } string filename = strpath; string hh = (xd.InnerXml.ToString()); System.IO.FileStream myFs = new System.IO.FileStream(filename, System.IO.FileMode.Create); System.IO.StreamWriter mySw = new System.IO.StreamWriter(myFs); mySw.Write(hh); mySw.Close(); myFs.Close(); }
/// <summary> /// Initializes settings for the project to be saved. /// </summary> /// <param name="project"></param> /// <param name="projectRootElementDeclaration">If null, XML declaration is not written.</param> internal void Initialize(XmlDocument project, XmlDeclaration projectRootElementDeclaration) { // if the project's whitespace is not being preserved if (!project.PreserveWhitespace) { // write out child elements in an indented fashion, instead of jamming all the XML into one line base.Formatting = Formatting.Indented; } // don't write an XML declaration unless the project already has one or has non-default encoding _writeXmlDeclaration = ((projectRootElementDeclaration != null) || ((_documentEncoding != Encoding.UTF8) && (_documentEncoding != null))); }
public ReqIfDocument() { xmlDeclaration = CreateXmlDeclaration("1.0", "UTF-8", null); }
public XmlDeclarationWrapper(XmlDeclaration declaration) : base((XmlNode) declaration) { this._declaration = declaration; }
public string SetXml() { System.Xml.XmlDocument doc = new XmlDocument(); System.Xml.XmlDocument savedoc = new XmlDocument(); System.Xml.XmlDeclaration declare = doc.CreateXmlDeclaration("1.0", "UTF-8", null); doc.InsertBefore(declare, doc.DocumentElement); XmlElement rootnode = doc.CreateElement("MIAP"); XmlElement headNode = doc.CreateElement("MIAP-Header"); XmlElement TransactionID_Node = doc.CreateElement("TransactionID"); TransactionID_Node.InnerText = TransactionID; headNode.AppendChild(TransactionID_Node); XmlElement Version_Node = doc.CreateElement("Version"); Version_Node.InnerText = Version; headNode.AppendChild(Version_Node); XmlElement MessageName_Node = doc.CreateElement("MessageName"); MessageName_Node.InnerText = MessageName.Replace("Req", "Resp"); headNode.AppendChild(MessageName_Node); XmlElement TestFlag_Node = doc.CreateElement("TestFlag"); TestFlag_Node.InnerText = TestFlag; headNode.AppendChild(TestFlag_Node); XmlElement ReturnCode_Node = doc.CreateElement("ReturnCode"); ReturnCode_Node.InnerText = ReturnCode; headNode.AppendChild(ReturnCode_Node); XmlElement ReturnMessage_Node = doc.CreateElement("ReturnMessage"); ReturnMessage_Node.InnerText = ReturnMessage; headNode.AppendChild(ReturnMessage_Node); rootnode.AppendChild(headNode); XmlElement bodyNode = doc.CreateElement("MIAP-Body"); string MessageName_Resp = MessageName.Replace("Req", "Resp"); /*根据记录集返回数据*/ for (int i = 0; i < dt_resp.Rows.Count; i++) { XmlElement Resp_Node = doc.CreateElement(MessageName_Resp); for (int c = 0; c < dt_resp.Columns.Count; c++) { string col_id = dt_resp.Columns[c].ColumnName; XmlElement colNode = doc.CreateElement(col_id); string col_data = dt_resp.Rows[i][c].ToString(); if (col_data == null) { col_data = ""; } if (col_id.ToUpper().IndexOf("PIC_") == 0) { colNode.InnerText = getpicstring(col_data); } else { colNode.InnerText = col_data; } Resp_Node.AppendChild(colNode); } bodyNode.AppendChild(Resp_Node); } rootnode.AppendChild(bodyNode); doc.AppendChild(rootnode); ResponseXml = doc.OuterXml; ResponseXml = ResponseXml.Replace("<", "<"); ResponseXml = ResponseXml.Replace(">", ">"); string yyyymmdd = DateTime.Now.ToString("yyyyMMdd"); string path = Server.MapPath("\\XML_LOG\\" + yyyymmdd); string filename = Guid.NewGuid().ToString() + ".xml"; string ls_url = Fun.GetIndexUrl() + "XML_LOG/" + yyyymmdd + "/" + filename; //log_sql = log_sql + " Select ,'" + RequestXml + "','" + yyyymmdd + "\\" + filename + "',sysdate from dual "; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string log_sql = "update M905 set M907_KEY= " + M907_key + ", RECEIVE_FILE ='" + yyyymmdd + "\\" + filename + "', modi_date= sysdate where m905_key=" + m905_key; db.BeginTransaction(); int li_db = db.ExecuteNonQuery(log_sql, CommandType.Text); if (li_db < 0) { db.Rollback(); } else { db.Commit(); } doc.Save(path + "\\" + filename); return(ls_url); }
public void NewFile(string FilePath) { _filePath = FilePath; _xmlDec = _xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", "yes"); _xmlDoc.AppendChild(_xmlDec); _xmlRoot = _xmlDoc.CreateElement("XmlConfiguation"); _xmlDoc.AppendChild(_xmlRoot); _xmlDoc.Save(FilePath); }
public XmlData(byte[] data) { //XmlDocument initialisieren InternalXmlDocument=new XmlDocument(); InternalXmlDeclaration=InternalXmlDocument.CreateXmlDeclaration("1.0", "utf-8", "yes"); InternalXmlDocument.InsertBefore(InternalXmlDeclaration, InternalXmlDocument.DocumentElement); MemoryStream ms=new MemoryStream(data); InternalFilename=""; InternalXmlDocument.Load(ms); }
/// <summary> /// Konstruktor welcher gleich eine Datei l�dt /// </summary> /// <param name="filename">Name der Datei</param> public void InitXmlDataWithFile(string filename, bool overwrite) { //XmlDocument initialisieren InternalXmlDocument=new XmlDocument(); InternalXmlDeclaration=InternalXmlDocument.CreateXmlDeclaration("1.0", "utf-8", "yes"); InternalXmlDocument.InsertBefore(InternalXmlDeclaration, InternalXmlDocument.DocumentElement); InternalFilename=filename; //InternalXmlDocument.XmlResolver=new Resolver(); if(FileSystem.ExistsFile(filename)&&overwrite==false) { InternalXmlDocument.Load(InternalFilename); } }
/// <summary> /// Konstruktor /// </summary> public XmlData() { //XmlDocument initialisieren InternalXmlDocument=new XmlDocument(); InternalXmlDeclaration=InternalXmlDocument.CreateXmlDeclaration("1.0", "utf-8", "yes"); InternalXmlDocument.InsertBefore(InternalXmlDeclaration, InternalXmlDocument.DocumentElement); }
private void LoadSetupNodeInfo() { int rowNum = 1; this._universeTable = new List<UniverseEntry>(); //Setup the XML Document doc = new XmlDocument(); //Try to load the settings file try { doc.Load("Modules\\Controller\\E131settings.xml"); } //Couldn't load the file, so create one catch (System.IO.FileNotFoundException) { doctype = doc.CreateXmlDeclaration("1.0", null, "yes"); doc.AppendChild(doctype); _setupNode = doc.CreateElement("Setup"); doc.AppendChild(_setupNode); } //Navigate to the correct part of the XML file _setupNode = doc.ChildNodes.Item(1); this._warningsOption = true; this._statisticsOption = false; this._eventRepeatCount = 0; this._guid = Guid.Empty; foreach (XmlNode child in _setupNode.ChildNodes) { XmlAttributeCollection attributes = child.Attributes; XmlNode attribute; if (child.Name == "Guid") { if ((attribute = attributes.GetNamedItem("id")) != null) { try { this._guid = new Guid(attribute.Value); } catch { this._guid = Guid.Empty; } } } if (child.Name == "Options") { this._warningsOption = false; if ((attribute = attributes.GetNamedItem("warnings")) != null) { if (attribute.Value == "True") { this._warningsOption = true; } } this._statisticsOption = false; if ((attribute = attributes.GetNamedItem("statistics")) != null) { if (attribute.Value == "True") { this._statisticsOption = true; } } this._eventRepeatCount = 0; if ((attribute = attributes.GetNamedItem("eventRepeatCount")) != null) { this._eventRepeatCount = attribute.Value.TryParseInt32(0); } } if (child.Name == "Universe") { bool active = false; int universe = 1; int start = 1; int size = 1; string unicast = null; string multicast = null; int ttl = 1; if ((attribute = attributes.GetNamedItem("active")) != null) { if (attribute.Value == "True") { active = true; } } if ((attribute = attributes.GetNamedItem("number")) != null) { universe = attribute.Value.TryParseInt32(1); } if ((attribute = attributes.GetNamedItem("start")) != null) { start = attribute.Value.TryParseInt32(1); } if ((attribute = attributes.GetNamedItem("size")) != null) { size = attribute.Value.TryParseInt32(1); } if ((attribute = attributes.GetNamedItem("unicast")) != null) { unicast = attribute.Value; } if ((attribute = attributes.GetNamedItem("multicast")) != null) { multicast = attribute.Value; } if ((attribute = attributes.GetNamedItem("ttl")) != null) { ttl = attribute.Value.TryParseInt32(1); } this._universeTable.Add( new UniverseEntry(rowNum++, active, universe, start - 1, size, unicast, multicast, ttl)); } } if (this._guid == Guid.Empty) { this._guid = Guid.NewGuid(); } }
private void createXMLFile(string path) { string[] aformatList = {"avi", "mp4", "mpeg", "mpg", "divx", "mov", "wmv"}; try { //////////////判断xml文件是否存在,如果不存在则创建新的xml文件 if (System.IO.File.Exists(xmlfilename)) { //如果a.xml已经存在,则载入 xmldoc.Load(xmlfilename); xmlfileexist = true; } else { //如果a.xml不存在,则创建新的xml文件。 xmldoc = new XmlDocument(); xmldecl = xmldoc.CreateXmlDeclaration("1.0", "gb2312", null); xmldoc.AppendChild(xmldecl); //加入XML的声明段落,<?xml version="1.0" encoding="gb2312"?> xmlelem = xmldoc.CreateElement("", "catalog", ""); //加入一个根元素 xmldoc.AppendChild(xmlelem); } /////////////// XmlNode root = xmldoc.SelectSingleNode("catalog"); //查找<Catelog> ///////////////遍历文件夹和文件,对应每个视频文件建立相应的vnode结点 string[] dir = Directory.GetDirectories(path); //当前文件夹列表 DirectoryInfo fdir = new DirectoryInfo(path); FileInfo[] file = fdir.GetFiles(); //FileInfo[] file = Directory.GetFiles(path); //文件列表 XmlElement xeTemp, xeTempSub, xeTempSub1; if (file.Length != 0 || dir.Length != 0) //当前目录文件或文件夹不为空 { foreach (FileInfo f in file) //显示当前目录所有文件,各种格式的都有,没有文件夹 { string sfullName = f.FullName.ToString(); //取得文件的完整路径字符串 int iLastIndexOfSlash = sfullName.LastIndexOf('\\'); int iLastIndexOfDot = sfullName.LastIndexOf('.'); string sformat = sfullName.Substring(iLastIndexOfDot + 1); //取出了文件类型 string sname = sfullName.Substring(iLastIndexOfSlash + 1, iLastIndexOfDot - iLastIndexOfSlash - 1); //取出了文件名 string sformatLow = sformat.ToLower(); long sLength = f.Length; foreach (string format in aformatList) // { if (sformatLow.CompareTo(format) == 0){ //如果找到了视频格式文件,则进行结点的创建 xeTemp = xmldoc.CreateElement("", "vnode", ""); //创建视频结点 xeTemp.SetAttribute("name", sname); xeTemp.SetAttribute("format", sformatLow); xeTempSub = xmldoc.CreateElement("", "vsize", ""); xeTempSub.InnerText = sLength.ToString(); xeTemp.AppendChild(xeTempSub); xeTempSub = xmldoc.CreateElement("", "vdir", ""); xeTempSub.InnerText = sfullName; xeTemp.AppendChild(xeTempSub); xeTempSub = xmldoc.CreateElement("", "vdataset", ""); xeTempSub.InnerText = "vdataset"; //TODO xeTemp.AppendChild(xeTempSub); xeTempSub = xmldoc.CreateElement("", "features", ""); xeTempSub.SetAttribute("fNumber", "0"); //default:0 xeTempSub1 = xmldoc.CreateElement("", ""); xeTemp.AppendChild(xeTempSub); root.AppendChild(xeTemp); } } Console.Write(sfullName + "\n sname: " + sname + "\n sformat: " + sformat); break; //Console.Write(" -- " + filename + "\n"); } foreach (string d in dir) { //Console.Write("d: " + d + "\n"); int startIndex = d.LastIndexOf("\\"); string fileName = d.Substring(startIndex + 1); //文件夹名称 //Console.Write("" + fileName + "\n"); createXMLFile(d); //递归 } } else return; xmldoc.Save("a.xml"); //保存a.xml文件 } catch { }; }
private void WriteResponse(ControllerContext context, XDocument doc, XmlDocument xmldoc, XmlDeclaration xmldecl, String encoding) { doc.Declaration = new XDeclaration("1.0", encoding, null); context.HttpContext.Response.Charset = encoding; xmldecl.Encoding = encoding.ToUpper(); XmlElement root = xmldoc.DocumentElement; xmldoc.InsertBefore(xmldecl, root); context.HttpContext.Response.BinaryWrite( System.Text.UTF8Encoding.Default.GetBytes(xmldoc.OuterXml)); //return root; }
public string GetDeclarationAttr(XmlDeclaration decl, string name) { if (name == "version") { return decl.Version; } if (name == "encoding") { return decl.Encoding; } if (name == "standalone") { return decl.Standalone; } return null; }
private XmlDocument GetDocumentWithDeclarartion(XmlDocument xdoc, XmlDeclaration xDecl) { try { XmlDeclaration xdec = xdoc.CreateXmlDeclaration(xDecl.Version, xDecl.Encoding, null); xdoc.InsertBefore(xdec, xdoc.FirstChild); } catch (Exception ex) { log.Error(jobKeyCode, "Could not create XmlDocuemnt with given XmlDeclaration"); log.Error(jobKeyCode,ex); } return xdoc; }
public String GetDeclarationAttr( XmlDeclaration decl, String name ) { //PreCondition: curNode is pointing at Declaration node or one of its virtual attributes if ( name == strVersion ) return decl.Version; if ( name == strEncoding ) return decl.Encoding; if ( name == strStandalone ) return decl.Standalone; return null; }
public void GetReady () { document = new XmlDocument (); document.LoadXml ("<foo><bar></bar></foo>"); declaration = document.CreateXmlDeclaration ("1.0", null, null); }
public XmlDeclarationWrapper(XmlDeclaration declaration) : base(declaration) { _declaration = declaration; }
/// <summary> /// Compares properties of XML declaration. /// </summary> private ComparisonResult CompareDeclarations(XmlDeclaration control, XPathContext controlContext, XmlDeclaration test, XPathContext testContext) { string controlVersion = control == null ? "1.0" : control.Version; string testVersion = test == null ? "1.0" : test.Version; ComparisonResult lastResult = Compare(new Comparison(ComparisonType.XML_VERSION, control, GetXPath(controlContext), controlVersion, test, GetXPath(testContext), testVersion)); if (lastResult == ComparisonResult.CRITICAL) { return lastResult; } string controlStandalone = control == null ? string.Empty : control.Standalone; string testStandalone = test == null ? string.Empty : test.Standalone; lastResult = Compare(new Comparison(ComparisonType.XML_STANDALONE, control, GetXPath(controlContext), controlStandalone, test, GetXPath(testContext), testStandalone)); if (lastResult == ComparisonResult.CRITICAL) { return lastResult; } string controlEncoding = control != null ? control.Encoding : string.Empty; string testEncoding = test != null ? test.Encoding : string.Empty; return Compare(new Comparison(ComparisonType.XML_ENCODING, control, GetXPath(controlContext), controlEncoding, test, GetXPath(testContext), testEncoding)); }