コード例 #1
0
        private T Deserialize <T>(string strXml, T responseType)
        {
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(strXml);
            using (XmlReader reader = new XmlNodeReader(doc)) {
                XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
                T             response;
                try {
                    response = (T)xmlSerializer.Deserialize(reader);
                }
                catch (Exception ex) {
                    ex.DoNothing();
                    reader.Close();
                    //Responses from PDMP Logicoy have contained "xsi:type" attributes in the Pmp node.  This causes deserialization to fail.
                    //Removing it has been the only thing that has worked in our extensive testing when this occurs.
                    StripAttributeFromNode(doc.ChildNodes, "Pmp", "xsi:type");
                    using (XmlReader strippedReader = new XmlNodeReader(doc)){
                        response = (T)xmlSerializer.Deserialize(strippedReader);
                        strippedReader.Close();
                    }
                }
                reader.Close();
                return(response);
            }
        }
コード例 #2
0
ファイル: Serialization.cs プロジェクト: alba2063/Media005
        public static UISettingsCollection CreateObject(XmlDocument XMLString, UISettingsCollection ui)
        {
            UISettingsCollection ui1 = new UISettingsCollection();

            if (XMLString != null)
            {
                XmlSerializer oXmlSerializer = new XmlSerializer(ui.GetType());

                XmlNodeReader reader = null;

                try
                {
                    reader = new XmlNodeReader(XMLString);

                    ui1 = oXmlSerializer.Deserialize(reader) as UISettingsCollection;
                    //initially deserialized, the data is represented by an object without a defined type
                }
                finally
                {
                    if (reader != null)
                    {
                        reader.Close();
                    }
                }
                return(ui1);
            }
            else
            {
                return(ui);
            }
        }
コード例 #3
0
        ///<summary>The problem with this is that if multiple copies of OD are open at the same time, it might get data from only the most recently opened database.  This won't work for some users, so we will normally dynamically alter the connection string.</summary>
        public static string GetODConnStr()
        {
            //return "Server=localhost;Database=development54;User ID=root;Password=;CharSet=utf8";
            XmlDocument document = new XmlDocument();
            string      path     = ODFileUtils.CombinePaths(Application.StartupPath, "FreeDentalConfig.xml");

            if (!File.Exists(path))
            {
                return("");
            }
            string computerName = "";
            string database     = "";
            string user         = "";
            string password     = "";

            try {
                document.Load(path);
                XmlNodeReader reader         = new XmlNodeReader(document);
                string        currentElement = "";
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        currentElement = reader.Name;
                    }
                    else if (reader.NodeType == XmlNodeType.Text)
                    {
                        switch (currentElement)
                        {
                        case "ComputerName":
                            computerName = reader.Value;
                            break;

                        case "Database":
                            database = reader.Value;
                            break;

                        case "User":
                            user = reader.Value;
                            break;

                        case "Password":
                            password = reader.Value;
                            break;
                        }
                    }
                }
                reader.Close();
            }
            catch {
                return("");
            }
            //example:
            //Server=localhost;Database=opendental;User ID=root;Password=;CharSet=utf8
            return("Server=" + computerName
                   + ";Database=" + database
                   + ";User ID=" + user
                   + ";Password="******";CharSet=utf8");
        }
コード例 #4
0
ファイル: DrawDriverXmlOp.cs プロジェクト: xuanximoming/key
        public static bool SetRowsAttributeByXmlNode(XmlDocument doc)
        {
            XmlNodeReader xmlNodeReader = null;
            bool          result;

            try
            {
                if (doc == null)
                {
                    throw new NullReferenceException();
                }
                foreach (XmlNode node in doc.ChildNodes)
                {
                    DrawDriverXmlOp.NodeChildNodes(node);
                }
                result = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (xmlNodeReader != null)
                {
                    xmlNodeReader.Close();
                }
            }
            return(result);
        }
コード例 #5
0
  public static void Main()
  {
    XmlNodeReader reader = null;

    try
    {
       //Create and load the XML document.
       XmlDocument doc = new XmlDocument();
       doc.LoadXml("<book genre='novel' ISBN='1-861003-78' publicationdate='1987'> " +
                   "</book>"); 

       //Load the XmlNodeReader 
       reader = new XmlNodeReader(doc);
  
       //Read the attributes on the root element.
       reader.MoveToContent();
       if (reader.HasAttributes){
         for (int i=0; i<reader.AttributeCount; i++){
            reader.MoveToAttribute(i);
            Console.WriteLine("{0} = {1}", reader.Name, reader.Value);
         }
         //Return the reader to the book element.
         reader.MoveToElement();
       }

     } 

     finally 
     {
        if (reader != null)
          reader.Close();
      }
  }
コード例 #6
0
  public static void Main() {
  
    XmlNodeReader reader = null;

    try {
               
        // Create and load an XmlDocument.
        XmlDocument doc = new XmlDocument();
        doc.LoadXml("<?xml version='1.0' ?>" +
                    "<!DOCTYPE book [<!ENTITY h 'hardcover'>]>" +
                    "<book>" +
                    "<title>Pride And Prejudice</title>" +
                    "<misc>&h;</misc>" +
                    "</book>");

        reader = new XmlNodeReader(doc);

        // Parse the file and display each node.
        while (reader.Read()) {
           if (reader.HasValue)
             Console.WriteLine("({0})  {1}={2}", reader.NodeType, reader.Name, reader.Value);
           else
             Console.WriteLine("({0}) {1}", reader.NodeType, reader.Name);
         }           
     }

     finally {
       if (reader!=null)
         reader.Close();
     }
  }
コード例 #7
0
        public static ArrayList GetDates()
        {
            ArrayList dates = new ArrayList();

            if (xdoc != null)
            {
                XmlNodeList xdates = xdoc.SelectNodes(SCREENSHOT_XPATH + "/" + SCREENSHOT_DATE);

                foreach (XmlNode xdate in xdates)
                {
                    XmlNodeReader xreader = new XmlNodeReader(xdate);

                    while (xreader.Read())
                    {
                        if (xreader.IsStartElement() && xreader.Name.Equals(SCREENSHOT_DATE))
                        {
                            xreader.Read();

                            if (!string.IsNullOrEmpty(xreader.Value))
                            {
                                dates.Add(xreader.Value);
                            }
                        }
                    }

                    xreader.Close();
                }
            }

            return(dates);
        }
コード例 #8
0
        public bool LoadObjectFromXmlNode<T>(XmlNode node, ref T dest)
        {
            XmlNodeReader reader = new XmlNodeReader(node);
            try
            {
                
                if (reader != null)
                {
                    //NetDataContractSerializer serial = new NetDataContractSerializer();
                    XmlSerializer serial = new XmlSerializer(typeof(T));
                    dest = (T)serial.Deserialize(reader);
                    return true;
                }
            }
            catch (Exception e)
            {
                SLogManager.getInstance().getClassLogger(GetType()).Error(e.Message);
            }
            finally
            {
                if (reader != null) reader.Close();
            }

            return false;
        }
コード例 #9
0
ファイル: Server.cs プロジェクト: svn2github/wot-xvm
        private static string GetVersion()
        {
            string        wotVersion = "RU";
            XmlNodeReader reader     = null;

            try
            {
                string      s   = "";
                XmlDocument doc = new XmlDocument();
                //read WOTLauncher.cfg
                doc.Load("WOTLauncher.cfg");

                XmlNode xn = doc.SelectSingleNode("/info/patch_info_urls");

                XmlNodeList xnl = xn.ChildNodes;

                foreach (XmlNode xnf in xnl)
                {
                    XmlElement xe = (XmlElement)xnf;
                    s = xe.InnerText;
                    if (s.LastIndexOf("http://update.worldoftanks.cn/") > -1)
                    {
                        wotVersion = "CN1";
                    }
                    else if (s.LastIndexOf("http://update.wot.ru.wargaming.net") > -1 ||
                             s.LastIndexOf("http://update.worldoftanks.ru") > -1)
                    {
                        wotVersion = "RU";
                    }
                    else if (s.LastIndexOf("http://update.worldoftanks.com") > -1)
                    {
                        wotVersion = "NA";
                    }
                    else if (s.LastIndexOf("http://update.worldoftanks.eu") > -1)
                    {
                        wotVersion = "EU";
                    }
                    else if (s.LastIndexOf("http://update-ct.worldoftanks.net") > -1)
                    {
                        wotVersion = "CT";
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(String.Format("Cannot read WOTLauncher.cfg:{0}{1}",
                                                  Environment.NewLine, ex));
            }
            finally
            {
                //clear
                if (reader != null)
                {
                    reader.Close();
                }
            }
            Log(2, string.Format("WoT version is: {0}", wotVersion));

            return(wotVersion);
        }
コード例 #10
0
        //private void ReadFromXml(int ModuleID)
        //{
        //    string szModelID = Server.ClientFramework.Common.Functions.ToModuleIdString(ModuleID);
        //    this.ReadFromXml(szModelID);
        //}

        private void ReadFromXml(/*string ModuleID*/)
        {
            //if (!this.m_ModulesLoaded.Contains(ModuleID))
            //{
            lock (syncRoot)
            {
                //string FileName = m_szResFilePath + "\\MultiLanRes\\" + m_LCID.ToString() + "\\" + ModuleID.ToString() + ".xml";
                string      FileName = m_szResFilePath + "\\MultiLanRes\\" + m_LCID.ToString() + ".xml";
                XmlDocument dataDoc  = new XmlDocument();
                DsStringRes Data     = new DsStringRes();
                try
                {
                    dataDoc.Load(FileName);
                    XmlNodeReader reader = new XmlNodeReader(dataDoc);
                    Data.ReadXml(reader);
                    reader.Close();
                    //this.m_ModulesLoaded.Add(ModuleID);
                }
                catch (Exception ex)
                {
                }
                //this.m_dsMutiLanRes.MergerFromStringRes(Data, this.m_LCID, ModuleID);
                this.m_dsMutiLanRes.MergerFromStringRes(Data, this.m_LCID);
            }
            //}
        }
コード例 #11
0
ファイル: Tables.cs プロジェクト: fulviofarina/Rsx.Dumb
        public static void ReadDTBytes <T>(ref byte[] auxiliar, ref T DestinyDataTable)
        {
            //string file = startupPath + Guid.NewGuid().ToString() + ".xml";

            //  IO.WriteFileBytes(ref auxiliar, file);
            DataTable toLoad = DestinyDataTable as DataTable;

            string xml = Encoding.UTF8.GetString(auxiliar);

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xml);
            XmlNodeReader reader = new XmlNodeReader(doc);

            try
            {
                toLoad.ReadXml(reader);
            }
            catch (Exception ex)
            {
            }


            reader.Close();
            reader = null;
            doc.RemoveAll();
            doc = null;
            toLoad.AcceptChanges();
            // auxiliar = null;
        }
コード例 #12
0
        /// <summary>
        /// Validates SOAP message from the stream specified.
        /// </summary>
        /// <param name="element"></param>
        /// <returns>True, if stream contains valid messages.</returns>
        public void Validate(XmlElement element)
        {
            XmlReader plainReader = new XmlNodeReader(element);

            while (plainReader.Read())
            {
                ;
            }
            plainReader.Close();
            if (_schemas != null)
            {
                XmlReaderSettings settings = new XmlReaderSettings();
                settings.ValidationType      = ValidationType.Schema;
                settings.Schemas.XmlResolver = null; //disable resolver - all schemas should be in place

                foreach (XmlSchema schema in _schemas.Schemas)
                {
                    settings.Schemas.Add(schema);
                }
                plainReader = new XmlNodeReader(element);
                XmlReader reader = XmlNodeReader.Create(plainReader, settings);

                while (reader.Read())
                {
                }
            }
        }
コード例 #13
0
        /// <summary>
        /// Deserialize settings from a file.
        /// </summary>
        /// <param name="filename">Name of the file.</param>
        /// <returns></returns>
        public static NntpSettings Deseriazlize(string filename)
        {
            var dataProviderTypes = new List <Type>();

            var doc = new XmlDocument();

            doc.Load(filename);

            // Collect all data provider's types
            foreach (XmlNode dataProviderTypeNode in doc.DocumentElement.
                     SelectNodes("/Settings/DataProviderTypeName"))
            {
                dataProviderTypes.Add(((IDataProvider)Activator.CreateInstance(
                                           Type.GetType(dataProviderTypeNode.InnerText, true))).GetConfigType());
            }

            // Deserialize settings with known types of data provider's config objects
            var serializer = new XmlSerializer(typeof(NntpSettings), null,
                                               dataProviderTypes.ToArray(), new XmlRootAttribute("Settings"), null);

            XmlReader fileReader = new XmlNodeReader(doc);

            var serverSettings = (NntpSettings)serializer.Deserialize(fileReader);

            fileReader.Close();

            return(serverSettings);
        }
コード例 #14
0
ファイル: source.cs プロジェクト: ruo2012/samples-1
    public static void Main()
    {
        XmlNodeReader reader = null;

        try
        {
            //Create and load the XML document.
            XmlDocument doc = new XmlDocument();
            doc.LoadXml("<!-- sample XML -->" +
                        "<book>" +
                        "<title>Pride And Prejudice</title>" +
                        "<price>19.95</price>" +
                        "</book>");

            //Load the XmlNodeReader
            reader = new XmlNodeReader(doc);

            reader.MoveToContent();                   //Move to the book node.
            reader.Read();                            //Read the book start tag.
            reader.Skip();                            //Skip the title element.

            Console.WriteLine(reader.ReadOuterXml()); //Read the price element.
        }

        finally
        {
            if (reader != null)
            {
                reader.Close();
            }
        }
    }
コード例 #15
0
        public static Screenshot GetBySlidename(string slidename, int screenNumber)
        {
            Screenshot screenshot = null;

            if (xDoc != null)
            {
                XmlNodeList xScreenshots = xDoc.SelectNodes(SCREENSHOT_XPATH + "[" + SCREENSHOT_SLIDENAME + " = '" + slidename + "' and " + SCREENSHOT_SCREEN + " = '" + screenNumber + "']");

                foreach (XmlNode xScreenshot in xScreenshots)
                {
                    XmlNodeReader xReader = new XmlNodeReader(xScreenshot);

                    while (xReader.Read())
                    {
                        if (xReader.IsStartElement() && xReader.Name.Equals(SCREENSHOT_INDEX))
                        {
                            xReader.Read();

                            if (!string.IsNullOrEmpty(xReader.Value))
                            {
                                screenshot = GetByIndex(Convert.ToInt32(xReader.Value));
                            }
                        }
                    }

                    xReader.Close();
                }
            }

            return(screenshot);
        }
コード例 #16
0
        /// <summary>
        ///  Loads the configuration from the application configuration file.
        /// </summary>
        public static ServerTestConfiguration Load(XmlElementCollection extensions)
        {
            if (extensions == null || extensions.Count == 0)
            {
                return(new ServerTestConfiguration());
            }

            foreach (XmlElement element in extensions)
            {
                if (element.NamespaceURI != "http://opcfoundation.org/UA/SDK/ServerTest/Configuration.xsd")
                {
                    continue;
                }

                XmlNodeReader reader = new XmlNodeReader(element);

                try {
                    DataContractSerializer  serializer    = new DataContractSerializer(typeof(ServerTestConfiguration));
                    ServerTestConfiguration configuration = serializer.ReadObject(reader) as ServerTestConfiguration;

                    if (configuration.Iterations <= 0)
                    {
                        configuration.Iterations = 1;
                    }

                    return(configuration);
                } finally {
                    reader.Close();
                }
            }

            return(new ServerTestConfiguration());
        }
コード例 #17
0
ファイル: source.cs プロジェクト: zhimaqiao51/docs
    public static void Main()
    {
        XmlNodeReader reader = null;

        try
        {
            //Create and load the XML document.
            XmlDocument doc = new XmlDocument();
            doc.LoadXml("<book genre='novel' ISBN='1-861003-78' publicationdate='1987'> " +
                        "</book>");

            //Load the XmlNodeReader
            reader = new XmlNodeReader(doc);

            //Read the genre attribute.
            reader.MoveToContent();
            reader.MoveToFirstAttribute();
            string genre = reader.Value;
            Console.WriteLine("The genre value: " + genre);
        }
        finally
        {
            if (reader != null)
            {
                reader.Close();
            }
        }
    }
コード例 #18
0
  public static void Main()
  {
    XmlNodeReader reader = null;

    try
    {
       //Create and load an XML document.
       XmlDocument doc = new XmlDocument();
       doc.LoadXml("<!DOCTYPE book [<!ENTITY h 'harcover'>]>" +
                   "<book genre='novel' misc='sale-item &h; 1987'>" +
                   "</book>");
        
       //Create the reader. 
       reader = new XmlNodeReader(doc);

       //Read the misc attribute. The attribute is parsed into multiple 
       //text and entity reference nodes.
       reader.MoveToContent();
       reader.MoveToAttribute("misc");
       while (reader.ReadAttributeValue()){
          if (reader.NodeType==XmlNodeType.EntityReference)
            //To expand the entity, call ResolveEntity.
            Console.WriteLine("{0} {1}", reader.NodeType, reader.Name);
          else
             Console.WriteLine("{0} {1}", reader.NodeType, reader.Value);
        } 
     } 
     finally 
     {
        if (reader != null)
          reader.Close();
      }
  }
コード例 #19
0
    public static void Main()
    {
        XmlNodeReader reader = null;

        try
        {
            //Create and load an XmlDocument.
            XmlDocument doc = new XmlDocument();
            doc.Load("http://localhost/uri.xml");

            reader = new XmlNodeReader(doc);

            //Parse the file and display the base URI for each node.
            while (reader.Read())
            {
                Console.WriteLine("({0}) {1}", reader.NodeType, reader.BaseURI);
            }
        }

        finally
        {
            if (reader != null)
            {
                reader.Close();
            }
        }
    }
コード例 #20
0
    public PmlElement Load(string path)
    {
        TextAsset  xmlFile = Resources.Load <TextAsset>(path);
        PmlElement data;

        if (_loadedElements.TryGetValue(path, out data))
        {
            return(data);
        }

        try
        {
            MemoryStream assetStream = new MemoryStream(xmlFile.bytes);
            XmlReader    reader      = XmlReader.Create(assetStream);
            XmlDocument  xmlDoc      = new XmlDocument();
            xmlDoc.Load(reader);

            XmlNodeReader node = new XmlNodeReader(xmlDoc);
            Debug.Log("XML \'" + path + "\' has loaded.");

            // Read the nodes recursively
            data = new PmlElement();
            ReadNodes(node, data);

            node.Close();

            _loadedElements.Add(path, data);
        }
        catch (Exception ex)
        {
            Debug.LogError("Error loading " + path + ":\n" + ex);
        }

        return(data);
    }
コード例 #21
0
        /// <summary>
        /// Creates the configuration object from the configuration section.
        /// </summary>
        /// <param name="parent">The parent object.</param>
        /// <param name="configContext">The configuration context object.</param>
        /// <param name="section">The section as XML node.</param>
        /// <returns>The created section handler object.</returns>
        public object Create(object parent, object configContext, System.Xml.XmlNode section)
        {
            if (section == null)
            {
                throw new ArgumentNullException("section");
            }

            XmlNode element = section.FirstChild;

            while (element != null && !typeof(XmlElement).IsInstanceOfType(element))
            {
                element = element.NextSibling;
            }

            XmlNodeReader reader = new XmlNodeReader(element);

            try
            {
                DataContractSerializer serializer    = new DataContractSerializer(typeof(ConfigurationLocation));
                ConfigurationLocation  configuration = serializer.ReadObject(reader) as ConfigurationLocation;
                return(configuration);
            }
            finally
            {
                reader.Close();
            }
        }
コード例 #22
0
ファイル: UserIdentity.cs プロジェクト: benvert/pfe
        /// <summary>
        /// Initializes the object with a UA identity token
        /// </summary>
        private void Initialize(IssuedIdentityToken token, SecurityTokenSerializer serializer, SecurityTokenResolver resolver)
        {
            if (token == null)
            {
                throw new ArgumentNullException("token");
            }

            string text = new UTF8Encoding().GetString(token.DecryptedTokenData);

            XmlDocument document = new XmlDocument();

            document.InnerXml = text.Trim();
            XmlNodeReader reader = new XmlNodeReader(document.DocumentElement);

            try
            {
                if (document.DocumentElement.NamespaceURI == "urn:oasis:names:tc:SAML:1.0:assertion")
                {
                    SecurityToken samlToken = new SamlSerializer().ReadToken(reader, serializer, resolver);
                    Initialize(samlToken);
                }
                else
                {
                    SecurityToken securityToken = serializer.ReadToken(reader, resolver);
                    Initialize(securityToken);
                }
            }
            finally
            {
                reader.Close();
            }
        }
コード例 #23
0
        private DataSet FromXML(string filename)
        {
            DataSet ds   = new DataSet();
            string  path = string.Empty;

            try {
                path = HttpContext.Current.Request.MapPath(filename);
            } catch {
            }
            XmlDocument xmlDoc  = new XmlDocument();
            bool        xmlLoad = false;

            try {
                xmlDoc.Load(path);
                xmlLoad = true;
            } catch {
            }
            if (xmlLoad)
            {
                XmlNodeReader reader = new XmlNodeReader(xmlDoc);

                ds.ReadXml(reader);
                reader.Close();
            }
            return(ds);
        }
コード例 #24
0
        public void NodeReaderCloseWithEmptyXml()
        {
            var nodeReader = new XmlNodeReader(new XmlDocument());

            nodeReader.Close();
            Assert.Equal(ReadState.Closed, nodeReader.ReadState);
        }
コード例 #25
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            Response.Clear();

            Regex rgxClient = new Regex(@"[0-9]{6}");

            if (!rgxClient.IsMatch(txtBoxClientId.Text))
            {
                div_xml.InnerText = "Please enter a Code Code in format 6 numbers with a leading '0' if needed.";
                return;
            }

            SolCaseService testWebService = new SolCaseService();
            XmlElement     xmlReturn      = testWebService.getClientDocs(txtBoxClientId.Text);

            Globals.xmlDoc = new XmlDocument();
            Globals.xmlDoc = xmlReturn.OwnerDocument;
            XmlReader xmlReader = new XmlNodeReader(Globals.xmlDoc);

            Globals.solcaseDocs = new DataSet();
            Globals.solcaseDocs.ReadXml(xmlReader);

            // populate the client name
            try
            {
                div_clientName.InnerText = Globals.solcaseDocs.Tables["Client"].Rows[0]["CL-NAME"].ToString();
            } catch
            {
                div_clientName.InnerText = "";
            }

            // create an additional column for the dataset
            // create a new dataset table "SolDoc" column to generate the proposed file name if not exists
            if (!Globals.solcaseDocs.Tables["SolDoc"].Columns.Contains("PROPOSED-FILE-NAME"))
            {
                Globals.solcaseDocs.Tables["SolDoc"].Columns.Add("PROPOSED-FILE-NAME", typeof(String));
            }
            // Now populate the new column
            foreach (DataRow row in Globals.solcaseDocs.Tables["SolDoc"].Rows)
            {
                row["PROPOSED-FILE-NAME"] = FileNameCorrector.ToValidFileName(row["HST-DESCRIPTION"].ToString() + "." + row["EXTENSION"].ToString());
            }

            xmlReader.Close();

            // populate the tree view
            TreeViewMatterList.Nodes.Clear();

            foreach (DataRow row in Globals.solcaseDocs.Tables["Matter"].Rows)
            {
                TreeNode matterNode = new TreeNode(row["MT-CODE"].ToString());

                TreeViewMatterList.Nodes.Add(matterNode);
            }

            // clear the grid view
            GridViewClientDocs.DataSource = null;
            GridViewClientDocs.DataBind();
        }
コード例 #26
0
ファイル: source.cs プロジェクト: yashbajra/samples
    public static void Main()
    {
        XmlNodeReader reader = null;

        try
        {
            //Create an XmlNodeReader to read the XmlDocument.
            XmlDocument doc = new XmlDocument();
            doc.Load(filename);
            reader = new XmlNodeReader(doc);

            //Parse the file and display each of the nodes.
            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    Console.Write("<{0}>", reader.Name);
                    break;

                case XmlNodeType.Text:
                    Console.Write(reader.Value);
                    break;

                case XmlNodeType.CDATA:
                    Console.Write(reader.Value);
                    break;

                case XmlNodeType.ProcessingInstruction:
                    Console.Write("<?{0} {1}?>", reader.Name, reader.Value);
                    break;

                case XmlNodeType.Comment:
                    Console.Write("<!--{0}-->", reader.Value);
                    break;

                case XmlNodeType.XmlDeclaration:
                    Console.Write("<?xml version='1.0'?>");
                    break;

                case XmlNodeType.Document:
                    break;

                case XmlNodeType.EndElement:
                    Console.Write("</{0}>", reader.Name);
                    break;
                }
            }
        }

        finally
        {
            if (reader != null)
            {
                reader.Close();
            }
        }
    }
コード例 #27
0
ファイル: DataSource.cs プロジェクト: steev90/opendental
        ///<summary></summary>
        private static string GetOpenDentalConnStr()
        {
            XmlDocument document = new XmlDocument();
            string      path     = Application.StartupPath + "\\" + "FreeDentalConfig.xml";

            //MessageBox.Show(path);
            if (!File.Exists(path))
            {
                return("");
            }
            string computerName = "";
            string database     = "";
            string user         = "";
            string password     = "";

            try{
                document.Load(path);
                XmlNodeReader reader         = new XmlNodeReader(document);
                string        currentElement = "";
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        currentElement = reader.Name;
                    }
                    else if (reader.NodeType == XmlNodeType.Text)
                    {
                        switch (currentElement)
                        {
                        case "ComputerName":
                            computerName = reader.Value;
                            break;

                        case "Database":
                            database = reader.Value;
                            break;

                        case "User":
                            user = reader.Value;
                            break;

                        case "Password":
                            password = reader.Value;
                            break;
                        }
                    }
                }
                reader.Close();
            }
            catch {
                return("");
            }
            return("Server=" + computerName
                   + ";Database=" + database
                   + ";User ID=" + user
                   + ";Password="******";CharSet=utf8");
        }
コード例 #28
0
        /// <summary>
        /// 获取一个字符串xml文档中的ds
        /// </summary>
        /// <param name="xml_string">含有xml信息的字符串</param>
        public static void get_XmlValue_ds(string xml_string, ref DataSet ds)
        {
            XmlDocument   xd  = XMLLoad(xml_string);
            XmlNodeReader xnr = new XmlNodeReader(xd);

            ds.ReadXml(xnr);
            xnr.Close();
            int a = ds.Tables.Count;
        }
コード例 #29
0
        /// <summary>
        /// Loads the image editors.
        /// </summary>
        public void Load()
        {
            if (Directory.Exists(FileSystem.ApplicationFolder) &&
                File.Exists(FileSystem.ApplicationFolder + FileSystem.EditorsFile))
            {
                XmlDocument xDoc = new XmlDocument();
                xDoc.Load(FileSystem.ApplicationFolder + FileSystem.EditorsFile);

                AppVersion  = xDoc.SelectSingleNode("/autoscreen").Attributes["app:version"]?.Value;
                AppCodename = xDoc.SelectSingleNode("/autoscreen").Attributes["app:codename"]?.Value;

                XmlNodeList xEditors = xDoc.SelectNodes(EDITOR_XPATH);

                foreach (XmlNode xEditor in xEditors)
                {
                    Editor        editor  = new Editor();
                    XmlNodeReader xReader = new XmlNodeReader(xEditor);

                    while (xReader.Read())
                    {
                        if (xReader.IsStartElement())
                        {
                            switch (xReader.Name)
                            {
                            case EDITOR_NAME:
                                xReader.Read();
                                editor.Name = xReader.Value;
                                break;

                            case EDITOR_APPLICATION:
                                xReader.Read();
                                editor.Application = xReader.Value;
                                break;

                            case EDITOR_ARGUMENTS:
                                xReader.Read();
                                editor.Arguments = xReader.Value;
                                break;
                            }
                        }
                    }

                    xReader.Close();

                    if (!string.IsNullOrEmpty(editor.Name) &&
                        !string.IsNullOrEmpty(editor.Application))
                    {
                        Add(editor);
                    }
                }

                if (Settings.VersionManager.IsOldAppVersion(AppVersion, AppCodename))
                {
                    Save();
                }
            }
        }
コード例 #30
0
        /// <summary>
        /// Deserializes this xml document and convert it to a ChmProject object.
        /// </summary>
        /// <returns>The ChmProject object readed from the xml.</returns>
        public ChmProject Deserialize()
        {
            XmlReader     reader     = new XmlNodeReader(this);
            XmlSerializer serializer = new XmlSerializer(typeof(ChmProject));
            ChmProject    cfg        = (ChmProject)serializer.Deserialize(reader);

            reader.Close();
            return(cfg);
        }
コード例 #31
0
    /// <summary>
    /// Retrieves data from SharePoint server using web services.
    /// </summary>
    /// <returns>Dataset or XmlNode</returns>
    protected object GetSharePointData()
    {
        #region "Prepare credentials for authentication"

        ICredentials credentials = null;

        // If there are data in username or password use it for authentication
        if (String.IsNullOrEmpty(Username) && String.IsNullOrEmpty(Password))
        {
            credentials = SharePointFunctions.GetSharePointCredetials();
        }
        else
        {
            credentials = SharePointFunctions.GetSharePointCredetials(Username, Password, useBase64Encoding);
        }

        #endregion

        #region "Retrieve SharePoint data"

        string serviceURL = SPServiceURL;

        // If not direct web service specified, determine web service URL by mode
        if (!serviceURL.EndsWithCSafe(".asmx", true))
        {
            // Remove trailing slash
            serviceURL = serviceURL.TrimEnd('/');

            switch (Mode.ToLowerCSafe())
            {
                case MODE_LIST_ITEMS:
                case MODE_SITE_LISTS:
                    serviceURL += "/_vti_bin/lists.asmx";
                    break;

                case MODE_PICTURE_LIBRARIES:
                case MODE_PICTURE_LIBRARY_ITEMS:
                    serviceURL += "/_vti_bin/imaging.asmx";
                    break;
            }
        }

        // Query web service
        try
        {
            Lists spLists;
            Imaging spImaging;

            switch (Mode.ToLowerCSafe())
            {
                    // Load list items
                case MODE_LIST_ITEMS:

                    // Instantiate Lists service
                    spLists = new Lists(serviceURL);
                    spLists.Credentials = credentials;

                    camlData = LoadListItems(spLists, ListName);
                    break;

                    // Load site lists
                case MODE_SITE_LISTS:
                    // Instantiate Lists service
                    spLists = new Lists(serviceURL);
                    spLists.Credentials = credentials;

                    // Get all SharePoint lists
                    camlData = spLists.GetListCollection();
                    break;

                    // Load picture libraries
                case MODE_PICTURE_LIBRARIES:
                    // Instantiate imaging service
                    spImaging = new Imaging(serviceURL);
                    spImaging.Credentials = credentials;

                    // Get picture libraries
                    camlData = spImaging.ListPictureLibrary();
                    break;

                    // Load picture library items
                case MODE_PICTURE_LIBRARY_ITEMS:
                    // Instantiate imaging service
                    spImaging = new Imaging(serviceURL);
                    spImaging.Credentials = credentials;

                    // Show error if library name empty
                    if (String.IsNullOrEmpty(ListName))
                    {
                        DisplayError(ResHelper.GetString("SharePoint.picslibunspecified"));
                        break;
                    }

                    // Get pictures in libraries, directly (not in folder)
                    camlData = spImaging.GetListItems(ListName, null);
                    break;
            }
        }
        catch (Exception ex)
        {
            DisplayError(ResHelper.GetString("sharepoint.erroradta") + ResHelper.Colon + " " + ex.Message);
        }

        // No data
        if (camlData == null)
        {
            return null;
        }

        #endregion

        #region "Prepare data"

        // Use of XSLT transformation
        if (!UseClassicDataset)
        {
            dataSource = camlData;
        }
        // Use of classic dataset
        else
        {
            // Prepare dataset
            DataSet ds = new DataSet();

            // If datset fields are specified
            if (!String.IsNullOrEmpty(Fields))
            {
                DataTable dt = ds.Tables.Add();

                string[] fields = Fields.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

                foreach (string field in fields)
                {
                    string currentField = field.Trim();
                    if (!string.IsNullOrEmpty(currentField))
                    {
                        try
                        {
                            dt.Columns.Add(field.Trim());
                        }
                        catch (DuplicateNameException)
                        {
                            mErrorMessage = ResHelper.GetString("sharepoint.duplicateField");
                        }
                    }
                }

                XmlNodeList records = GetDataRecords(camlData);

                List<string> fieldsCheck = new List<string>();
                fieldsCheck.AddRange(fields);

                // Load items to dataset
                foreach (XmlNode record in records)
                {
                    DataRow dr = dt.NewRow();

                    // Add fields
                    foreach (string field in fields)
                    {
                        string currentField = field.Trim();
                        if (!string.IsNullOrEmpty(currentField))
                        {
                            XmlAttribute attr = record.Attributes[currentField];
                            if (attr != null)
                            {
                                dr[currentField] = attr.Value;

                                // At least one record has the field
                                fieldsCheck.Remove(field);
                            }
                        }
                    }

                    dt.Rows.Add(dr);
                }

                // None of retrieved records has fields
                if (fieldsCheck.Count > 0)
                {
                    DisplayError(String.Format(ResHelper.GetString("sharepoint.fieldnotFound"), fieldsCheck[0]));
                    return null;
                }

                // Set daatsource
                dataSource = ds;
            }
            // No fields specified, use all fields
            else
            {
                // Only if CAML contains data record, otherwise dataset would contain wrong values
                if (HasData)
                {
                    camlData.InnerXml = SpecialCharsRegex.Replace(camlData.InnerXml, "_");
                    XmlNodeReader rd = new XmlNodeReader(camlData);
                    ds.ReadXml(rd);
                    rd.Close();

                    switch (Mode.ToLowerCSafe())
                    {
                            // Use last datatable as datasource
                        case MODE_LIST_ITEMS:

                            dataSource = ds.Tables[ds.Tables.Count - 1].DefaultView;
                            break;

                            // Filter hidden lists in dataset
                        case MODE_SITE_LISTS:
                            // Dataset structure changes based on xml, try to use last data table
                            DataTable dt = ds.Tables[ds.Tables.Count - 1];

                            // Show only visible lists
                            dt.DefaultView.RowFilter = "Hidden = 'False'";
                            dataSource = dt.DefaultView;
                            break;

                            // Dateset with picture libraries
                        case MODE_PICTURE_LIBRARIES:
                            dataSource = ds.Tables[ds.Tables.Count - 1].DefaultView;
                            break;

                            // Dataset with pictures
                        case MODE_PICTURE_LIBRARY_ITEMS:
                            dataSource = ds.Tables[ds.Tables.Count - 1].DefaultView;
                            break;
                    }
                }
            }
        }

        #endregion

        ShowRawResponse(camlData);

        return dataSource;
    }