Click here to Skip to main content
15,887,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, my requirement is as follows:
1= read an xml url and then search a specific value using a text box and then list all the occurrence of that text in parsed order

For eg: my API is as follows:
HTML
<blockquote class="FQ"><div class="FQA">Quote:</div>
<Record1>
<ID>4</ID>
<Name>ABCD</Name>
<NumberOfPosition>1</NumberOfPosition>
<Rate>0</Rate>
<SignalID>102288301</SignalID>
<SignalTime>2013-07-16T23:59:59.043</SignalTime>
<SignalType>CloseMarketOrder</SignalType>
<Loss>0</Loss>
<SubName>78730843</SubName>
<SystemID>720</SystemID>
<SystemName>Passion 1</SystemName>
<Profitrate>0</Profitrate>
</Record1>

<pre lang="HTML"><blockquote class="FQ"><div class="FQA">Quote:</div><Record2>
<ID>4</ID>
<Name>ABCD</Name>
<NumberOfPosition>1</NumberOfPosition>
<Rate>0</Rate>
<SignalID>102288301</SignalID>
<SignalTime>2013-07-16T23:59:59.043</SignalTime>
<SignalType>CloseMarketOrder</SignalType>
<Loss>0</Loss>
<SubName>78730843</SubName>
<SystemID>720</SystemID>
<SystemName>Passion 1</SystemName>
<Profitrate>0</Profitrate>
</Record2>
and so on 
</blockquote> 


I want to parse it like:
ID = 4
Name = ABCD
etc

and then search using a text box for eg: Name = ABCD so this search should check the all the occurrence of ABCD in the xml and list the complete data in the text box

Plese help
Posted

1 solution

Here's an example using Linq:

C#
var xmlNodes= from element in XElement.Load("MyXmlFile.xml").XPathSelectElements("/Items/Item/Description")
            select new
            {
                Value = element.Value.Trim()
            };
 
foreach (var node in xmlNodes)
{
    // Do Stuff with "node", E.g.:
    MyListBox.Items.Add(node);
}



* In case you are not familiar with XPath, I'd suggest you give it a few minutes to learn, it's quite handy! See a tutorial here[^].


Good luck,
Edo
 
Share this answer
 
v4
Comments
Mitul12 18-Jul-13 19:35pm    
Thanks for the reply, but i asked how to search a string and then print the result of complete data matching that string
For eg: in the above example
if i search for ABCD then it should result all data related to ABCD abd if suppose ABC is occuring many times in the xml then also all the relavent data should be printed in the text box

Please help
Joezer BH 21-Jul-13 1:24am    
IF I understand you correctly, then the example should work just fine, you just need to use the XPath from your textbox in the select elements line above:
XElement.Load("MyXmlFile.xml").XPathSelectElements(YourTextboxTextHere);

* If you are not familiar with XPath, I'd suggest you give it a few minutes - it's quite handy!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900