Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

How to read text from xml nodes

Hello HF,

This is a sample xml
Code
<Contents><Key>000018a19cfbbcb12286c4c051b09b27.jpeg</Key><LastModified>2016-02-10T23:58:24.000Z</LastModified><ETag>"000018a19cfbbcb12286c4c051b09b27"</ETag><Size>227621</Size><Owner><ID>07ba55931634353d81b28388db73b19c576cefcc3f5a19be3137e5cbf691f554</ID><DisplayName>admin</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents><Contents><Key>00002627b319131d0de89347c32ad3b6.jpeg</Key><LastModified>2016-02-13T12:34:54.000Z</LastModified><ETag>"00002627b319131d0de89347c32ad3b6"</ETag><Size>102336</Size><Owner><ID>07ba55931634353d81b28388db73b19c576cefcc3f5a19be3137e5cbf691f554</ID><DisplayName>admin</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents><Contents><Key>00002aee6026afbd407096d212d88344.jpg</Key><LastModified>2016-02-21T22:44:02.000Z</LastModified><ETag>"00002aee6026afbd407096d212d88344"</ETag><Size>69219</Size><Owner><ID>07ba55931634353d81b28388db73b19c576cefcc3f5a19be3137e5cbf691f554</ID><DisplayName>admin</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents><Contents><Key>00002e987b80919a095bf8da63d8399b.jpg</Key><LastModified>2016-02-22T15:02:14.000Z</LastModified><ETag>"00002e987b80919a095bf8da63d8399b"</ETag><Size>166892</Size><Owner><ID>07ba55931634353d81b28388db73b19c576cefcc3f5a19be3137e5cbf691f554</ID><DisplayName>admin</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents>

i want to read the text between all nodes named '<Key>' (without quotes).
can anyone have a suggestion. how to read ?? ❓ 🤐
PHP Code

<?php 
Dim XML 
As XmlDocument = New XmlDocument()
XML.Load("Filepath.xml")
Dim KeysList As XmlNodeList = XML.GetElementsByTagName("Key")
For 
i=0 to KeysList.Count-1
Console
.WriteLine(KeysList.ItemOf(i).InnerXml)
Next 

I think this will do.
(Mar 2, 2016 11:11 AM)Support™ Wrote:  
PHP Code

<?php 
Dim XML 
As XmlDocument = New XmlDocument()
XML.Load("Filepath.xml")
Dim KeysList As XmlNodeList = XML.GetElementsByTagName("Key")
For 
i=0 to KeysList.Count-1
Console
.WriteLine(KeysList.ItemOf(i).InnerXml)
Next 

I think this will do.

thank you for your reply. i tried this but this code read only first node's text. not all nodes ('<Key>' node). 🤨
Not sure if this is what you're looking for but I found a few links.
all of these links are lil bit helpful but cannot solve my issue, Sir. :(
(Mar 2, 2016 12:56 PM)hunters Wrote:  all of these links are lil bit helpful but cannot solve my issue, Sir. :(

How about you post your code so we can help fix it? How do you expect we can fix your code if you havent posted your code?
Pretty sure it's

Code
Dim XML As XmlDocument = New XmlDocument()
XML.Load("Filepath.xml")
Dim KeysList As XmlNodeList = XML.SelectNodes("Contents/Key")
For i=0 to KeysList.Count-1
Console.WriteLine(KeysList.ItemOf(i).InnerText)
Next


Or if the XML is in a string:

Code
Dim XMLString As String = "XML HERE"
Dim XML As XmlDocument = New XmlDocument()
XML.LoadString(XMLString)
Dim KeysList As XmlNodeList = XML.SelectNodes("Contents/Key")
For i=0 to KeysList.Count-1
Console.WriteLine(KeysList.ItemOf(i).InnerText)
Next
(Mar 2, 2016 12:56 PM)hunters Wrote:  all of these links are lil bit helpful but cannot solve my issue, Sir. :(

Honestly this isn't that difficult.
Apply yourself instead of relying on others to provide a solution.
(Mar 2, 2016 11:17 AM)hunters Wrote:  thank you for your reply. i tried this but this code read only first node's text. not all nodes ('<Key>' node). 🤨

It is because your XML is messed up.
You have multiple root elements with <Contents> tag and you will also need need to escape the double quotes(") in <ETag>.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[The Brotherhood] by HackersFeb 22, 2026 09:00 AM 2 116 Feb 22, 2026 09:00 AM
Last Post: Hackers
[Source] by HackersJul 24, 2023 04:07 AM 6 268 Jul 24, 2023 04:07 AM
Last Post: Hackers
[Python] by Ownc0d3rAug 12, 2018 07:03 AM 3 149 Aug 12, 2018 07:03 AM
Last Post: TyrantKingBen