modernmobile
New Member
I try to get some specific values from an xml config. See example below.\[code\]<?xml version="1.0" encoding="utf-8"?><ExcelConfig> <ExcelDocument name="Customer" type="flat"> <IdentityColumn> <Column name="Id" /> </IdentityColumn> <Validate> <Column name="Name" mandatory="true" /> <Column name="FirstName" mandatory="true" /> <OrColumns mandatory="true"> <Column name="PostalCode" mandatory="false" /> <Column name="PostalCode2" mandatory="false" /> </OrColumns> </Validate> </ExcelDocument> <ExcelDocument name="Company" type="flat"> <IdentityColumn> <Column name="Id" /> </IdentityColumn> <Validate> <Column name="Name" mandatory="true" /> <Column name="FirstName" mandatory="true" /> <OrColumns mandatory="true"> <Column name="PostalCode" mandatory="false" /> <Column name="PostalCode2" mandatory="false" /> </OrColumns> </Validate> </ExcelDocument> <ExcelDocument name="SomeOtherType" type="block"> <IdentityBlock> <Column name="Period" col="A" /> <Column name="Period2" col="B" /> </IdentityBlock> <Validate> <Column name="Name" mandatory="true" /> <Column name="FirstName" mandatory="true" /> </Validate> </ExcelDocument></ExcelConfig>\[/code\]I use the following code to get some information from the excel file. "ValidationConfiguration" is the string with the previous configuration. \[code\] //Get Different NodeTypes of Excel documents List<XPathNavigator> types = XmlHelper.GetNodeTypes(validationConfiguration, "/ExcelConfig/ExcelDocument"); List<XPathNavigator> flatTypes = XmlHelper.GetNodeTypes(validationConfiguration, "//ExcelConfig/ExcelDocument[@type='flat']"); List<XPathNavigator> blockTypes = XmlHelper.GetNodeTypes(validationConfiguration, "//ExcelConfig/ExcelDocument[@type='block']"); //First we check if the file is from the flat type and get the IdentityColumns List<XPathNavigator> identityColumnsNode = XmlHelper.GetNodeTypes(validationConfiguration, "//ExcelConfig/ExcelDocument[@type='flat']/IdentityColumn");\[/code\]You can find the XmlHelper class below.\[code\] public static class XmlHelper { public static List<XPathNavigator> GetNodeTypes(string xmlConfiguration,string xPath) { XPathDocument doc = new XPathDocument(new StringReader(xmlConfiguration)); XPathNavigator nav = doc.CreateNavigator(); XPathExpression expr = nav.Compile(xPath); List<XPathNavigator> elements = new List<XPathNavigator>(); foreach (XPathNavigator node in nav.Select(expr)) { elements.Add(node); } return elements; } public static List<string> GetIdentityColumnNames(List<XPathNavigator> xPathNavigators) { List<string> identityColumns = new List<string>(); foreach (XPathNavigator xPathNavigator in xPathNavigators) { foreach (XPathNavigator test in xPathNavigator.Select("//Column")) { identityColumns.Add(test.GetAttribute("name", "")); } } return identityColumns; } }\[/code\]Now i want to do the following. I selected the identityColumnsNodes(they contains the IdentityColumn from the exceldocuments that have the flat type).The i get for al that types the colums. But when i try that, i get all columns back from the whole file. He don't only the items from the node that i use.\[code\] foreach (XPathNavigator identityColumNode in identityColumnsNode) { List<string> identityColumns = XmlHelper.GetIdentityColumnNames(identityColumnsNode); }\[/code\]The second problem/thing i want to do --> the best way to select the right validate node from the specific file. With the identityColumns (that i get back and my list of HeaderRow Cells i know what file it is. But how can i select that validate node?Or are their better methods to do this stuff?