c# - How would I retrieve Query Parameter and name Values From XML String -
how parse following, wont alter @ to the lowest degree layout of line. need able query parmeter value out ie typeprojectionid , value of name=? have ideas @ all?
i using text 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>
your xml has default namespace need utilize xmlnamespacemanager able query xml using xpath. example, value of parameter attribute can follow :
xmlnamespacemanager nsmanager = new xmlnamespacemanager(new nametable()); //register ns prefix point default namespace nsmanager.addnamespace("ns", node.firstchild.getnamespaceofprefix("")); //use namespace manager , registered prefix 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); } c# xml regex parsing
No comments:
Post a Comment