0

I have a xml document like this

    <?xml version="1.1" encoding="UTF-8" standalone="yes"?>
    <p:FatturaElettronica versione="1.1" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:p="http://www.fatturapa.gov.it/sdi/fatturapa/v1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <FatturaElettronicaHeader>
            <DatiTrasmissione>
                <IdTrasmittente>
                    <IdPaese>IT</IdPaese>
...

If i use:

Dim doc As New XmlDocument()
doc.Load(filePath)

I receive an error:

1.1 is not a valid version

Why, how can i do for read xml with this version?

Thanks

Luca Romagnoli
  • 12,145
  • 30
  • 95
  • 157
  • Did you try to remove `` and tested?? – prashant thakre Sep 30 '15 at 10:39
  • I think version must be 1.1.0 – prashant thakre Sep 30 '15 at 10:40
  • i can't change the document – Luca Romagnoli Sep 30 '15 at 10:53
  • Are you validating this xml with any xsd?? – prashant thakre Sep 30 '15 at 10:53
  • 1
    The error message seems quite descriptive. After a quick look at a random sample of XML files I have in my computer, I have confirmed that all of them have version="1.0". Also according to the associated MSDN article (https://msdn.microsoft.com/en-us/library/ms256048.aspx), 1.0 is the current version. You should either make sure that the input information is right or reduce the strictness of your parsing approach. That is: change the corresponding options in the XML reader; or read it as a plain text file; or do a mixed approach: read it as text file to memory, modify it and use XML reader. – varocarbas Sep 30 '15 at 10:55
  • Looks like 1.1 isn't widely supported, this may help: http://stackoverflow.com/questions/17231675/does-net-4-5-support-xml-1-1-yet-for-characters-invalid-in-xml-1-0 – Jonas Schumacher Sep 30 '15 at 10:57

2 Answers2

0

Give this a try. It assumes that not having the first line has no consequences.

    Dim fileLines As List(Of String) = IO.File.ReadAllLines(filePath).ToList
    fileLines.RemoveAt(0)
    Dim fileAsString As String = String.Join(Environment.NewLine, fileLines)

    Dim xe As XElement = XElement.Parse(fileAsString)

    Dim doc As New XmlDocument()
    doc.Load(xe.CreateReader)
dbasnett
  • 11,334
  • 2
  • 25
  • 33
0

If you download an example of file FatturaPA from http://www.fatturapa.gov.it/export/fatturazione/it/a-3.htm you will notice that xml version is 1.0.

<?xml version="1.0" encoding="UTF-8"?>
<p:FatturaElettronica versione="1.1" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:p="http://www.fatturapa.gov.it/sdi/fatturapa/v1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

So maybe your file is not correct.

tezzo
  • 10,858
  • 1
  • 25
  • 48