<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                # 解析一個body片斷 <div><h2>問題</h2> <p>假如你有一個HTML片斷 (比如. 一個 <code>div</code> 包含一對 <code>p</code> 標簽; 一個不完整的HTML文檔) 想對它進行解析。這個HTML片斷可以是用戶提交的一條評論或在一個CMS頁面中編輯body部分。</p> <h2>辦法</h2> <p>使用<code><a title="Parse a fragment of HTML, with the assumption that it forms the body of the HTML." href="http://jsoup.org/apidocs/org/jsoup/Jsoup.html#parseBodyFragment%28java.lang.String%29">Jsoup.parseBodyFragment(String html)</a></code>方法.</p> <pre><code>String html = "&lt;div&gt;&lt;p&gt;Lorem ipsum.&lt;/p&gt;"; Document doc = Jsoup.parseBodyFragment(html); Element body = doc.body(); </code></pre> <h2>說明</h2> <p><code>parseBodyFragment</code> 方法創建一個空殼的文檔,并插入解析過的HTML到<code>body</code>元素中。假如你使用正常的 <code><a title="Parse HTML into a Document." href="http://jsoup.org/apidocs/org/jsoup/Jsoup.html#parse%28java.lang.String%29">Jsoup.parse(String html)</a></code> 方法,通常你也可以得到相同的結果,但是明確將用戶輸入作為 body片段處理,以確保用戶所提供的任何糟糕的HTML都將被解析成body元素。</p> <p><code><a title="Accessor to the document's body element." href="http://jsoup.org/apidocs/org/jsoup/nodes/Document.html#body%28%29">Document.body()</a></code> 方法能夠取得文檔body元素的所有子元素,與 <code>doc.getElementsByTag("body")</code>相同。</p> <h2>保證安全Stay safe</h2> <p>假如你可以讓用戶輸入HTML內容,那么要小心避免跨站腳本攻擊。利用基于 <code><a title="Whitelists define what HTML (elements and attributes) to allow through the cleaner." href="http://jsoup.org/apidocs/org/jsoup/safety/Whitelist.html">Whitelist</a></code> 的清除器和 <code><a title="Get safe HTML from untrusted input HTML, by parsing input HTML and filtering it through a white-list of permitted tags and attributes." href="http://jsoup.org/apidocs/org/jsoup/Jsoup.html#clean%28java.lang.String,%20org.jsoup.safety.Whitelist%29">clean(String bodyHtml, Whitelist whitelist)</a></code>方法來清除用戶輸入的惡意內容。</p><br></div>
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看