You can parse string to XmlDocument object. For example:
string xml = "<?xml version='1.0'?><person firstname='john'
lastname='smith' />";
XmlDocument doc = new XmlDocument();
doc.InnerXml = xml;
XmlElement root = doc.DocumentElement;
Console.WriteLine(" The firstname : {0} lastname: {1}",
root.GetAttribute("firstname"), root.GetAttribute("lastname"));You can refer to the discussion of this trick at http://bytes.com/topic/c-sharp/answers/251022-parsing-xml-string On Wed, Dec 15, 2010 at 3:18 PM, Anchit Kathuria <[email protected]>wrote: > thanks :).. it helped > > On Dec 14, 5:43 pm, Anchit Kathuria <[email protected]> wrote: > > Hi, > > I have got the following XML test in a string variable: > > > > string str is assigned the following value : > > "<Cryptic_GetScreen_Reply><CAPI_Screen><Response>* * * * * * * * * * * > > * PV OFFICE PROFILE * * * * * * * * * * > > AMADEUS OFFICE ID - YYZ6W210X AMID - 288365 > > NATIONAL SYSTEM OFFICE ID - 1S/10019368 > > DATE/TIME - 02NOV10/1239 > > > > * * * * * * * * * * * * OFFICE IDENTIFICATION * * * * * * * * > > CIN*IATA NUMBER - 67906602 - PRIMARY > > ERN*ERSP NUMBER - 00000000 > > CCO*CALL CENTER OFFICE - NO > > * * * * * * * * * * * * GENERAL DATA * * * * * * * * * * * * > > NAM*OFFICE NAME - CUMBERLAND TRAVEL > > AD1*ADDRESS 1 - 2200 MARKHAM ROAD, UNIT 1 > > AD2*ADDRESS 2 - NONE > > AD3*CITY NAME - SCARBOROUGH, ON M1B 2W4 > > CRP*CORPORATE IMPLANT- NONE > > CTN*COUNTRY NAME - CANADA > > PHO*PHONE PRIMARY - 416 250-6200 > > PH2*PHONE SECONDARY - NONE > > FAX*FAX PRIMARY - 416-250-6205 > > FA2*FAX SECONDARY - NONE > > EML*EMAIL ADDRESS - NONE > > OOH*OPENING HOURS - M 1): OPEN ALL DAY > > )></Response></CAPI_Screen></Cryptic_GetScreen_Reply>" > > > > Now, can you please tell me a way to get the values of various fields > > (in above text) from the string. I have already tried using "split" > > function and Regix function on this string but it was getting too > > complicated. May be there is a way to insert this into an XML Document > > object? I need to insert the VALUES from above string into a DB table > > (using ADO.NET). How can I get only the values from above string? (eg: > > YYZ6W210X, 288365, 1S/10019368 etc.) > -- Man Vuong Ha Thanh Faculty of Software Engineering University of Information Technology, VNU-HCMC Mobile: +84 984 919 728 Email: [email protected] Yahoo! Messenger: [email protected]
