Exemplo n.º 1
0
        public ActionResult MostrarDestinoIco(String url)
        {
            if (ValidateUrl(url))
            {
                String xml = WebRequest(oAuthTwitter.Method.GET, url, String.Empty);
                if (xml != "")
                {
                    XmlDocument myXmlDocument = new XmlDocument();
                    myXmlDocument.LoadXml(xml);
                    myXmlDocument.Normalize();

                    XmlNodeList myNodeList = myXmlDocument.GetElementsByTagName("CUENTA");

                    IList<Destino> destinos = new List<Destino>();
                    var destino = new Destino();
                    foreach (XmlNode nodo in myNodeList)
                    {
                        destino.Direccion = nodo.ChildNodes[6].InnerText;
                        destino.Descripcion = nodo.ChildNodes[2].InnerText;
                        destino.Fecha = DateTime.Parse(nodo.ChildNodes[8].InnerText);
                        destino.Url = nodo.ChildNodes[4].InnerText;
                        destinos.Add(destino);
                    }

                    return View(destinos);
                }
            }
            return View();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Formats XHTML as an XML document with perfect indentation.
        /// </summary>
        /// <param name="html">The XHTML to format.</param>
        /// <returns>The formatted XHTML.</returns>
        public static string FormatHtml(string html)
        {
            // Create a memory stream to store the formatted output
            using (MemoryStream memoryStream = new MemoryStream())
            {
                try
                {
                    // Get the HTML output from the HTTP response stream and load it into an XML document
                    XmlDocument document = new XmlDocument();
                    document.PreserveWhitespace = false;
                    document.LoadXml(html);
                    document.Normalize();

                    // Write the document to the memory stream
                    XmlTextWriter writer = new XmlTextWriter(memoryStream, Encoding.UTF8);
                    writer.Formatting = Formatting.Indented;
                    writer.Indentation = 2;
                    document.Save(writer);

                    // Return the formatted XHTML
                    return Encoding.UTF8.GetString(memoryStream.ToArray());
                }
                catch (XmlException)
                {
                    return null;
                }
            }
        }
Exemplo n.º 3
0
 public static string Canonicalize(string xml)
 {
     XmlDocument doc = new XmlDocument();
     doc.LoadXml(xml);
     doc.Normalize();
     return doc.DocumentElement.OuterXml;
 }
Exemplo n.º 4
0
        public void LoadBots()
        {
            if (!File.Exists(BotSaveFile))
            {
                return;
            }
            try
            {
                Cover.SetVisible(true);
                XmlDocument LoadFile = new XmlDocument();
                LoadFile.Load(BotSaveFile);
                LoadFile.Normalize();

                Cover.ExecuteOnBar((BarExecutable)((ProgressBar Bar) =>
                {
                    Bar.Minimum = 0;
                    Bar.Maximum = LoadFile.SelectNodes("//Version").Count;
                    Bar.Value = 0;
                }));

                XmlNodeList Owners = LoadFile.SelectSingleNode("/SavedBots").SelectNodes("Owner");
                for (int x = 0; x < Owners.Count; x++)
                {
                    string OwnerName = Owners[x].Attributes["Name"].Value;
                    XmlNodeList Bots = Owners[x].SelectNodes("Bot");
                    for (int y = 0; y < Bots.Count; y++)
                    {
                        string BotName = Bots[x].Attributes["Name"].Value;
                        XmlNodeList Versions = Bots[y].SelectNodes("Version");
                        for (int z = 0; z < Versions.Count; z++)
                        {
                            string Version = Versions[z].Attributes["Value"].Value;
                            string BotPath = Versions[z].InnerText;
                            VersionTreeViewItem Temp;
                            this.Bots.AddVersion(OwnerName, BotName, Version, BotPath, out Temp);

                            Cover.ExecuteOnBar((BarExecutable)((ProgressBar Bar) =>
                            {
                                Bar.Value++;
                            }));
                        }
                    }
                }
            }
            catch
            {
                throw new Exception("Failed to load all bots.");
            }
            finally
            {
                Cover.SetVisible(false);
            }
        }
Exemplo n.º 5
0
		// ------------------------------------------------------------------
		#endregion

		#region Private methods.
		// ------------------------------------------------------------------

		/// <summary>
		/// Load files from FileSystem
		/// </summary>
		private void loadFiles()
		{
			_resxFiles = new List<ResxFile>();

			foreach (var item in _gridEditableData.GetFileInformationsSorted())
			{
				using (var reader = XmlReader.Create(item.File.FullName))
				{
					var doc = new XmlDocument();
					doc.Load(reader);
					doc.Normalize();

					_resxFiles.Add(
						new ResxFile
							{
								FileInformation = item,
								FilePath = item.File,
								Document = doc
							});
				}
			}
		}
        /// <summary>
        /// Compares two <code>XmlDocument</code>s.
        /// Returns TRUE if the xml dcouments have the same nodes, in the same position with the exact attributes.
        /// </summary>
        /// <returns>True if the xml dcouments have the same nodes, in the same position with the exact attributes.</returns>
        public static bool AreIdentical(XmlDocument xmlDoc1, XmlDocument xmlDoc2)
        {
            //normalize the documents to avoid adjacent XmlText nodes.
            xmlDoc1.Normalize();
            xmlDoc2.Normalize();

            XmlNodeList nodeList1 = xmlDoc1.ChildNodes;
            XmlNodeList nodeList2 = xmlDoc2.ChildNodes;
            bool same = true;

            if (nodeList1.Count != nodeList2.Count)
            {
                return false;
            }

            IEnumerator enumerator1 = nodeList1.GetEnumerator();
            IEnumerator enumerator2 = nodeList2.GetEnumerator();
            while (enumerator1.MoveNext() && enumerator2.MoveNext() && same)
            {
                same = CompareNodes((XmlNode)enumerator1.Current, (XmlNode)enumerator2.Current);
            }
            return same;
        }
        public WriteableContactProperties(Stream source, bool ownsStream)
        {
            // _disposed = false;
            // _modified = false;

            Assert.IsNotNull(source);

            try
            {
                _document = new XmlDocument();
                _document.Schemas.Add(_ContactSchemaCache);

                source.Position = 0;
                _document.Load(source);

                if (ownsStream)
                {
                    Utility.SafeDispose(ref source);
                }

                // Coalesce adjacent Text nodes.  The XSD may make this superfluous.
                _document.Normalize();

                _ValidateDom();

                _contactTree = new ContactTree(_document);
                _namespaceManager = new XmlElementManager(_document);
            }
            catch (XmlException xmlEx)
            {
                throw new InvalidDataException("Invalid XML", xmlEx);
            }
        }
Exemplo n.º 8
0
		/// <summary>
		/// Creates/serializes an XML doc from the persisted DTS package object.
		/// </summary>
		/// <returns>The XML doc.</returns>
		private XmlDocument createXMLDocFromPackage()
		{
			XmlDocument xDoc = new XmlDocument();
			
			XmlNode xRoot = xDoc.CreateNode(XmlNodeType.Element, "DTS_File", "");
			XmlAttribute xAttr;
			xAttr = xDoc.CreateAttribute("Package_Name", "");
			xAttr.Value = oPackage.Name;
			xRoot.Attributes.Append(xAttr);

			// create top level Package_Property nodes
			int zz = 0;
			CreateChildNodes(xDoc, ref xRoot, typeof(DTS.Package2Class), "Package", oPackage);

			// create GlobalVariables nodes
			XmlNode xGlobalVariables = xDoc.CreateNode(XmlNodeType.Element, "GlobalVariables", "");
			zz = 0;
			foreach( DTS.GlobalVariable2 gv2 in oPackage.GlobalVariables )
			{
				Type t = typeof(DTS.GlobalVariable2);
				string nodeName = "GlobalVariable_" + zz.ToString();
				CreateChildNodes(xDoc, ref xGlobalVariables, t, nodeName, gv2);
				zz ++;
			}
			xRoot.SelectSingleNode("descendant::Package").RemoveChild(xRoot.SelectSingleNode("descendant::Package/GlobalVariables"));
			xRoot.SelectSingleNode("descendant::Package").AppendChild(xGlobalVariables);

			// create connections nodes
			XmlNode xConnections = xDoc.CreateNode(XmlNodeType.Element, "Connections", "");
			zz = 0;
			foreach( DTS.Connection2 cn in oPackage.Connections )
			{
				Type t = typeof(DTS.Connection2);
				string nodeName = "Connection_" + zz.ToString();
				CreateChildNodes(xDoc, ref xConnections, t, nodeName, cn);
				zz ++;
			}
			xRoot.SelectSingleNode("descendant::Package").RemoveChild(xRoot.SelectSingleNode("descendant::Package/Connections"));
			xRoot.SelectSingleNode("descendant::Package").AppendChild(xConnections);

			// create steps nodes
			XmlNode xSteps = xDoc.CreateNode(XmlNodeType.Element, "Steps", "");
			zz = 0;
			foreach( DTS.Step2 sp in oPackage.Steps )
			{
				Type t = typeof(DTS.Step2);
				string nodeName = "Step_" + zz.ToString();
				CreateChildNodes(xDoc, ref xSteps, t, nodeName, sp);
				zz ++;
			}
			xRoot.SelectSingleNode("descendant::Package").RemoveChild(xRoot.SelectSingleNode("descendant::Package/Steps"));
			xRoot.SelectSingleNode("descendant::Package").AppendChild(xSteps);
			
			// create tasks nodes
			XmlNode xTasks = xDoc.CreateNode(XmlNodeType.Element, "Tasks", "");
			zz = 0;
			foreach( DTS.Task ts in oPackage.Tasks )
			{
				Type t = typeof(DTS.Task);
				string nodeName = "Task_" + zz.ToString();
				CreateChildNodes(xDoc, ref xTasks, t, nodeName, ts);
				// remove customtask node as it is only being used to get the customtask properties under the customtaskID node
				xTasks.SelectSingleNode("child::" + nodeName).RemoveChild(xTasks.SelectSingleNode("child::" + nodeName + "/CustomTask"));
				zz ++;
			}
			xRoot.SelectSingleNode("descendant::Package").RemoveChild(xRoot.SelectSingleNode("descendant::Package/Tasks"));
			xRoot.SelectSingleNode("descendant::Package").AppendChild(xTasks);

			xDoc.AppendChild(xRoot);
			xDoc.Normalize();
			return xDoc;
		}
Exemplo n.º 9
0
 public static XmlNode ToXml(IEnumerable<itemHistory> itemsHistorial)
 {
     XmlDocument xmlDoc = new XmlDocument();
     string nodo = "<Historial>";
     if(itemsHistorial!=null)
     foreach (itemHistory item in itemsHistorial)
         nodo += item.ToNodoXml().OuterXml;
     nodo += "</Historial>";
     xmlDoc.LoadXml(nodo);
     xmlDoc.Normalize();
     return xmlDoc.FirstChild;
 }
Exemplo n.º 10
0
 public XmlNode ToNodoXml()
 {
     XmlDocument xmlDoc = new XmlDocument();
     string nodos = itemHistory.ToXml(historial).OuterXml;
     string nodoItemCronos = "<ItemCronos>";
     if (!String.IsNullOrEmpty(Descripcion))
         nodoItemCronos += "<DescripcionItem>" + Descripcion.EscaparCaracteresXML() + "</DescripcionItem>";
     else nodoItemCronos += "<DescripcionItem/>";
     nodoItemCronos += nodos + "</ItemCronos>";
     xmlDoc.LoadXml(nodoItemCronos);
     xmlDoc.Normalize();
     return xmlDoc.FirstChild;
 }
Exemplo n.º 11
0
 public static XmlDocument ToXml(itemCronos[] items)
 {
     XmlDocument xmlDoc = new XmlDocument();
     string doc = "<CronosHistory>";
     for (int i = 0; i < items.Length; i++)
         doc += items[i].ToNodoXml().OuterXml;
     doc += "</CronosHistory>";
     xmlDoc.InnerXml = doc;
     xmlDoc.Normalize();
     return xmlDoc;
 }
 // Helper method that outputs a DOM element from a XML string.
 private static XmlElement parseXmlString(String xmlString)
 {
     var document = new XmlDocument();
     document.LoadXml(xmlString);
     document.Normalize();
     return document.DocumentElement;
 }
Exemplo n.º 13
0
        /**
         * Save relationships into the part.
         *
         * @param rels
         *            The relationships collection to marshall.
         * @param relPartName
         *            Part name of the relationship part to marshall.
         * @param zos
         *            Zip output stream in which to save the XML content of the
         *            relationships serialization.
         */
        public static bool MarshallRelationshipPart(
                PackageRelationshipCollection rels, PackagePartName relPartName,
                ZipOutputStream zos)
        {
            // Building xml
            XmlDocument xmlOutDoc = new XmlDocument();
            // make something like <Relationships
            // xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
            System.Xml.XmlNamespaceManager xmlnsManager = new System.Xml.XmlNamespaceManager(xmlOutDoc.NameTable);
            xmlnsManager.AddNamespace("x", PackageNamespaces.RELATIONSHIPS);

            XmlNode root = xmlOutDoc.AppendChild(xmlOutDoc.CreateElement(PackageRelationship.RELATIONSHIPS_TAG_NAME, PackageNamespaces.RELATIONSHIPS));

            // <Relationship
            // TargetMode="External"
            // Id="rIdx"
            // Target="http://www.custom.com/images/pic1.jpg"
            // Type="http://www.custom.com/external-resource"/>

            Uri sourcePartURI = PackagingUriHelper
                    .GetSourcePartUriFromRelationshipPartUri(relPartName.URI);

            foreach (PackageRelationship rel in rels)
            {
                // the relationship element
                XmlElement relElem = xmlOutDoc.CreateElement(PackageRelationship.RELATIONSHIP_TAG_NAME,PackageNamespaces.RELATIONSHIPS);

                // the relationship ID
                relElem.SetAttribute(PackageRelationship.ID_ATTRIBUTE_NAME, rel.Id);

                // the relationship Type
                relElem.SetAttribute(PackageRelationship.TYPE_ATTRIBUTE_NAME, rel
                        .RelationshipType);

                // the relationship Target
                String targetValue;
                Uri uri = rel.TargetUri;
                if (rel.TargetMode == TargetMode.External)
                {
                    // Save the target as-is - we don't need to validate it,
                    //  alter it etc
                    targetValue = uri.OriginalString;

                    // add TargetMode attribute (as it is external link external)
                    relElem.SetAttribute(
                            PackageRelationship.TARGET_MODE_ATTRIBUTE_NAME,
                            "External");
                }
                else
                {
                    targetValue = PackagingUriHelper.RelativizeUri(
                            sourcePartURI, rel.TargetUri, true).ToString();
                }
                relElem.SetAttribute(PackageRelationship.TARGET_ATTRIBUTE_NAME,
                        targetValue);
                xmlOutDoc.DocumentElement.AppendChild(relElem);
            }

            xmlOutDoc.Normalize();

            // String schemaFilename = Configuration.getPathForXmlSchema()+
            // File.separator + "opc-relationships.xsd";

            // Save part in zip
            ZipEntry ctEntry = new ZipEntry(ZipHelper.GetZipURIFromOPCName(
                    relPartName.URI.ToString()).OriginalString);
            try
            {
                zos.PutNextEntry(ctEntry);

                StreamHelper.SaveXmlInStream(xmlOutDoc, zos);
                zos.CloseEntry();
            }
            catch (IOException e)
            {
                logger.Log(POILogger.ERROR,"Cannot create zip entry " + relPartName, e);
                return false;
            }
            return true; // success
        }
Exemplo n.º 14
0
        public int Collect()
        {
            Queue<Uri> uriQueue = new Queue<Uri>(this.subscriptionList);
            Queue<Task<IEnumerable<Entry>>> taskQueue = new Queue<Task<IEnumerable<Entry>>>();
            List<Entry> entryList = new List<Entry>();
            int successfulRow = 0;

            this.entryList.Clear();

            while (uriQueue.Count > 0 || taskQueue.Count > 0)
            {
                while (uriQueue.Count > 0 && taskQueue.Count < 2 * Environment.ProcessorCount)
                {
                    WebRequest webRequest = WebRequest.Create(uriQueue.Dequeue());
                    Task<IEnumerable<Entry>> task = new Task<IEnumerable<Entry>>(delegate (object state)
                    {
                        WebRequest request = (WebRequest)state;
                        WebResponse response = null;
                        Stream s = null;
                        BufferedStream bs = null;

                        try
                        {
                            response = request.GetResponse();
                            s = response.GetResponseStream();
                            bs = new BufferedStream(s);
                            s = null;

                            XmlDocument xmlDocument = new XmlDocument();

                            xmlDocument.Load(bs);
                            xmlDocument.Normalize();

                            if (xmlDocument.DocumentElement.NamespaceURI.Equals("http://www.w3.org/1999/02/22-rdf-syntax-ns#") && xmlDocument.DocumentElement.LocalName.Equals("RDF"))
                            {
                                return ParseRss10(xmlDocument.DocumentElement);
                            }
                            else if (xmlDocument.DocumentElement.Name.Equals("rss"))
                            {
                                foreach (XmlAttribute xmlAttribute in xmlDocument.DocumentElement.Attributes)
                                {
                                    if (xmlAttribute.Name.Equals("version"))
                                    {
                                        if (xmlAttribute.Value.Equals("2.0"))
                                        {
                                            return ParseRss20(xmlDocument.DocumentElement);
                                        }

                                        break;
                                    }
                                }
                            }
                            else if (xmlDocument.DocumentElement.NamespaceURI.Equals("http://www.w3.org/2005/Atom") && xmlDocument.DocumentElement.LocalName.Equals("feed"))
                            {
                                return ParseAtom10(xmlDocument.DocumentElement);
                            }
                        }
                        finally
                        {
                            if (bs != null)
                            {
                                bs.Close();
                            }

                            if (s != null)
                            {
                                s.Close();
                            }

                            if (response != null)
                            {
                                response.Close();
                            }
                        }

                        return Enumerable.Empty<Entry>();
                    }, webRequest, TaskCreationOptions.LongRunning);

                    if (this.timeout.HasValue)
                    {
                        webRequest.Timeout = this.timeout.Value;
                    }

                    if (this.userAgent != null)
                    {
                        HttpWebRequest httpWebRequest = webRequest as HttpWebRequest;

                        if (httpWebRequest != null)
                        {
                            httpWebRequest.UserAgent = this.userAgent;
                        }
                    }

                    taskQueue.Enqueue(task);
                    task.Start();
                }

                Task<IEnumerable<Entry>>[] tasks = taskQueue.ToArray();
                int index = Task<IEnumerable<Entry>>.WaitAny(tasks);

                taskQueue.Clear();

                for (int i = 0; i < tasks.Length; i++)
                {
                    if (index == i)
                    {
                        if (tasks[i].Exception == null)
                        {
                            this.entryList.AddRange(tasks[i].Result);
                        }
                    }
                    else
                    {
                        taskQueue.Enqueue(tasks[i]);
                    }
                }
            }

            foreach (System.Configuration.ConnectionStringSettings settings in System.Configuration.ConfigurationManager.ConnectionStrings)
            {
                DbProviderFactory factory = DbProviderFactories.GetFactory(settings.ProviderName);

                using (IDbConnection connection = factory.CreateConnection())
                {
                    connection.ConnectionString = settings.ConnectionString;
                    connection.Open();

                    this.entryList.ForEach(delegate (Entry entry)
                    {
                        if (entry.Resource != null)
                        {
                            string sql = null;

                            using (IDbCommand command = factory.CreateCommand())
                            {
                                command.Connection = connection;
                                command.CommandText = BuildSelectStatement(entry.Resource);

                                if ((int)command.ExecuteScalar() == 0)
                                {
                                    sql = BuildInsertStatement(entry);
                                }
                                else if (entry.Created < entry.Modified)
                                {
                                    sql = BuildUpdateStatement(entry);
                                }
                            }

                            if (sql != null)
                            {
                                using (IDbCommand c = factory.CreateCommand())
                                {
                                    c.Connection = connection;
                                    c.CommandText = sql;

                                    IDbTransaction transaction = connection.BeginTransaction(IsolationLevel.ReadCommitted);

                                    c.Transaction = transaction;

                                    try
                                    {
                                        successfulRow += c.ExecuteNonQuery();

                                        transaction.Commit();
                                    }
                                    catch
                                    {
                                        transaction.Rollback();
                                    }
                                }
                            }
                        }
                    });
                }
            }

            return successfulRow;
        }
Exemplo n.º 15
0
        private void saveToolStripButton_Click(object sender, EventArgs e)
        {
            if (imageset_filename.Length == 0)
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Filter = "Imageset Files|*.imageset";
                if (DialogResult.OK == sfd.ShowDialog(this))
                {
                    imageset_filename = sfd.FileName;
                }
                else
                    return;
            }

            layout_editor.ClearUndoRedo();

            System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
            XmlElement imageset_el = doc.CreateElement("Imageset");
            imageset_el.SetAttribute("Name", imageset_name);
            imageset_el.SetAttribute("Imagefile", imagefile);

            imageset_el.SetAttribute("NativeHorzRes", NativeHorzRes.ToString());
            imageset_el.SetAttribute("NativeVertRes", NativeVertRes.ToString());
            imageset_el.SetAttribute("AutoScaled", AutoScaled.ToString());

            doc.AppendChild(imageset_el);

            foreach (TextureRegion reg in layout_editor.Regions)
            {
                XmlElement el = doc.CreateElement("Image");
                el.SetAttribute("Name", reg.Name);

                el.SetAttribute("XPos", reg.Rectangle.X.ToString());
                el.SetAttribute("YPos", reg.Rectangle.Y.ToString());
                el.SetAttribute("Width", reg.Rectangle.Width.ToString());
                el.SetAttribute("Height", reg.Rectangle.Height.ToString());
                imageset_el.AppendChild(el);
            }

            doc.Normalize();
            doc.Save(imageset_filename);
        }
Exemplo n.º 16
0
        public ActionResult MostrarViaje(String url)
        {
            if (ValidateUrl(url))
            {
                String xml = WebRequest(oAuthTwitter.Method.GET, url, String.Empty);
                if (xml != "")
                {
                    XmlDocument myXmlDocument = new XmlDocument();
                    myXmlDocument.LoadXml(xml);
                    myXmlDocument.Normalize();

                    XmlNodeList myNodeList = myXmlDocument.GetElementsByTagName("ViajeXml");

                    IList<Viaje> viajes = new List<Viaje>();
                    IList<Destino> destinos = new List<Destino>();
                    Viaje viaje=null;
                    foreach (XmlNode nodo in myNodeList)
                    {
                        viaje = new Viaje();
                        viaje.Destino = nodo.ChildNodes[0].InnerText;
                        viaje.Nombre = nodo.ChildNodes[5].InnerText;
                        viaje.FechaFin = DateTime.Parse(nodo.ChildNodes[1].InnerText);
                        viaje.FechaInicio = DateTime.Parse(nodo.ChildNodes[2].InnerText);
                        viaje.Hospedaje = nodo.ChildNodes[3].InnerText;
                        viaje.IdViaje = Int32.Parse(nodo.ChildNodes[4].InnerText);
                        viaje.Privacidad = nodo.ChildNodes[6].InnerText;
                        XmlNodeList myNodeList2 = nodo.ChildNodes[7].ChildNodes;

                        foreach (XmlNode nodo2 in myNodeList2)
                        {
                            Destino destino = new Destino();
                            destino.Descripcion =nodo2.ChildNodes[0].InnerText;
                            destino.Direccion = nodo2.ChildNodes[1].InnerText;
                            destino.Fecha = DateTime.Parse(nodo2.ChildNodes[2].InnerText);
                            destinos.Add(destino);
                        }
                        viaje.Destinos = destinos;

                    }

                    return View(viaje);
                }
            }
            return View();
        }
 // Build the PhoneMetadataCollection from the input XML file.
 public static PhoneMetadataCollection BuildPhoneMetadataCollection(Stream input, bool liteBuild)
 {
     var document = new XmlDocument();
     document.Load(input);
     document.Normalize();
     var metadataCollection = new PhoneMetadataCollection.Builder();
     foreach (XmlElement territory in document.GetElementsByTagName("territory"))
     {
         String regionCode = "";
         // For the main metadata file this should always be set, but for other supplementary data
         // files the country calling code may be all that is needed.
         if (territory.HasAttribute("id"))
              regionCode = territory.GetAttribute("id");
         PhoneMetadata metadata = LoadCountryMetadata(regionCode, territory, liteBuild);
         metadataCollection.AddMetadata(metadata);
     }
     return metadataCollection.Build();
 }
Exemplo n.º 18
0
 public XmlNode ToNodoXml()
 {
     XmlDocument xmlDoc = new XmlDocument();
     text nodo = "<HistoryCronos>";
     for (int i = 0; i < stkHistorial.Children.Count; i++)
         nodo &= (stkHistorial.Children[i] as ItemHistorialTime).ToXmlNode().OuterXml;
     nodo &= "</HistoryCronos>";
     xmlDoc.InnerXml = nodo;
     xmlDoc.Normalize();
     return xmlDoc.FirstChild;
 }
Exemplo n.º 19
0
        //获取etouch api数据,并用Listview显示出来
        //  请求例子 http://wthrcdn.etouch.cn/WeatherApi?city=江门
        private DataSet ReadXMl(string XMLFileStream)
        {
            try
            {

                XmlDocument doc = new XmlDocument();
                doc.Normalize();
               // doc.Load(XMLFileStream);
               //doc.Load()
                string url = string.Format("{0}","http://wthrcdn.etouch.cn/WeatherApi?city=江门");
               System.IO.Stream xmlstream =
                   System.Net.WebRequest.Create(url).GetResponse().GetResponseStream();

              // doc.Load(xmlstream);

               StreamReader newxmlstream = new StreamReader(xmlstream, Encoding.UTF8);
               doc.Load(newxmlstream);

                XmlNode xn = doc.SelectSingleNode("resp");

                DataSet dstWeather = new DataSet();
                DataTable dtNormal = new DataTable("normal");

                dstWeather.Tables.Add(dtNormal);

                dstWeather.Tables["normal"].Columns.Add("city", typeof(string));
                dstWeather.Tables["normal"].Columns.Add("wendu", typeof(string));
                dstWeather.Tables["normal"].Columns.Add("shidu", typeof(string));

                if (xn.HasChildNodes == true) //判断是否有子节点
                {

                    DataRow drowNormal = dstWeather.Tables["normal"].NewRow();
                    drowNormal["city"] = xn.SelectSingleNode("city").InnerText;
                    drowNormal["wendu"] = xn.SelectSingleNode("wendu").InnerText;
                    drowNormal["shidu"] = xn.SelectSingleNode("shidu").InnerText;
                    dstWeather.Tables["normal"].Rows.Add(drowNormal);

                }

                return dstWeather;

            }
            catch (Exception exc)
            {
                DataSet dstWeather = new DataSet();
                DataTable dtNormal = new DataTable("normal");
                dstWeather.Tables.Add(dtNormal);
                dstWeather.Tables["normal"].Columns.Add("city", typeof(string));
                dstWeather.Tables["normal"].Columns.Add("wendu", typeof(string));
                dstWeather.Tables["normal"].Columns.Add("shidu", typeof(string));

                DataRow drowNormal = dstWeather.Tables["normal"].NewRow();
                drowNormal["city"] = "none";
                drowNormal["wendu"] = "none";
                drowNormal["shidu"] = "none";
                dstWeather.Tables["normal"].Rows.Add(drowNormal);
                MessageBox.Show(exc.Message);
                return dstWeather;
            }
        }
Exemplo n.º 20
0
        public ActionResult MostrarViajeMateo(String url)
        {
            if (ValidateUrl(url))
            {
                String xml = WebRequest(oAuthTwitter.Method.GET, url, String.Empty);
                if (xml != "")
                {
                    XmlDocument myXmlDocument = new XmlDocument();
                    myXmlDocument.LoadXml(xml);
                    myXmlDocument.Normalize();

                    XmlNodeList myNodeList = myXmlDocument.GetElementsByTagName("trip");

                    IList<Viaje> viajes = new List<Viaje>();

                    foreach (XmlNode nodo in myNodeList)
                    {
                        var viaje = new Viaje();
                        viaje.FechaFin = DateTime.Parse(nodo.ChildNodes[4].InnerText);
                        viaje.FechaInicio = DateTime.Parse(nodo.ChildNodes[7].InnerText);
                        viaje.Hospedaje = nodo.ChildNodes[5].InnerText;
                        viaje.IdViaje = Int32.Parse(nodo.ChildNodes[1].InnerText);
                        viajes.Add(viaje);
                    }

                    return View(viajes);
                }
            }
            return View();
        }
Exemplo n.º 21
0
        public ActionResult MostrarViajeNata(String url)
        {
            if (ValidateUrl(url))
            {
                String xml = WebRequest(oAuthTwitter.Method.GET, url, String.Empty);
                if (xml != "")
                {
                    XmlDocument myXmlDocument = new XmlDocument();
                    myXmlDocument.LoadXml(xml);
                    myXmlDocument.Normalize();

                    XmlNodeList myNodeList = myXmlDocument.GetElementsByTagName("ITINERARIOS");

                    IList<Viaje> viajes = new List<Viaje>();
                    IList<Destino> destinos = new List<Destino>();
                    Viaje viaje=null;
                    foreach (XmlNode nodo in myNodeList)
                    {
                        viaje = new Viaje();
                        viaje.Destino = nodo.ChildNodes[0].InnerText;
                        XmlNodeList myNodeList2 = nodo.ChildNodes[1].ChildNodes;

                        foreach (XmlNode nodo2 in myNodeList2)
                        {
                            Destino destino = new Destino();
                            destino.Direccion = nodo2.ChildNodes[0].InnerText;
                            destino.Fecha = DateTime.Parse(nodo2.ChildNodes[1].InnerText);
                            destino.Url = nodo2.ChildNodes[2].InnerText;
                            destinos.Add(destino);
                        }
                        viaje.Destinos = destinos;

                    }

                    return View(viaje);
                }
            }
            return View();
        }
Exemplo n.º 22
0
        /**
         * Save the contents type part.
         * 
         * @param outStream
         *            The output stream use to save the XML content of the content
         *            types part.
         * @return <b>true</b> if the operation success, else <b>false</b>.
         */
        public bool Save(Stream outStream)
        {
            XmlDocument xmlOutDoc = new XmlDocument();
            XmlNamespaceManager xmlnm = new XmlNamespaceManager(xmlOutDoc.NameTable);
            xmlnm.AddNamespace("x", TYPES_NAMESPACE_URI);
            XmlElement typesElem = xmlOutDoc.CreateElement(TYPES_TAG_NAME, TYPES_NAMESPACE_URI);
            xmlOutDoc.AppendChild(typesElem);

            // Adding default types
            IEnumerator<KeyValuePair<string, string>> contentTypes = defaultContentType.GetEnumerator();
            while (contentTypes.MoveNext())
            {
                AppendDefaultType(xmlOutDoc, typesElem, contentTypes.Current);
            }

            // Adding specific types if any exist
            if (overrideContentType != null)
            {

                IEnumerator<KeyValuePair<PackagePartName, string>> overrideContentTypes = overrideContentType.GetEnumerator();
                while (overrideContentTypes.MoveNext())
                {
                    AppendSpecificTypes(xmlOutDoc, typesElem, overrideContentTypes.Current);
                }
            }

            xmlOutDoc.Normalize();

            // Save content in the specified output stream
            return this.SaveImpl(xmlOutDoc, outStream);

        }
Exemplo n.º 23
0
      private void FailIfXmlNotEqual (TestCaseResult result, String ret, String orig)
	{
	  XmlDocument xd_ret = new XmlDocument ();
	  XmlDocument xd_orig = new XmlDocument ();

	  xd_ret.LoadXml (ret);
	  xd_orig.LoadXml (orig);

	  xd_ret.Normalize ();
	  xd_orig.Normalize ();

	  result.FailIfNotEqual (xd_ret.DocumentElement.OuterXml, xd_orig.DocumentElement.OuterXml);
	}
Exemplo n.º 24
0
 private static void CleanAndNormalize(XmlDocument document)
 {
     XmlNodeList comments = document.SelectNodes("//comment()");
     foreach(XmlNode comment in comments) comment.ParentNode.RemoveChild(comment);
     document.Normalize();
 }
Exemplo n.º 25
0
        /// <summary>
        /// Pretty print XML data.
        /// </summary>
        /// <param name="xml">The string containing valid XML data.</param>
        /// <returns>The xml data in idented and justified form.</returns>
        private static string PrettyPrintXml(string xml)
        {
            var doc = new XmlDocument();
            doc.LoadXml(xml);
            doc.Normalize();

            TextWriter wr = new StringWriter();
            doc.Save(wr);
            var str = wr.ToString();
            return str;
        }