I think you should use LINQ-TO-XML to deal with the problem by using Descedants to find out the specific element of xsd and then do outputting like following this:
【Sample & Solution】
namespace CSharp
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
namespace ConsoleApplication7
{
public class Program
{
static void Main(string[] args)
{
var result = from e in XDocument.Load("XMLFile1.xml").Descendants(XNamespace.Get("http://www.w3.org/2001/XMLSchema") + "complexType")
where e.Attribute("name").Value.Equals("EXP")
select e.Descendants(XNamespace.Get("http://www.w3.org/2001/XMLSchema") + "element");
//Loop out all the ComplexType
foreach (var item in result)
{
//Loop out all the element type nested in the Complex type
foreach (var sitem in item)
{
Console.WriteLine(sitem.Attribute("name").Value);
}
}
}
}
}
}
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Help with c# XPath
Apr 30, 2012 01:10 AM|LINK
Hello:)
I think you should use LINQ-TO-XML to deal with the problem by using Descedants to find out the specific element of xsd and then do outputting like following this:
【Sample & Solution】
namespace CSharp { using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml.Linq; namespace ConsoleApplication7 { public class Program { static void Main(string[] args) { var result = from e in XDocument.Load("XMLFile1.xml").Descendants(XNamespace.Get("http://www.w3.org/2001/XMLSchema") + "complexType") where e.Attribute("name").Value.Equals("EXP") select e.Descendants(XNamespace.Get("http://www.w3.org/2001/XMLSchema") + "element"); //Loop out all the ComplexType foreach (var item in result) { //Loop out all the element type nested in the Complex type foreach (var sitem in item) { Console.WriteLine(sitem.Attribute("name").Value); } } } } } }