Skip to main content

Posts

Showing posts from August, 2018

#XML #C# Read a XML (from a string) and get some fields

string myXML = "<?xml version=\"1.0\" encoding=\"utf-16\"?><myDataz xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><listS> <sog><field1>123</field1><field2>a</field2><field3>b</field3> </sog><sog><field1>456</field1><field2>c</field2><field3>d</field3> </sog></listS></myDataz>" ; XmlDocument xmlDoc = new XmlDocument (); xmlDoc . LoadXml ( xml ); string xpath = "myDataz/listS/sog" ; var nodes = xmlDoc . SelectNodes ( xpath ); foreach ( XmlNode childrenNode in nodes ) {      HttpContext . Current . Response . Write ( childrenNode . SelectSingleNode ( "//field1" ). Value ); } Try :         childrenNode . SelectSingleNode ( "field1" ). Value .InnerText or .InnerXML ----------------------------...

#HTTPRequestHeader- How to get an specific header value from the HttpResponseMessage

How to get an specific header value from the HttpResponseMessage You should be able to use the TryGetValues method. HttpHeaders headers = response . Headers ; IEnumerable <string> values ; if ( headers . TryGetValues ( "X-BB-SESSION" , out values )) {         string session = values . First (); } Note: First() is an extension method; include System.Linq to get access to it.