.net - Linq to XML...I never get any Descendent values with XML as-is -
here part of xml trying parse:
<?xml version="1.0" encoding="utf-8"?> <workflow xmlns="http://soap.sforce.com/2006/04/metadata"> <alerts> <fullname>broker_not_in_sf_current_broker_account</fullname> <description>broker not in sf - current broker account</description> <protected>false</protected> <recipients> <recipient>geddylee@yyz.com</recipient> <type>user</type> </recipients> <sendertype>currentuser</sendertype> <template>broker_emails/current_broker_on_acct_not_in_sf</template> </alerts> <rules> <fullname>no service contact assigned</fullname> <active>true</active> <criteriaitems> <field>account.type</field> <operation>equals</operation> <value>client</value> </criteriaitems> <criteriaitems> <field>account.service_contact__c</field> <operation>equals</operation> </criteriaitems> <description>notification when service contact has not been assigned after 5 days, 8 days.</description> <triggertype>oncreateortriggeringupdate</triggertype> </rules> </workflow>
i can use simple linq xml on random simple xml file, in instance nothing. assume because of xml namespace, there way around other removing in xml rile prior parsing?
i haven't done xml work in past, i'm trying understand best way can take file shown , pull out rule nodes create collection or rules properties. can object/collection part, i'm stuck on why namespace failing simple call:
var setting = xmldoc.descendants("rules").first(e => e.element("fullname").value == "no service contact assigned"); console.writeline(setting.element("active").value);
thanks on or how use namespace.
you need xnamespace
this:
xnamespace ns = "http://soap.sforce.com/2006/04/metadata"; var setting = xmldoc.root.descendants(ns+"rules").first(e => e.element(ns+"fullname").value == "no service contact assigned"); console.writeline(setting.element(ns+"active").value);
note document not root node (e.g. workflow
element), root property on document is. added that.
Comments
Post a Comment