Beispiel #1
0
 /// <summary>
 /// Reads the XML file form the passed stream and processes the shared strings table
 /// </summary>
 /// <param name="stream">Stream of the XML file</param>
 /// <exception cref="IOException">Throws IOException in case of an error</exception>
 public void Read(MemoryStream stream)
 {
     try
     {
         using (stream) // Close after processing
         {
             XmlDocument xr = new XmlDocument();
             xr.Load(stream);
             StringBuilder sb    = new StringBuilder();
             XmlNodeList   nodes = xr.DocumentElement.ChildNodes;
             foreach (XmlNode node in xr.DocumentElement.ChildNodes)
             {
                 if (node.LocalName.ToLower() == "si")
                 {
                     sb.Clear();
                     GetTextToken(node, ref sb);
                     if (sb.Length > 0)
                     {
                         SharedStrings.Add(sb.ToString());
                     }
                 }
             }
         }
     }
     catch (System.Exception ex)
     {
         throw new IOException("XMLStreamException", "The XML entry could not be read from the input stream. Please see the inner exception:", ex);
     }
 }
Beispiel #2
0
 /// <summary>
 /// Reads the XML file form the passed stream and processes the shared strings table
 /// </summary>
 /// <param name="stream">Stream of the XML file</param>
 /// <exception cref="Exceptions.IOException">Throws IOException in case of an error</exception>
 public void Read(Stream stream)
 {
     try
     {
         using (stream) // Close after processing
         {
             XmlDocument xr = new XmlDocument();
             xr.XmlResolver = null;
             xr.Load(stream);
             StringBuilder sb = new StringBuilder();
             foreach (XmlNode node in xr.DocumentElement.ChildNodes)
             {
                 if (node.LocalName.Equals("si", StringComparison.InvariantCultureIgnoreCase))
                 {
                     sb.Clear();
                     GetTextToken(node, ref sb);
                     SharedStrings.Add(sb.ToString());
                 }
             }
         }
     }
     catch (Exception ex)
     {
         throw new IOException("XMLStreamException", "The XML entry could not be read from the " + nameof(stream) + ". Please see the inner exception:", ex);
     }
 }
Beispiel #3
0
        internal int SetSharedString(string value)
        {
            int stringId;

            if (SharedStringIndex.TryGetValue(value, out stringId))
            {
                return(stringId);
            }

            // Add it
            stringId = SharedStrings.Count;
            SharedStrings.Add(value);
            SharedStringIndex.Add(value, stringId);

            return(stringId);
        }
        public void Read(Stream stream)
        {
            SharedStrings.Clear();
            XmlTextReader xr = new XmlTextReader(stream);
            bool          isStringItem = false, isText = false;
            string        item = "";
            string        name;

            while (xr.Read())
            {
                name = xr.Name.ToLower();
                if (name == "si" && xr.IsStartElement() == true)
                {
                    isStringItem = true;
                    continue;
                }
                else if (name == "t" && isStringItem == true)
                {
                    isText = true;
                    continue;
                }
                else if (string.IsNullOrEmpty(name) && isText)
                {
                    item = xr.ReadString();
                    continue;
                }
                else if (name == "si" && isStringItem == true && isText == true)
                {
                    SharedStrings.Add(item);
                    item         = "";
                    isText       = false;
                    isStringItem = false;
                    continue;
                }
            }
        }