0

The developer of this particular library seems to be MIA. https://github.com/Kamiizumi/NmapXmlParser

To test the issue grab his library (NmapXmlParser) from Nu-Get and make sure you have

using System.Xml.Serialization;
using System.IO;
using Xunit;

The code he gives on the example looks like this

var xmlSerializer = new XmlSerializer(typeof(nmaprun));
var result = default(nmaprun);

using (var xmlStream = new StreamReader("NmapResults.xml"))
{
    result = xmlSerializer.Deserialize(xmlStream) as nmaprun;
}

Console.WriteLine(result.args);

This works when getting the elements inside of the nmaprun object. He does not give any other examples so I assumed if I wanted to check the host object i would change all instances of nmaprun in above code to host. And then on the Console line change to an element inside the host object like this

var xmlSerializer = new XmlSerializer(typeof(host));
var result = default(host);

using (var xmlStream = new StreamReader("NmapResults.xml"))
{
    result = xmlSerializer.Deserialize(xmlStream) as host;
}

Console.WriteLine(result.reason);

The Intellisense inside of the Console.Writeline wants to autocomplete to the elements so I feel its set up right but I keep getting this error.

System.InvalidOperationException: 'There is an error in XML document (5, 2).' Inner Exception InvalidOperationException: was not expected.

You can use the example XML in his Github if you do not have an Nmap xml output file

Dante
  • 17
  • 5
  • Your xml has an error on line 5 column 2. You can validate the xml in VS using following menu : Project : Add New Item : XML File. Then paste xml into view. The errors will show up like any compiler error in the Error View. – jdweng Mar 01 '20 at 11:23
  • i think the XML is fine I think it is more similar to this issue https://stackoverflow.com/questions/1556874/user-xmlns-was-not-expected-deserializing-twitter-xml . but i still don't know how to get it working. ill keep reading up – Dante Mar 02 '20 at 09:24
  • The error you are getting is definitely due to the xml file. The xml link you provided is fine. Try testing with the same xml as the line and see if you get the same error. If you are reading the xml from a file open file with notepad. Then do a FileSAVE. On the popup there is box indicating encoding which should be UTF-8. I've seen cases where I've taken an XML from a webpage and save to a file for testing and got errors. When I read from from c# from w webpage I did not get errors. So this may be an encoding issue. Not sure. – jdweng Mar 02 '20 at 09:42

0 Answers0