0

I am having issues with converting string to xml.string is in this format

 String s = "<?xml version="1.0"?><Brands><Brand><BrandID>1</BrandID><BrandName>ABC</BrandName></Brand><Brand><BrandID>2</BrandID><BrandName>DEF</BrandName></Brand></Brands>";

the above string comes as webservice response.

The main problem is when i have string like this with <?xml version="1.0"?> it gives error that "; expected" because of that xml header with "1.0". Rest of the code i have it figured out to convert to xml and all.it doesn't even compile so that i can go further.

 XmlDocument doc = new XmlDocument();
 doc.LoadXml(s);
user2232861
  • 273
  • 2
  • 10
  • 27

2 Answers2

0

You can escape the " with \". So something like:

String s = "<?xml version=\"1.0\"?><Brands>..."
Lily
  • 316
  • 3
  • 10
  • ,I can't.it's coming like that from webservice response with double quotes. – user2232861 May 21 '13 at 18:26
  • It's coming as an invalid string? Can you pass the response straight into the LoadXml? Or can you show us how you're getting the response? – Lily May 21 '13 at 18:39
  • I guess you are right. Right now webservice is not ready and I am hardcoding the string. once it is ready it will be not an issue it seems. – user2232861 May 21 '13 at 18:43
0

Try using a single quote (') instead of a double quote (") around 1.0

Kermit
  • 33,827
  • 13
  • 85
  • 121
Johnny
  • 1