Hi
When i try to read the following XML file and add it to a treeview i run into problems with two methods
a) text read
b) xml read
The issue is the 2nd line, the <?xml-stylesheet
IF i remove the "<?xml-stylesheet " line, i can get the treeview being populated on,
with it there, no, i found a code sample which used an XML reader and the use of reader.MoveToContent();
however this results in just one node, the top node.
>> I am after pointers how to respove this issue as i don't want to have to manually edit XML files to remove the stylesheet statement.
Thanks in advance
<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="1.xsl"?> <== Problem line<TestRun xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="6b2e3387-1bf0-43b5-bf92-1df31723afca" name="Build@VD-BLDCS 2013-07-05 20:11:46_Win32_Release" runUser="CITSYD\Build" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010"><TestSettings name="BuildServer" id="f02d2bf0-a34b-4093-950a-63f96662b942"> ......
private void xmlview_Load(object sender, EventArgs e) { XmlDocument xmldoc = new XmlDocument(); XmlNode xmlnode; /* This works if ?xml-stylesheet is removed FileStream fs = new FileStream(MainFormClass.MainForm.fileXML.Text, FileMode.Open, FileAccess.Read); xmldoc.Load(fs); */ // This does not work with ?xml-stylesheet in the file , get single node // XmlTextReader reader = new XmlTextReader(MainFormClass.MainForm.fileXML.Text); reader.WhitespaceHandling = WhitespaceHandling.None; reader.MoveToContent(); xmldoc.Load(reader); // xmlnode = xmldoc.ChildNodes[1]; treeView1.Nodes.Clear(); treeView1.Nodes.Add(new TreeNode(xmldoc.DocumentElement.Name)); TreeNode tNode; tNode = treeView1.Nodes[0]; AddNode(xmlnode, tNode); } private void AddNode(XmlNode inXmlNode, TreeNode inTreeNode) { XmlNode xNode; TreeNode tNode; XmlNodeList nodeList; int i = 0; if (inXmlNode.HasChildNodes) { nodeList = inXmlNode.ChildNodes; for (i = 0; i <= nodeList.Count - 1; i++) { xNode = inXmlNode.ChildNodes[i]; inTreeNode.Nodes.Add(new TreeNode(xNode.Name)); tNode = inTreeNode.Nodes[i]; AddNode(xNode, tNode); } } else { inTreeNode.Text = inXmlNode.InnerText.ToString(); } }