Example #1
0
	public static void Main (string [] args)
	{
		if (args.Length == 0) {
			Console.WriteLine ("pass path-to-web.config.");
			return;
		}
		XmlDocument doc = new XmlDocument ();
		doc.Load (args [0]);
		XmlElement el = doc.SelectSingleNode ("/configuration/system.web/httpHandlers") as XmlElement;
		XmlElement old = el.SelectSingleNode ("add[@path='*.svc']") as XmlElement;
		XmlNode up = doc.ReadNode (new XmlTextReader ("fixup-config2.xml"));
		if (old != null)
			el.RemoveChild (old);
		el.InsertAfter (up, null);
		XmlTextWriter w = new XmlTextWriter (args [0], null);
		w.Formatting = Formatting.Indented;
		w.IndentChar = '\t';
		w.Indentation = 1;
		doc.Save (w);
		w.Close ();
	}
Example #2
0
	public static void Main (string [] args)
	{
		if (args.Length == 0) {
			Console.WriteLine ("pass path-to-machine.config.");
			return;
		}
		XmlDocument doc = new XmlDocument ();
		doc.Load (args [0]);
		XmlElement el = doc.SelectSingleNode ("/configuration/configSections") as XmlElement;
		XmlElement old = el.SelectSingleNode ("sectionGroup[@name='system.serviceModel']") as XmlElement;
		XmlNode up = doc.ReadNode (new XmlTextReader ("fixup-config.xml"));
		if (old != null)
			el.RemoveChild (old);
		el.InsertAfter (up, null);
		XmlTextWriter w = new XmlTextWriter (args [0], null);
		w.Formatting = Formatting.Indented;
		w.IndentChar = '\t';
		w.Indentation = 1;
		doc.Save (w);
		w.Close ();
	}
Example #3
0
        public bool MoveNext()
        {
            XmlDocument xmlDoc = new XmlDocument();
            XmlNode testNode;

            try {
                testNode = xmlDoc.ReadNode(reader);
            }
            catch (System.Exception ex) {
                Debug.LogException(ex);
                return false;
            }
            if (testNode != null) {
                currentNode = testNode;
                return true;
            }
            return false;
        }
Example #4
0
    /// <summary>
    /// Funtion for client to call for uploading xml file.
    /// takes a file stream as input and ouputs a 
    /// string response in xml format with a message 
    /// element, errors element and succesful element 
    /// on the status of the upload.
    /// </summary>
    /// <param name="stream"></param>
    /// <returns></returns>
    public string UploadStream(System.IO.Stream stream)
    {
        // create vars for validation
        bool bIsValid;
        XmlNode currentRow;
        XmlDocument xmlDoc = new XmlDocument();
        string strErrors = "";

        //create return xmlDoc
        XmlElement parentNode = xmlDoc.CreateElement("upload");;
        CreateReturnXml(xmlDoc, parentNode);

        //this implementation places the uploaded xml file
        //in the bin directory and gives it a unique id filename
        //To Do:should add a meaningful string to filename
        string filePath = HostingEnvironment.ApplicationPhysicalPath + ConfigurationManager.AppSettings["bin"].ToString() + Guid.NewGuid() + ".xml";

        // XmlWriter is not in using block so as to
        // differentiate between xsd validation problem
        // and xml is not well formed problem
        XmlWriter writer = XmlWriter.Create(filePath);
        try
        {
            // creating xmlreader and xmlreaderSetting to validate
            // against and xsd file
            String xsdUri = HostingEnvironment.ApplicationPhysicalPath + ConfigurationManager.AppSettings["XSDPath"].ToString() + "books.xsd";
            XmlReaderSettings xmlSettings = new XmlReaderSettings();
            xmlSettings.ValidationType = ValidationType.Schema;
            xmlSettings.Schemas.Add(null, xsdUri);
            // xml validation handler
            xmlSettings.ValidationEventHandler += delegate(object sender, ValidationEventArgs vargs)
            {
                strErrors += vargs.Message + "\n";
                bIsValid = false;
            };

            // An using block to close xmlreader and xmlwritter
            // in case of an exception
            using (XmlReader reader = XmlReader.Create(stream, xmlSettings))
            {
                //create xmlDocument used to read a node from reader
                XmlDocument doc = new XmlDocument();

                // creating  xmlWriter setting
                XmlWriterSettings xws = new XmlWriterSettings();
                xws.Indent = true;
                writer.Close();
                writer = XmlWriter.Create(filePath, xws);

                // ToFix: find a way to read, validate, and
                // write xml at same time with out using
                // xmlNode (right now loading one xmlNode
                // at a time)

                //loop in the reader until end of xmlreader is reached
                while (reader.Read())
                {
                    // set default of the read to successful
                    bIsValid = true;
                    // read a xmlnode
                    currentRow = doc.ReadNode(reader);
                    // if it is a valid node write to xmlwriter
                    if (bIsValid)
                    {
                        currentRow.WriteTo(writer);
                    }
                    // close xml reader, writer, and the stream
                    // and delete the file and return
                    else
                    {
                        writer.Close();
                        stream.Close();
                        System.IO.File.Delete(filePath);
                        // retrieve the text for return
                        return XsdReturnMessage(xmlDoc, strErrors, parentNode);
                    }
                }
                // xml processed successfully
                // close xml reader, writer, and stream
                writer.Close();
                stream.Close();
                return ValidXml(xmlDoc, filePath, parentNode);
            }
        }
        // if process not sucessful
        // Delete file
        catch (Exception ex)
        {
            ((IDisposable)writer).Dispose();
            stream.Close();
            System.IO.File.Delete(filePath);
            // retrieve the text for return
            return XmlNotWellFormed(xmlDoc, strErrors, parentNode);
        }
        finally
        {
            ((IDisposable)writer).Dispose();
            stream.Close();
        }
    }