Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am not able to parse the following XML using XML reader.
Need some guidance on the same.
XML

Regards,
Swayam
Posted
Updated 23-Feb-15 6:57am
v2
Comments
Zoltán Zörgő 23-Feb-15 13:43pm    
"Not able to" is no error message.
swayamrath 23-Feb-15 13:55pm    
@Zoltan,
I am not able to write the code using XMLReader to read the XML present in this URL

https://raw.githubusercontent.com/STIXProject/schemas/version_1.1.1/samples/STIX_IP_Watchlist.xml
Zoltán Zörgő 23-Feb-15 13:56pm    
I got that part, but what have you tried?
swayamrath 23-Feb-15 14:04pm    
this is the code that i tried

XmlTextReader reader = new XmlTextReader("https://raw.githubusercontent.com/STIXProject/schemas/version_1.1.1/samples/STIX_Malware_Sample.xml");
string contents = "";
while (reader.Read())
{
reader.MoveToContent();
if (reader.NodeType == System.Xml.XmlNodeType.Element)
contents += "<" + reader.Name + ">\n";
if (reader.NodeType == System.Xml.XmlNodeType.Text)
contents += reader.Value + "\n";
}
Response.Write(contents);

The method described here: http://support2.microsoft.com/kb/307643/en-us[^] works just fine.
 
Share this answer
 
Comments
swayamrath 23-Feb-15 14:18pm    
It doesn't go to the Switch() block and escapes the code for my XML URL
Zoltán Zörgő 23-Feb-15 14:21pm    
I don't know what you are expericenting. I have copied the code in LinqPad and replaced the url with yours. And it works.
swayamrath 23-Feb-15 14:26pm    
My apologies..I had missed the "While" part.
but having said that, the out put that i am getting is as below

>>>Example STIX document for sharing a Malware Sample>Malware Samples> Contains a fake malware sample. The 'malware sample' is a draft version of the TAXII Services Specification PDF, zipped, with a password of 'test'. The XML representation is Base64 encoded and is encapsulated in a CDATA blob.>>>>>>>>>>>>sample.zip>Characterized_By

i don;t think this is what the XML contains.
swayamrath 23-Feb-15 14:34pm    
My apologies again. It perfectly parsing the XML .

Thanks for the solution.

Regards,
Swayam
Maciej Los 23-Feb-15 15:41pm    
+5!
there are lots of way to parse data from XML so here i am describing one of the easiest method.

DataTable dt=new DataTable();
dt.ReadXml(mapPath("you_Url"));

now you can assign or you can perform any operation by using dataTable dt.
 
Share this answer
 

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