Last post Oct 18, 2019 01:24 PM by AddWeb Solution
Contributor
2876 Points
1172 Posts
Oct 18, 2019 08:22 AM|chandu123|LINK
<server><requests><Session.loginRq userName="admin" password="admin" /> <IntegrationCBO.ProcessWCFServiceRq name="test" binding="http" url="http://abrxmlsearch.asmx" searchString="53004085616" includeHistoricalDetails="N" authenticationGuid="88bf33e2-96a6-402c-a870-47c03af2a80b"></IntegrationCBO.ProcessWCFServiceRq><Session.closeRq /></requests></server>
How to find the value of searchString?
3370 Points
1409 Posts
Oct 18, 2019 09:58 AM|samwu|LINK
Hi chandu123,
chandu123 How to find the value of searchString?
According to your description, I made demo for your.
You can select Node with Attribute value using XPath, then find attribute value base on Node.
The code:
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /> protected void Button1_Click(object sender, EventArgs e) { XmlDocument doc = new XmlDocument(); doc.Load(@"C:\Users\samwu\Desktop\Test.xml"); XmlNodeList nodeList = doc.SelectNodes("/server/requests/IntegrationCBO.ProcessWCFServiceRq[@searchString='53004085616']"); foreach (XmlNode node in nodeList) { Response.Write(" url: " + node.Attributes["url"].Value); } }
The result:
Best regards,
Sam
Participant
850 Points
492 Posts
Oct 18, 2019 01:24 PM|AddWeb Solution|LINK
Hello chandu123,
I had added a code for the getting value from the specific element.
here is my sample code for .aspx page
<asp:Button ID="getXmlAttrinuteValue" runat="server" OnClick="getXmlAttrinuteValue_Click" Text="Get XML Attribute "/>
Here is my codebehind sample code for getting value of searchstring.
protected void getXmlAttrinuteValue_Click(object sender, EventArgs e) { XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(@"D:\XML\sampleXMLFile.xml"); var node = xmlDocument.GetElementsByTagName("IntegrationCBO.ProcessWCFServiceRq"); if(node.Count > 0) { var element = node[0].Attributes["searchString123"]; string value = "Element not found"; if(element != null) { value = " searchString : " + node[0].Attributes["searchString123"].Value; } Response.Write(value); } }
Thank you.
Contributor
2876 Points
1172 Posts
How to find a attribute value in XML
Oct 18, 2019 08:22 AM|chandu123|LINK
<server><requests><Session.loginRq userName="admin" password="admin" />
<IntegrationCBO.ProcessWCFServiceRq name="test" binding="http" url="http://abrxmlsearch.asmx" searchString="53004085616" includeHistoricalDetails="N" authenticationGuid="88bf33e2-96a6-402c-a870-47c03af2a80b"></IntegrationCBO.ProcessWCFServiceRq><Session.closeRq /></requests></server>
How to find the value of searchString?
Chandrasekhar (MCTS) .NET framework 3.5, ASP.NET Applications
If my ANSWER helps you in solving your problem MARK IT AS ANSWER
Contributor
3370 Points
1409 Posts
Re: How to find a attribute value in XML
Oct 18, 2019 09:58 AM|samwu|LINK
Hi chandu123,
According to your description, I made demo for your.
You can select Node with Attribute value using XPath, then find attribute value base on Node.
The code:
The result:
Best regards,
Sam
Participant
850 Points
492 Posts
Re: How to find a attribute value in XML
Oct 18, 2019 01:24 PM|AddWeb Solution|LINK
Hello chandu123,
I had added a code for the getting value from the specific element.
here is my sample code for .aspx page
Here is my codebehind sample code for getting value of searchstring.
Thank you.