question

AkashJagtap-1178 avatar image
0 Votes"
AkashJagtap-1178 asked ·

How to parse XML tag which contains underscore in it.

Hi Team,

I am tring to parse the XML file which contains some XML tag with Underscore in it .

for example.

 <Betalningsmottagares_x0020_postnr>401 01</Betalningsmottagares_x0020_postnr>
 <Betalningsmottagares_x0020_postort>Göteborg</Betalningsmottagares_x0020_postort>

I have tried encoding for swedish language character but i am not sure how should i parse the XML tag contains undersocre.
Please guid me for detail solution

         var xmlSerializer = new XmlSerializer(typeof(DocumentElement));
         StreamReader reader = new StreamReader(stream, Encoding.UTF8);
         var AutoGiroFile = xmlSerializer.Deserialize(reader) as DocumentElement;
dotnet-aspnetcore-mvc
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

YitzhakKhabinsky-0887 avatar image
0 Votes"
YitzhakKhabinsky-0887 answered ·

Hi @AkashJagtap-1178,

XML prolog has encoding attribute to specify character sets from different languages.
By default it is UTF-8.

Underscore is absolutely legit in XML element names.
Spaces are not legit in XML element names.

What exactly the problem?

Please see below a legit XML.

 <?xml version="1.0" encoding="UTF-8"?>
 <root>
  <Betalningsmottagares_x0020_postnr>401 01</Betalningsmottagares_x0020_postnr>
  <Betalningsmottagares_x0020_postort>Göteborg</Betalningsmottagares_x0020_postort>
 </root>
·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.