0

How would i parse the following, it wont change at least the layout of the line. So I need to be able to get the Query Parmeter value out ie TypeProjectionId and also the value of Name=? does anybody have any ideas at all?

I am using this to get the text from an xml file.

                string path = "/View/Data/ItemsSource";
                XmlNodeList nodeList = currentDocument.SelectNodes(path);
                IDictionary<string, string> keyValuePairList = new Dictionary<string, string>();
                string itemsource;
                itemsource = "";
                foreach (XmlNode node in nodeList)
                {

                    itemsource = node.InnerXml;
                     //   keyValuePairList.Add(new KeyValuePair<string, string>(node.Attributes[0].Value, node.Attributes[0].Value));

                }

Result of itemsource

    <AdvancedListSupportClass xmlns=\"clr-namespace:Microsoft.EnterpriseManagement.UI.ViewFramework;assembly=Microsoft.EnterpriseManagement.UI.ViewFramework\" xmlns:av=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\" xmlns:s=\"clr-namespace:System;assembly=mscorlib\" DataTypeName=\"\" AdapterName=\"viewframework://Adapters/AdvancedList\" FullUpdateAdapter=\"dataportal:EnterpriseManagementObjectProjectionAdapter\" DataSource=\"mom:ManagementGroup\" IsRecurring=\"True\" RecurrenceFrequency=\"{x:Static s:Int32.MaxValue}\" FullUpdateFrequency=\"1\" Streaming=\"true\">
      <AdvancedListSupportClass.Parameters>
        <QueryParameter Parameter=\"TypeProjectionId\" Value=\"$MPElement[Name='System.WorkItem.Incident.View.ProjectionType']$\" />
      </AdvancedListSupportClass.Parameters>
    </AdvancedListSupportClass> 
c-sharp-and-swiftui-devni
  • 3,743
  • 4
  • 39
  • 100

1 Answers1

0

Your XML has default namespace so you need to use XmlNamespaceManager to be able to query the XML using XPath. For example, to get value of Parameter attribute you can do as follow :

XmlNamespaceManager nsManager = new XmlNamespaceManager(new NameTable());

//register ns prefix to point to default namespace 
nsManager.AddNamespace("ns", node.FirstChild.GetNamespaceOfPrefix(""));

//use the namespace manager and registered prefix to get desired element
string xpath = "/ns:AdvancedListSupportClass/ns:AdvancedListSupportClass.Parameters/ns:QueryParameter";
var queryParameters = node.SelectNodes(xpath, nsManager);

foreach(XmlNode queryParameter in queryParameters)
{
    //get value of Parameter attribute of each <QueryParameter>
    Console.WriteLine(queryParameter.Attributes["Parameter"].Value);
}
har07
  • 88,338
  • 12
  • 84
  • 137
  • thanks for the answer but having trouble implmenting it is their no way i can just parse it its values out as i getting that all as one string just their could be multple paremters though – c-sharp-and-swiftui-devni Jun 20 '14 at 12:59
  • Updated the code to accommodate case where there are multiple ``s – har07 Jun 20 '14 at 13:09
  • i think this is over complicating it I already have this in strong typed class "" all i need to do is extract the typeprotectionid and value of name: can i not just parse this line? – c-sharp-and-swiftui-devni Jun 20 '14 at 13:45