c# - Parsing a element with name space not working xpath -
c# - Parsing a element with name space not working xpath -
i no got shot downwards before inquire tried implmenting name space xml still not working xml document service center maanger.
public void getcriteraparamters(string queryparmeterstring, string xpath) { list<querycritera> listcriteraparameter = new list<querycritera>(); xmldocument currentdocument = new xmldocument(); currentdocument.loadxml(queryparmeterstring); string path = xpath; xmlnodelist nodelist = currentdocument.selectnodes(path); xmlelement elm = currentdocument.documentelement; xmlnodelist listcritera= elm.childnodes; xmlnamespacemanager nsmgr = new xmlnamespacemanager(currentdocument.nametable); nsmgr.addnamespace("querycriteria", "http://microsoft.enterprisemanagement.core.criteria/"); var topicnodes = currentdocument.selectnodes("expression", nsmgr); list<querycritera> qp = new list<querycritera>(); string itemsource=""; (int = 0; < listcritera.count; i++) { querycritera qplist = new querycritera(); string mystring = listcritera[i].innerxml.tostring(); string xml2 = xelement.parse(mystring).tostring(); xmldocument currentdocument2 = new xmldocument(); currentdocument2.loadxml(xml2); xmlnodelist nodelist2 = currentdocument.selectnodes(xpath); foreach (xmlnode node in nodelist2) { itemsource = node.innerxml; } } }
i need able select nodes under cirtiera look ones.
<?xml version="1.0" encoding="utf-8" ?> <view> <data> <adapters> <adapter adaptername="dataportal:enterprisemanagementobjectprojectionadapter"> <adapterassembly>microsoft.enterprisemanagement.ui.sdkdataaccess</adapterassembly> <adaptertype>microsoft.enterprisemanagement.ui.sdkdataaccess.dataadapters.enterprisemanagementobjectprojectionadapter</adaptertype> </adapter> <adapter adaptername="viewframework://adapters/advancedlist"> <adapterassembly>microsoft.enterprisemanagement.ui.viewframework</adapterassembly> <adaptertype>microsoft.enterprisemanagement.ui.viewframework.advancedlistsupportadapter</adaptertype> </adapter> <adapter adaptername="omsdk://adapters/criteria"> <adapterassembly>microsoft.enterprisemanagement.ui.sdkdataaccess</adapterassembly> <adaptertype>microsoft.enterprisemanagement.ui.sdkdataaccess.dataadapters.sdkcriteriaadapter</adaptertype> </adapter> </adapters> <itemssource> <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> </itemssource> <criteria> <querycriteria xmlns="http://tempuri.org/criteria.xsd" adapter="omsdk://adapters/criteria"> <criteria> <freeformcriteria> <freeform> <criteria xmlns="http://microsoft.enterprisemanagement.core.criteria/"> <expression> <and> <expression> <simpleexpression> <valueexpressionleft> <property>$context/property[type='coreincident!system.workitem.incident']/tierqueue$</property> </valueexpressionleft> <operator>equal</operator> <valueexpressionright> <value>$mpelement[name="incidenttierqueuesenum.tier2"]$</value> </valueexpressionright> </simpleexpression> </expression> <expression> <simpleexpression> <valueexpressionleft> <property>$context/property[type='coreincident!system.workitem.incident']/status$</property> </valueexpressionleft> <operator>notequal</operator> <valueexpressionright> <value>$mpelement[name="coreincident!incidentstatusenum.resolved"]$</value> </valueexpressionright> </simpleexpression> </expression> <expression> <simpleexpression> <valueexpressionleft> <property>$context/property[type='coreincident!system.workitem.incident']/status$</property> </valueexpressionleft> <operator>notequal</operator> <valueexpressionright> <value>$mpelement[name="coreincident!incidentstatusenum.closed"]$</value> </valueexpressionright> </simpleexpression> </expression> <expression> <unaryexpression> <valueexpression> <genericproperty path="$context/path[relationship='workitem!system.workitemassignedtouser' seedrole='source']$">id</genericproperty> </valueexpression> <operator>isnull</operator> </unaryexpression> </expression> </and> </expression> </criteria> </freeform> </freeformcriteria> </criteria> </querycriteria> </criteria> </data> <presentation> <columns> <mux:columncollection xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:mux="http://schemas.microsoft.com/systemcenter/common/ui/views/gridview" xmlns:s="clr-namespace:system;assembly=mscorlib" xmlns:datebinding="clr-namespace:microsoft.enterprisemanagement.ui.extensions;assembly=microsoft.enterprisemanagement.ui.extensions"> <mux:column name="id" displaymemberbinding="{binding path=id, mode=oneway}" width="150" displayname="header_id" property="id$returnvalueasbigint$" datatype="s:string" /> <mux:column name="title" displaymemberbinding="{binding path=title, mode=oneway}" width="200" displayname="header_title" property="title" datatype="s:string" /> <mux:column name="sdisplayname" displaymemberbinding="{binding path=status.displayname, mode=oneway}" width="100" displayname="header_status" property="status.displayname" datatype="s:string" /> <mux:column name="priority" displaymemberbinding="{binding path=priority, mode=oneway}" width="100" displayname="header_priority" property="priority" datatype="s:int32" /> <mux:column name="targettime" displaymemberbinding="{datebinding:datebinding path=targetresolutiontime, mode=oneway}" width="100" displayname="header_target_resolution_time" property="targetresolutiontime" datatype="s:datetime" /> <mux:column name="adisplayname" displaymemberbinding="{binding path=affecteduser.displayname, mode=oneway}" width="150" displayname="header_affected_user" property="affecteduser.displayname" datatype="s:string" /> <mux:column name="lastmodified" displaymemberbinding="{binding path=$lastmodified$, mode=oneway}" width="150" displayname="header_last_modified" property="$lastmodified$" datatype="s:datetime" /> </mux:columncollection> </columns> <viewstrings> <viewstring id="header_id">$mpelement[name="system.workitem.incident.queue.tier2.unassigned.view.header_id"]$</viewstring> <viewstring id="header_title">$mpelement[name="system.workitem.incident.queue.tier2.unassigned.view.header_title"]$</viewstring> <viewstring id="header_status">$mpelement[name="system.workitem.incident.queue.tier2.unassigned.view.header_status"]$</viewstring> <viewstring id="header_priority">$mpelement[name="system.workitem.incident.queue.tier2.unassigned.view.header_priority"]$</viewstring> <viewstring id="header_target_resolution_time">$mpelement[name="system.workitem.incident.queue.tier2.unassigned.view.header_target_resolution_time"]$</viewstring> <viewstring id="header_affected_user">$mpelement[name="system.workitem.incident.queue.tier2.unassigned.view.header_affected_user"]$</viewstring> <viewstring id="header_last_modified">$mpelement[name="system.workitem.incident.queue.tier2.unassigned.view.header_last_modified"]$</viewstring> </viewstrings> </presentation> </view>
its values hope pull out stronlgy typed object have created?.
<expression> <and> <expression> <simpleexpression> <valueexpressionleft> <property>$context/property[type='coreincident!system.workitem.incident']/tierqueue$</property> </valueexpressionleft> <operator>equal</operator> <valueexpressionright> <value>$mpelement[name="incidenttierqueuesenum.tier2"]$</value> </valueexpressionright> </simpleexpression> </expression> <expression> <simpleexpression> <valueexpressionleft> <property>$context/property[type='coreincident!system.workitem.incident']/status$</property> </valueexpressionleft> <operator>notequal</operator> <valueexpressionright> <value>$mpelement[name="coreincident!incidentstatusenum.resolved"]$</value> </valueexpressionright> </simpleexpression> </expression> <expression> <simpleexpression> <valueexpressionleft> <property>$context/property[type='coreincident!system.workitem.incident']/status$</property> </valueexpressionleft> <operator>notequal</operator> <valueexpressionright> <value>$mpelement[name="coreincident!incidentstatusenum.closed"]$</value> </valueexpressionright> </simpleexpression> </expression> <expression> <unaryexpression> <valueexpression> <genericproperty path="$context/path[relationship='workitem!system.workitemassignedtouser' seedrole='source']$">id</genericproperty> </valueexpression> <operator>isnull</operator> </unaryexpression> </expression> </and> </expression>
when using xmldocument xml has namespaces in it, need utilize xmlnamespacemanager create aliases namespaces. in xpath statements utilize aliases in front end of element names. give try:
xmldocument doc = new xmldocument(); doc.load("xmlfile1.xml"); // give namespace alias utilize in our xpath statement xmlnamespacemanager mgr = new xmlnamespacemanager(doc.nametable); mgr.addnamespace("a", "http://microsoft.enterprisemanagement.core.criteria/"); // find criteria node tagged "a" namespace xmlnode node = doc.selectsinglenode("//a:criteria", mgr); console.writeline(node.outerxml);
c# xml parsing
Comments
Post a Comment