Xml is Xml. What you really want is to get the same results in c# that you were getting on a different machine. The question is why you are getting a different number of server on the local machine as the remote machine. Are the two machines on the same subnet? Are the two machines running the same operating system (windows/linux)? What you are asking is to run an application on a remote machine and then process results locally. This may be more complicated than to solve the issue why local and remote machines are seeing different number of servers. Seeing different number of servers usually means they are on different subnets. It is possible that you are listening to the wrong ethernet connection on the local machine. To see all the ethernet data you need to make sure you are listening on IP.Any which receives all the subnets.
Try following code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
namespace ConsoleApplication122
{
class Program
{
const string FILENAME = @"c:\temp\test.xml";
static void Main(string[] args)
{
XDocument doc = XDocument.Load(FILENAME);
XElement file = doc.Descendants("file").FirstOrDefault();
var result = file.Elements("group").Select(x => new
{
user = (string)x.Element("properties").Element("name"),
server = x.Elements("group").Select(y => new {
serviceName = (string)y.Element("properties").Element("name"),
locations = y.Elements("group").Select(z => new {
locationName = (string)z.Element("properties").Element("name"),
servers = z.Elements("server").Select(a => new {
displayName = (string)a.Descendants("displayName").FirstOrDefault(),
serverName = (string)a.Descendants("name").FirstOrDefault()
}).ToList()
}).ToList()
}).ToList()
}).ToList();
}
}
}
Here is code loading a Treeview
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Linq;
namespace WindowsFormsApplication48
{
public partial class Form1 : Form
{
const string FILENAME = @"c:\temp\test.xml";
public Form1()
{
InitializeComponent();
XDocument doc = XDocument.Load(FILENAME);
XElement file = doc.Descendants("file").FirstOrDefault();
foreach (XElement xUser in file.Elements("group"))
{
string user = (string)xUser.Element("properties").Element("name");
TreeNode userNode = new TreeNode(user);
treeView1.Nodes.Add(userNode);
foreach (XElement xService in xUser.Elements("group"))
{
string serviceName = (string)xService.Element("properties").Element("name");
TreeNode serviceNode = new TreeNode(serviceName);
userNode.Nodes.Add(serviceNode);
foreach (XElement xLocation in xService.Elements("group"))
{
string locationName = (string)xService.Element("properties").Element("name");
TreeNode locationNode = new TreeNode(locationName);
serviceNode.Nodes.Add(locationNode);
foreach (XElement xServer in xLocation.Elements("server"))
{
string displayName = (string)xServer.Descendants("displayName").FirstOrDefault();
string serverName = (string)xServer.Descendants("name").FirstOrDefault();
TreeNode serverNode = new TreeNode(displayName + "," + serverName);
locationNode.Nodes.Add(serverNode);
}
}
}
}
treeView1.ExpandAll();
}
}
}
Here is recursive code to build the treeview
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Linq;
namespace WindowsFormsApplication48
{
public partial class Form1 : Form
{
const string FILENAME = @"c:\temp\test.xml";
public Form1()
{
InitializeComponent();
XDocument doc = XDocument.Load(FILENAME);
XElement file = doc.Descendants("file").FirstOrDefault();
string name = (string)file.Element("properties").Element("name");
TreeNode fileNode = new TreeNode(name);
treeView1.Nodes.Add(fileNode);
GetTree(file, fileNode);
treeView1.ExpandAll();
}
void GetTree(XElement xParent, TreeNode parentNode)
{
foreach (XElement group in xParent.Elements("group"))
{
string groupName = (string)group.Element("properties").Element("name");
TreeNode groupNode = new TreeNode(groupName);
parentNode.Nodes.Add(groupNode);
GetTree(group, groupNode);
}
foreach (XElement xServer in xParent.Elements("server"))
{
string displayName = (string)xServer.Descendants("displayName").FirstOrDefault();
string serverName = (string)xServer.Descendants("name").FirstOrDefault();
TreeNode serverNode = new TreeNode(displayName + "," + serverName);
parentNode.Nodes.Add(serverNode);
}
}
}
}