xml标签属性是字符串内容如何加双引号
How to add double quotes to the xml tag attributes that is a string content
我有一个 xml 字符串内容,在解析它之前,我想在标签属性中添加双引号,以便它有效 xml:
"<fields>
<f id=page-number>OP</f>
<f id=presenter>MA</f>
<f id=title>OPENER</f>
<f id=type>CLIP</f>
<f id=graphic></f>
<f id=video-id></f>
<f id=audiochannel></f>
<f id=event-status></f>
<f id=audio-time uec>26</f>
<f id=back-time uec>@41410</f>
<f id=editor></f>
<f id=total-time>26</f>
<f id=cume-time></f>
<f id=still-id></f>
<f id=app1-1>SF</f>
<f id=var-3></f>
<f id=modify-by>scrivensl</f>
<f id=modify-date>1571272301</f>
<f id=status>OK</f>
<f id=app3-1></f>
<f id=air-date>1571272300</f>
</fields>"
List<string> patternList = new List<string>() { @"<fields[^>]*>([\s\S]*)</fields>"};
foreach (var item in patternList)
{
matchedContent = getContent(item, xmlData);
XElement xmlTree = XElement.Parse(matchedContent);
}
我想在解析之前为标签属性添加双引号,代码仍在等待中。
public string getContent(string patternToMatch, string content)
{
// Instantiate the regular expression object.
Regex r = new Regex(patternToMatch, RegexOptions.IgnoreCase);
return r.Match(content).ToString();
}
你的文字不是HTML,但仍然HtmAgilityPack可以用来规范化它。
var orgxml = @"<fields>
<f id=page-number>OP</f>
...
<f id=app3-1></f>
<f id=air-date>1571272300</f>
</fields>";
var doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(orgxml);
string cleanxml;
using (var sw = new StringWriter())
{
doc.Save(sw);
cleanxml = sw.ToString();
}
cleanxml
现在包含
<fields>
<f id="page-number">OP</f>
...
<f id="app3-1"></f>
<f id="air-date">1571272300</f>
</fields>
我有一个 xml 字符串内容,在解析它之前,我想在标签属性中添加双引号,以便它有效 xml:
"<fields>
<f id=page-number>OP</f>
<f id=presenter>MA</f>
<f id=title>OPENER</f>
<f id=type>CLIP</f>
<f id=graphic></f>
<f id=video-id></f>
<f id=audiochannel></f>
<f id=event-status></f>
<f id=audio-time uec>26</f>
<f id=back-time uec>@41410</f>
<f id=editor></f>
<f id=total-time>26</f>
<f id=cume-time></f>
<f id=still-id></f>
<f id=app1-1>SF</f>
<f id=var-3></f>
<f id=modify-by>scrivensl</f>
<f id=modify-date>1571272301</f>
<f id=status>OK</f>
<f id=app3-1></f>
<f id=air-date>1571272300</f>
</fields>"
List<string> patternList = new List<string>() { @"<fields[^>]*>([\s\S]*)</fields>"};
foreach (var item in patternList)
{
matchedContent = getContent(item, xmlData);
XElement xmlTree = XElement.Parse(matchedContent);
}
我想在解析之前为标签属性添加双引号,代码仍在等待中。
public string getContent(string patternToMatch, string content)
{
// Instantiate the regular expression object.
Regex r = new Regex(patternToMatch, RegexOptions.IgnoreCase);
return r.Match(content).ToString();
}
你的文字不是HTML,但仍然HtmAgilityPack可以用来规范化它。
var orgxml = @"<fields>
<f id=page-number>OP</f>
...
<f id=app3-1></f>
<f id=air-date>1571272300</f>
</fields>";
var doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(orgxml);
string cleanxml;
using (var sw = new StringWriter())
{
doc.Save(sw);
cleanxml = sw.ToString();
}
cleanxml
现在包含
<fields>
<f id="page-number">OP</f>
...
<f id="app3-1"></f>
<f id="air-date">1571272300</f>
</fields>