private XmlNoNamespaceWriter(XmlWriter xmlWriter)
        {
            mAttributeStack = new Stack<bool>();
            mStripNextString = false;

            mXmlWriter = xmlWriter;
            mAddNamespace = mXmlWriter.GetType().GetMethod("AddNamespace", BindingFlags.NonPublic | BindingFlags.Instance);
        }
Example #2
0
 /// <summary>
 /// Writes an XML Element with Attributes using a Dictionary of items.
 /// </summary>
 /// <param name="writer">Writer that has the assigned file location</param>
 /// <param name="tag">Xml Open Tag</param>
 /// <param name="attributePool">Dictionary of your attributes ["Key" Being your attirbute name and "Value" being it's value]</param>
 /// <param name="descriptionValue">Element Description Value</param>
 public void XmlWriteAttributeElement(XmlWriter writer, string tag, Dictionary<string, string> attributePool, string descriptionValue)
 {
     if (writer != null)
     {
         writer.WriteStartElement(tag);
         foreach (KeyValuePair<string, string> kvp in attributePool)
         {
             writer.WriteAttributeString(kvp.Key, kvp.Value);
         }
         writer.WriteString(descriptionValue);
         writer.WriteEndElement();
     }
     else
     {
         throw new ArgumentNullException(writer.GetType().Name, "Writer is Null, please generate one using XmlWriter.Create().");
     }
 }
        public override void WriteTo(XmlWriter w)
        {
            if (positionXmlDocument.oldWriter != w)
            {
                try
                {
                    positionXmlDocument.oldWriter = w;
                    positionXmlDocument.lineCnt = 0;
                    positionXmlDocument.linePositionPrevious = 0;

                    var xmlWriterField = w.GetType()
                        .GetField("xmlWriter", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
                    if (xmlWriterField != null)
                    {
                        var xmlwriter = xmlWriterField.GetValue(w);
                        var rawTextWPrp = xmlwriter.GetType()
                            .GetProperty("InnerWriter", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
                        var rawTextW = rawTextWPrp.GetValue(xmlwriter, null);
                        var bufCharsField = rawTextW.GetType()
                            .GetField("bufChars", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
                        var contentPosField = rawTextW.GetType()
                            .GetField("contentPos", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
                        var buffPosField = rawTextW.GetType()
                            .GetField("bufPos", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
                        var ioTextWriterField = rawTextW.GetType()
                            .GetField("writer", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
                        var ioTextWriter = ioTextWriterField.GetValue(rawTextW);
                        var sbField = ioTextWriter.GetType()
                            .GetField("_sb", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
                        positionXmlDocument.writerSb = sbField.GetValue(ioTextWriter) as StringBuilder;

                        positionXmlDocument.bufGetter =
                            Expression.Lambda<Func<char[]>>(Expression.Field(Expression.Constant(rawTextW), bufCharsField)).Compile();
                        positionXmlDocument.contentPosFieldGetter =
                            Expression.Lambda<Func<int>>(Expression.Field(Expression.Constant(rawTextW), contentPosField)).Compile();
                        positionXmlDocument.buffPosGetter =
                            Expression.Lambda<Func<int>>(Expression.Field(Expression.Constant(rawTextW), buffPosField)).Compile();
                    }
                }
                catch(Exception)
                { }
            }

            if (positionXmlDocument.bufGetter != null && positionXmlDocument.buffPosGetter != null &&
                positionXmlDocument.writerSb != null)
            {
                try
                {
                    var buff = positionXmlDocument.bufGetter();
                    var pos = positionXmlDocument.buffPosGetter();
                    for (int n = pos; n >= positionXmlDocument.lastCharacterPos; n--)
                    {
                        if (buff[n] == '\n')
                        {
                            positionXmlDocument.lineCnt++;
                        }
                    }

                    this.xamlElementLineInfo = new XamlElementLineInfo(positionXmlDocument.lineCnt + 1,
                        pos + 1 + positionXmlDocument.writerSb.Length);

                    if (buff[pos - 1] != '>')
                        this.xamlElementLineInfo.LinePosition++;

                    this.xamlElementLineInfo.Position = pos + positionXmlDocument.writerSb.Length;
                }
                catch (Exception)
                {
                }
            }

            base.WriteTo(w);

            if (positionXmlDocument.bufGetter != null && positionXmlDocument.buffPosGetter != null &&
                positionXmlDocument.writerSb != null)
            {
                try
                {
                    var pos = positionXmlDocument.buffPosGetter();
                    this.xamlElementLineInfo.Length = pos + positionXmlDocument.writerSb.Length - this.xamlElementLineInfo.Position;
                }
                catch (Exception)
                {
                }
            }
        }
Example #4
0
 public void XmlWriteAttributeElement(XmlWriter writer, string tag, string attributeTag, string attributeValue, string descriptionValue)
 {
     if (writer != null)
     {
         writer.WriteStartElement(tag);
         writer.WriteAttributeString(attributeTag, attributeValue);
         writer.WriteString(descriptionValue);
         writer.WriteEndElement();
     }
     else
     {
         throw new ArgumentNullException(writer.GetType().Name, "Writer is Null, please generate one using XmlWriter.Create().");
     }
 }