Exemplo n.º 1
0
        internal void WritePreservedAttributes(XmlAttributePreservingWriter writer, XmlAttributeCollection attributes)
        {
            string newLineString = null;

            if (this.attributeNewLineString != null)
            {
                newLineString = writer.SetAttributeNewLineString(this.attributeNewLineString);
            }
            try
            {
                foreach (string str2 in this.orderedAttributes)
                {
                    XmlAttribute attribute = attributes[str2];
                    if (attribute != null)
                    {
                        if (this.leadingSpaces.ContainsKey(str2))
                        {
                            writer.WriteAttributeWhitespace(this.leadingSpaces[str2]);
                        }
                        attribute.WriteTo(writer);
                    }
                }
                if (this.leadingSpaces.ContainsKey(string.Empty))
                {
                    writer.WriteAttributeTrailingWhitespace(this.leadingSpaces[string.Empty]);
                }
            }
            finally
            {
                if (newLineString != null)
                {
                    writer.SetAttributeNewLineString(newLineString);
                }
            }
        }
Exemplo n.º 2
0
        public void Apply(DateAndTime dttm)
        {
            StringBuilder date = new StringBuilder();

            date.Append(String.Format("{0:0000}", dttm.yr));
            date.Append("-");
            date.Append(String.Format("{0:00}", dttm.mon));
            date.Append("-");
            date.Append(String.Format("{0:00}", dttm.dom));
            date.Append("T");
            date.Append(String.Format("{0:00}", dttm.hr));
            date.Append(":");
            date.Append(String.Format("{0:00}", dttm.mint));
            date.Append(":00Z");

            XmlAttribute xml = _nodeFactory.CreateAttribute("w", "date", OpenXmlNamespaces.WordprocessingML);

            xml.Value = date.ToString();

            //append or write
            if (_writer != null)
            {
                xml.WriteTo(_writer);
            }
            else if (_parent != null)
            {
                _parent.Attributes.Append(xml);
            }
        }
Exemplo n.º 3
0
            private void WriteAttributesTo(XmlWriter w)
            {
                XmlAttributeCollection attrs = Attributes;

                for (int i = 0; i < attrs.Count; i += 1)
                {
                    XmlAttribute attr = attrs[i];
                    attr.WriteTo(w);
                }
            }
Exemplo n.º 4
0
        public void WriteTo()
        {
            doc.AppendChild(doc.CreateElement("root"));
            doc.DocumentElement.SetAttribute("attr", string.Empty);
            doc.DocumentElement.Attributes ["attr"].InnerXml = "&ent;";
            StringWriter  sw  = new StringWriter();
            XmlTextWriter xtw = new XmlTextWriter(sw);

            xtw.WriteStartElement("result");
            XmlAttribute attr = doc.DocumentElement.Attributes ["attr"];

            attr.WriteTo(xtw);
            xtw.Close();
            Assert.AreEqual("<result attr=\"&ent;\" />", sw.ToString());
        }
Exemplo n.º 5
0
        internal void WritePreservedAttributes(XmlAttributePreservingWriter writer, XmlAttributeCollection attributes)
        {
            string oldNewLineString = null;

            if (_attributeNewLineString != null)
            {
                oldNewLineString = writer.SetAttributeNewLineString(_attributeNewLineString);
            }

            try
            {
                foreach (string attributeName in _orderedAttributes)
                {
                    XmlAttribute attr = attributes[attributeName];
                    if (attr == null)
                    {
                        continue;
                    }
                    if (_leadingSpaces.ContainsKey(attributeName))
                    {
                        writer.WriteAttributeWhitespace(_leadingSpaces[attributeName]);
                    }

                    attr.WriteTo(writer);
                }

                if (_leadingSpaces.ContainsKey(string.Empty))
                {
                    writer.WriteAttributeTrailingWhitespace(_leadingSpaces[string.Empty]);
                }
            }
            finally
            {
                if (oldNewLineString != null)
                {
                    writer.SetAttributeNewLineString(oldNewLineString);
                }
            }
        }
        internal void WritePreservedAttributes(XmlAttributePreservingWriter writer, XmlAttributeCollection attributes)
        {
            string newLineString = (string)null;

            if (this.attributeNewLineString != null)
            {
                newLineString = writer.SetAttributeNewLineString(this.attributeNewLineString);
            }
            try
            {
                foreach (string key in this.orderedAttributes)
                {
                    XmlAttribute xmlAttribute = attributes[key];
                    if (xmlAttribute != null)
                    {
                        if (this.leadingSpaces.ContainsKey(key))
                        {
                            writer.WriteAttributeWhitespace(this.leadingSpaces[key]);
                        }
                        xmlAttribute.WriteTo((XmlWriter)writer);
                    }
                }
                if (!this.leadingSpaces.ContainsKey(string.Empty))
                {
                    return;
                }
                writer.WriteAttributeTrailingWhitespace(this.leadingSpaces[string.Empty]);
            }
            finally
            {
                if (newLineString != null)
                {
                    writer.SetAttributeNewLineString(newLineString);
                }
            }
        }