Reputation: 3563
Need to verify the XML:
>
", "<
", "&
", because they are forbidden, but allowed in &xHEX
, where HEX is a number in the the 16th notation.I think that I need to create XDocument
like:
static void Main(string[] args)
{
string s = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<!--This is a comment.-->" +
"<?xml-stylesheet href='mystyle.css' title='Compact' type='text/css'?>" +
"<Pubs>" +
"<Book>" +
"<Title>Artifacts of Roman Civilization</Title>" +
"<Author>Moreno, Jordao</Author>" +
"</Book>" +
"<Book>" +
"<Title>Midieval Tools and Implements</Title>" +
"<Author>Gazit, Inbar</Author>" +
"</Book>" +
"</Pubs>" +
"<!--This is another comment.-->";//= Console.ReadLine();
try
{
XDocument xDoc = XDocument.Parse(s);
xDoc.Save("C://22.xml");
Console.WriteLine("Valid");
}
catch
{
Console.WriteLine("Invalid");
}
}
Is there anything similar XDocument.Parse(s)
for Framework 2
?
Upvotes: 0
Views: 52
Reputation: 125630
XDocument
and entire LINQ to XML was introduced in .NET 3.5
If you're using .NET Framework 2.0, you should use XmlDocument
:
var doc = new XmlDocument();
doc.LoadXml(s);
doc.Save("C//22.xml");
LoadXml
throws XmlException
when document is invalid and parsing cannot be performed.
Upvotes: 1