I developed a small C#script that opens a file XLS, parses it, and creates a list of files XMLthat check them on the file XSD.
I tried to upload these verified files to a third-party online service (the same company that provided me with the documentation / xsd), and one generated file is not accepted because it is NOT VALID .
The file is not accepted because it has a space at the beginning of the decimal value in the node attribute; removing this space fixes the problem.
I created a simple test case where the XDocument Validate method validates XML with extra space without any problems.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Schema;
using System.Xml.Linq;
using System.Xml;
using System.IO;
namespace TestParser {
class Program {
static void Main(string[] args) {
string xsdMarkup =
@"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>
<xs:element name='option'>
<xs:complexType>
<xs:simpleContent>
<xs:extension base='xs:string'>
<xs:attribute name='value' type='xs:decimal'>
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:schema>";
XmlSchemaSet schemas = new XmlSchemaSet();
schemas.Add("", XmlReader.Create(new StringReader(xsdMarkup)));
XDocument doc1 = new XDocument(
new XElement("option","test", new XAttribute("value", " 423423")
));
Console.WriteLine("Validating doc1");
bool errors = false;
doc1.Validate(schemas, (o, e) =>
{
Console.WriteLine("{0}", e.Message);
errors = true;
}, true);
Console.WriteLine("doc1 {0}", errors ? "not valid" : "validated");
Console.WriteLine();
Console.WriteLine("Contents of doc1:");
Console.WriteLine(doc1);
}
}
}
The result is the following:
Validating doc1
doc1 validated
Contents of doc1:
<option value=" 423423">test</option>
, XML- # XML?
Parser ?