Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jan 08, 2013 06:03 AM by ashwanisaini
Member
731 Points
164 Posts
Jan 07, 2013 09:36 AM|LINK
Hi I want to get the value for the key REG_LINK from the XML feed below, I tried the xpath but it does not work "onl:cceobject/onl:content/onl:extrafields/onl:extrafield/[onl:key='REG_LINK']"
<?xml version="1.0" encoding="UTF-8"?> <onl:cceobject xmlns:onl="http://www.saxotech.com/online"> <onl:content> <onl:title><![CDATA[2013 Energy Symposium]]></onl:title> <onl:extrafields> <onl:extrafield type="text"> <onl:key><![CDATA[CITY]]></onl:key> <onl:displaytext><![CDATA[]]></onl:displaytext> <onl:value><![CDATA[Camp Hill]]></onl:value> </onl:extrafield> <onl:extrafield type="text"> <onl:key><![CDATA[CONTACT_NAME]]></onl:key> <onl:displaytext><![CDATA[]]></onl:displaytext> <onl:value><![CDATA[Colleen Jones]]></onl:value> </onl:extrafield> <onl:extrafield type="text"> <onl:key><![CDATA[REG_LINK]]></onl:key> <onl:displaytext><![CDATA[]]></onl:displaytext> <onl:value><![CDATA[https://www.centralpennbusiness.com/section/Energy-Symp-Registration]]></onl:value> </onl:extrafield> <onl:extrafield type="text"> <onl:key><![CDATA[STATE]]></onl:key> <onl:displaytext><![CDATA[]]></onl:displaytext> <onl:value><![CDATA[PA]]></onl:value> </onl:extrafield> <onl:extrafield type="text"> <onl:key><![CDATA[STREET_ADDRESS]]></onl:key> <onl:displaytext><![CDATA[]]></onl:displaytext> <onl:value><![CDATA[1150 Camp Hill Bypass]]></onl:value> </onl:extrafield> <onl:extrafield type="text"> <onl:key><![CDATA[VENUE]]></onl:key> <onl:displaytext><![CDATA[]]></onl:displaytext> <onl:value><![CDATA[Radisson Hotel Harrisburg]]></onl:value> </onl:extrafield> </onl:extrafields> </onl:content> </onl:cceobject>
I am using below code to get the value but it did not work please help:
xmlDoc.LoadXml(Return_XmLFeedByURL("XMLFeed URL"); XmlNamespaceManager namespaceManager = new XmlNamespaceManager(xmlDoc.NameTable); namespaceManager.AddNamespace("onl", "http://www.saxotech.com/online"); string strEventLink = xmlDoc.SelectSingleNode("onl:cceobject/onl:content/onl:extrafields/onl:extrafield/[onl:key='REG_LINK']", namespaceManager);
All-Star
118619 Points
18779 Posts
Jan 08, 2013 01:59 AM|LINK
Hello,
There's a fatal error with your xml syntax while searching for that spicific value, so please change to this:
XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load("XMLFile1.xml"); XmlNamespaceManager namespaceManager = new XmlNamespaceManager(xmlDoc.NameTable); namespaceManager.AddNamespace("onl", "http://www.saxotech.com/online"); var strEventLink = xmlDoc.SelectSingleNode("/onl:cceobject/onl:content/onl:extrafields//onl:extrafield[onl:key='REG_LINK']", namespaceManager).InnerText; Console.WriteLine(strEventLink);
For more about Xml's XPath, please refer to this:
http://www.w3schools.com/xpath/default.asp
Jan 08, 2013 06:03 AM|LINK
Thank You Decker!
I am looking for the value of element "onl:value" where "onl:key = 'REG_LINK'".
I tried your XPath expresion, It works great i modified it to a bit get the desired result.
Thanks a lot!
Below is my wroking Code to get the value for KEY REG_LINK
string strRegLink = xmlDoc.SelectSingleNode("onl:cceobject/onl:content/onl:extrafields/onl:extrafield[onl:key='REG_LINK']/onl:value", namespaceManager).InnerText;
Thanks Ashwani
ashwanisaini
Member
731 Points
164 Posts
Filetr XML using Xpath with key Value.
Jan 07, 2013 09:36 AM|LINK
Hi I want to get the value for the key REG_LINK from the XML feed below, I tried the xpath but it does not work "onl:cceobject/onl:content/onl:extrafields/onl:extrafield/[onl:key='REG_LINK']"
<?xml version="1.0" encoding="UTF-8"?> <onl:cceobject xmlns:onl="http://www.saxotech.com/online"> <onl:content> <onl:title><![CDATA[2013 Energy Symposium]]></onl:title> <onl:extrafields> <onl:extrafield type="text"> <onl:key><![CDATA[CITY]]></onl:key> <onl:displaytext><![CDATA[]]></onl:displaytext> <onl:value><![CDATA[Camp Hill]]></onl:value> </onl:extrafield> <onl:extrafield type="text"> <onl:key><![CDATA[CONTACT_NAME]]></onl:key> <onl:displaytext><![CDATA[]]></onl:displaytext> <onl:value><![CDATA[Colleen Jones]]></onl:value> </onl:extrafield> <onl:extrafield type="text"> <onl:key><![CDATA[REG_LINK]]></onl:key> <onl:displaytext><![CDATA[]]></onl:displaytext> <onl:value><![CDATA[https://www.centralpennbusiness.com/section/Energy-Symp-Registration]]></onl:value> </onl:extrafield> <onl:extrafield type="text"> <onl:key><![CDATA[STATE]]></onl:key> <onl:displaytext><![CDATA[]]></onl:displaytext> <onl:value><![CDATA[PA]]></onl:value> </onl:extrafield> <onl:extrafield type="text"> <onl:key><![CDATA[STREET_ADDRESS]]></onl:key> <onl:displaytext><![CDATA[]]></onl:displaytext> <onl:value><![CDATA[1150 Camp Hill Bypass]]></onl:value> </onl:extrafield> <onl:extrafield type="text"> <onl:key><![CDATA[VENUE]]></onl:key> <onl:displaytext><![CDATA[]]></onl:displaytext> <onl:value><![CDATA[Radisson Hotel Harrisburg]]></onl:value> </onl:extrafield> </onl:extrafields> </onl:content> </onl:cceobject>I am using below code to get the value but it did not work please help:
xmlDoc.LoadXml(Return_XmLFeedByURL("XMLFeed URL"); XmlNamespaceManager namespaceManager = new XmlNamespaceManager(xmlDoc.NameTable); namespaceManager.AddNamespace("onl", "http://www.saxotech.com/online"); string strEventLink = xmlDoc.SelectSingleNode("onl:cceobject/onl:content/onl:extrafields/onl:extrafield/[onl:key='REG_LINK']", namespaceManager);Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Filetr XML using Xpath with key Value.
Jan 08, 2013 01:59 AM|LINK
Hello,
There's a fatal error with your xml syntax while searching for that spicific value, so please change to this:
For more about Xml's XPath, please refer to this:
http://www.w3schools.com/xpath/default.asp
ashwanisaini
Member
731 Points
164 Posts
Re: Filetr XML using Xpath with key Value.
Jan 08, 2013 06:03 AM|LINK
Thank You Decker!
I am looking for the value of element "onl:value" where "onl:key = 'REG_LINK'".
I tried your XPath expresion, It works great i modified it to a bit get the desired result.
Thanks a lot!
Below is my wroking Code to get the value for KEY REG_LINK
string strRegLink = xmlDoc.SelectSingleNode("onl:cceobject/onl:content/onl:extrafields/onl:extrafield[onl:key='REG_LINK']/onl:value", namespaceManager).InnerText;Thanks
Ashwani