Prevent XElement.Attribute().Value from HtmlDecode/-Encode

  Kiến thức lập trình

I am using XmlReader to read/load .xml-files and want to filter out certain strings by Regex. But the Attribute().Value does translate < to < etc., which is not desired. So the question is how prevent it from en-/decoding?

This code snippet should be enough, if not ask me:

Regex rg = new Regex("<font color = '#......'>.*</font>");
var fontStrings = elementList.Where(e=> rg.IsMatch(e.Attribute("target").Value))
                             .SelectMany(e=> rg.Matches(e.Attribute("target").Value)
                                                .Cast<Match>().Select(m => m.Value))
                             .ToArray();

The elementList is a List<XElement>.

Example string:

"testword3<font color = '#2478FF'>[testword1]</font> testword2<font color = '#2478FF'>[testword4]</font>testword5"

FYI: One string can have multiple matches. Manually de/-encoding won’t work because some parts should stay untouched (then i get & which is not desired).

5

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

Prevent XElement.Attribute().Value from HtmlDecode/-Encode

I am using XmlReader to read/load .xml-files and want to filter out certain strings by Regex. But the Attribute().Value does translate < to < etc., which is not desired. So the question is how prevent it from en-/decoding?

This code snippet should be enough, if not ask me:

Regex rg = new Regex("<font color = '#......'>.*</font>");
var fontStrings = elementList.Where(e=> rg.IsMatch(e.Attribute("target").Value))
                             .SelectMany(e=> rg.Matches(e.Attribute("target").Value)
                                                .Cast<Match>().Select(m => m.Value))
                             .ToArray();

The elementList is a List<XElement>.

Example string:

"testword3<font color = '#2478FF'>[testword1]</font> testword2<font color = '#2478FF'>[testword4]</font>testword5"

FYI: One string can have multiple matches. Manually de/-encoding won’t work because some parts should stay untouched (then i get & which is not desired).

5

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

Prevent XElement.Attribute().Value from HtmlDecode/-Encode

I am using XmlReader to read/load .xml-files and want to filter out certain strings by Regex. But the Attribute().Value does translate < to < etc., which is not desired. So the question is how prevent it from en-/decoding?

This code snippet should be enough, if not ask me:

Regex rg = new Regex("<font color = '#......'>.*</font>");
var fontStrings = elementList.Where(e=> rg.IsMatch(e.Attribute("target").Value))
                             .SelectMany(e=> rg.Matches(e.Attribute("target").Value)
                                                .Cast<Match>().Select(m => m.Value))
                             .ToArray();

The elementList is a List<XElement>.

Example string:

"testword3<font color = '#2478FF'>[testword1]</font> testword2<font color = '#2478FF'>[testword4]</font>testword5"

FYI: One string can have multiple matches. Manually de/-encoding won’t work because some parts should stay untouched (then i get & which is not desired).

5

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT