我可以获取标签中值的长度吗
Can I get the length of the values in a tag
我有一个 XML 开头的文件:
<!DOCTYPE html>
<!-- This is a simple page with no bean -->
<html lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>Combo boxes page</title>
</h:head>
为了处理此文件,我正在做的是:
XElement root = (XElement.Load(fileName, LoadOptions.SetLineInfo | LoadOptions.PreserveWhitespace));
一旦我有了根,我能得到里面的文字长度吗? (HTML 语言...)
您想要从开始 html 标记 (<html...
) 开始到结束 html 标记 (</html>
) 的字符串长度吗?
XElement root = (XElement.Load(fileName ,LoadOptions.SetLineInfo | LoadOptions.PreserveWhitespace));
int htmlLength = root.ToString().Length;
System.Diagnostics.Debug.WriteLine("length of string including html tags: " + htmlLength);
或者您想要 html 标签之间字符串的长度?
String html = root.ToString();
int indexOpeningTag = html.IndexOf(">")+1;
String contentInHtmlTags = html.Substring(indexOpeningTag, html.IndexOf("</html>") - indexOpeningTag);
System.Diagnostics.Debug.WriteLine("length of string between html tags: " + contentInHtmlTags.Length);
我有一个 XML 开头的文件:
<!DOCTYPE html>
<!-- This is a simple page with no bean -->
<html lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>Combo boxes page</title>
</h:head>
为了处理此文件,我正在做的是:
XElement root = (XElement.Load(fileName, LoadOptions.SetLineInfo | LoadOptions.PreserveWhitespace));
一旦我有了根,我能得到里面的文字长度吗? (HTML 语言...)
您想要从开始 html 标记 (<html...
) 开始到结束 html 标记 (</html>
) 的字符串长度吗?
XElement root = (XElement.Load(fileName ,LoadOptions.SetLineInfo | LoadOptions.PreserveWhitespace));
int htmlLength = root.ToString().Length;
System.Diagnostics.Debug.WriteLine("length of string including html tags: " + htmlLength);
或者您想要 html 标签之间字符串的长度?
String html = root.ToString();
int indexOpeningTag = html.IndexOf(">")+1;
String contentInHtmlTags = html.Substring(indexOpeningTag, html.IndexOf("</html>") - indexOpeningTag);
System.Diagnostics.Debug.WriteLine("length of string between html tags: " + contentInHtmlTags.Length);