Подскажите кто-нибудь. Имеется 2 xml файла, один содержит список клиентов, другой - список книг. Хочу сделать так, чтобы при вводе имени клиента с консоли проходила проверка xml файла на существование данного имени и, если имя существует, добавление всех данныч клиента в др. xml файл, включая город, паспортные данные, номер телефона.
namespace Library
{
class ClientBook
{
//static string pathXmlClientBook= ConfigurationSettings.AppSettings["XmlDataPath"].ToString();
static string pathXmlBook = ConfigurationSettings.AppSettings["XmlData"].ToString();
static string pathXmlClient = ConfigurationSettings.AppSettings["pathXmlData"].ToString();
public static bool GetClientBook(Man existMan, string message)//возвращаем людей
{
//Открываем FileStream
//FileStream fsClientBook = new FileStream(pathXmlClientBook, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); //указываем путь к файлу.
FileStream fsBook = new FileStream(pathXmlBook, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
FileStream fsClient = new FileStream(pathXmlClient, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
//Создаем Xml документ.
XmlDataDocument xmlDoc = new XmlDataDocument();
//xmlDoc.Load(fsClientBook); //загружаем в память данные из файла xml
xmlDoc.Load(fsBook);
xmlDoc.Load(fsClient);
ArrayList nameClient_nameBook = new ArrayList();
string temp;
for (int i = 0; i < xmlDoc.DocumentElement.ChildNodes.Count; i++)
{
temp = xmlDoc.DocumentElement.ChildNodes[i].SelectSingleNode("name").InnerText +
" " + xmlDoc.DocumentElement.ChildNodes[i].SelectSingleNode("surName").InnerText +
" " + xmlDoc.DocumentElement.ChildNodes[i].SelectSingleNode("nameBook").InnerText;
nameClient_nameBook.Add(temp);
}
//fsClientBook.Close();
fsBook.Close();
fsClient.Close();
//Добавление элементов из одного xml файла в другой
string viborName, viborSurName;
viborName = Console.ReadLine();
viborSurName = Console.ReadLine();
//проверка на существование файла
for (int i = 0; i < xmlDoc.DocumentElement.ChildNodes.Count; i++)
{
if (viborName == xmlDoc.DocumentElement.ChildNodes[i].SelectSingleNode("name").InnerText &&
viborSurName == xmlDoc.DocumentElement.ChildNodes[i].SelectSingleNode("surName").InnerText)
{
FileStream fsClientBook = new FileStream(pathXmlClientBook, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
try
{
using (fsClientBook)
{
xmlDoc.Load(fsClientBook);
//код передачи из одного XML в другой XML
fsClientBook.Close();
}
}
catch
{
message = "Не удалось создать персону";
return false;
}
}
else
{
Console.WriteLine("Книга не может быть добавлена");
}
}
return true;
}
}
}