web-dev-qa-db-fra.com

Comment lire une chaîne xml dans le type XMLTextReader

J'ai une chaîne XML. J'ai besoin de convertir cette chaîne en type XMLTextReader (System.Xml.XMLTextReader) dans dotnet.

J'ai utilisé le code suivant:

string szInputXml = "<TestDataXml><DataName>testing</DataName></TestDataXml>" ;
XmlTextReader reader = new XmlTextReader(new System.IO.StringReader(szInputXml));

Mais la chaîne à l'intérieur de reader est vide après exécution.

Veuillez m'aider à comprendre ce qui doit être fait pour que le XMLTextReader soit rempli avec la chaîne donnée.

19
osum

Comment déterminez-vous si la chaîne est vide?

string szInputXml = "<TestDataXml><DataName>testing</DataName></TestDataXml>";
XmlTextReader reader = new XmlTextReader( new System.IO.StringReader( szInputXml ) );
reader.Read();
string inner = reader.ReadInnerXml();

Sans la 3ème ligne "intérieure" était en effet vide. Maintenant, il contient des tests.

39
dzendras