Exemple #1
0
 /// <summary>
 /// Ensures a meta charset (html) or xml declaration (xml) with the current
 /// encoding used.
 /// </summary>
 /// <remarks>
 /// Ensures a meta charset (html) or xml declaration (xml) with the current
 /// encoding used. This only applies with
 /// <see cref="UpdateMetaCharsetElement(bool)">updateMetaCharset</see>
 /// set to
 /// <tt>true</tt>, otherwise this method does nothing.
 /// <list type="bullet">
 /// <item><description>An exsiting element gets updated with the current charset
 /// </description></item>
 /// <item><description>If there's no element yet it will be inserted
 /// </description></item>
 /// <item><description>Obsolete elements are removed
 /// </description></item>
 /// </list>
 /// <b>Elements used:</b>
 /// <list type="bullet">
 /// <item><description><b>Html:</b> <i>&lt;meta charset="CHARSET"&gt;</i>
 /// </description></item>
 /// <item><description><b>Xml:</b> <i>&lt;?xml version="1.0" encoding="CHARSET"&gt;</i>
 /// </description></item>
 /// </list>
 /// </remarks>
 private void EnsureMetaCharsetElement()
 {
     if (updateMetaCharset)
     {
         iText.StyledXmlParser.Jsoup.Nodes.Syntax syntax = OutputSettings().Syntax();
         if (syntax == iText.StyledXmlParser.Jsoup.Nodes.Syntax.html)
         {
             iText.StyledXmlParser.Jsoup.Nodes.Element metaCharset = Select("meta[charset]").First();
             if (metaCharset != null)
             {
                 metaCharset.Attr("charset", Charset().DisplayName());
             }
             else
             {
                 iText.StyledXmlParser.Jsoup.Nodes.Element head = Head();
                 if (head != null)
                 {
                     head.AppendElement("meta").Attr("charset", Charset().DisplayName());
                 }
             }
             // Remove obsolete elements
             Select("meta[name=charset]").Remove();
         }
         else
         {
             if (syntax == iText.StyledXmlParser.Jsoup.Nodes.Syntax.xml)
             {
                 iText.StyledXmlParser.Jsoup.Nodes.Node node = ChildNodes()[0];
                 if (node is XmlDeclaration)
                 {
                     XmlDeclaration decl = (XmlDeclaration)node;
                     if (decl.Name().Equals("xml"))
                     {
                         decl.Attr("encoding", Charset().DisplayName());
                         String version = decl.Attr("version");
                         if (version != null)
                         {
                             decl.Attr("version", "1.0");
                         }
                     }
                     else
                     {
                         decl = new XmlDeclaration("xml", baseUri, false);
                         decl.Attr("version", "1.0");
                         decl.Attr("encoding", Charset().DisplayName());
                         PrependChild(decl);
                     }
                 }
                 else
                 {
                     XmlDeclaration decl = new XmlDeclaration("xml", baseUri, false);
                     decl.Attr("version", "1.0");
                     decl.Attr("encoding", Charset().DisplayName());
                     PrependChild(decl);
                 }
             }
         }
     }
 }
Exemple #2
0
 /// <summary>Set the document's output syntax.</summary>
 /// <remarks>
 /// Set the document's output syntax. Either
 /// <c>html</c>
 /// , with empty tags and boolean attributes (etc), or
 /// <c>xml</c>
 /// , with self-closing tags.
 /// </remarks>
 /// <param name="syntax">serialization syntax</param>
 /// <returns>the document's output settings, for chaining</returns>
 public virtual iText.StyledXmlParser.Jsoup.Nodes.OutputSettings Syntax(iText.StyledXmlParser.Jsoup.Nodes.Syntax
                                                                        syntax)
 {
     this.syntax = syntax;
     return(this);
 }