sbondalapati
asked on
"EDomParse error: Invalid at the top level of the document".
HI,
I used TXMLDocument component to load and parse the xml file. I want to validate that xml file before parsing with xsd file. for this i set the parse options for xmldocument1 like below
xmldocument1 .ParseOptions := xmldocument1 .ParseOptions + [poValidateOnParse];
after that i used below statements
xmldocument1 .LoadFromXML(filename);
xmldocument1 .Active;
when i tried to exute my program i am getting the following error.
"EDomParse error: Invalid at the top level of the document".
can any body give the suggestions on this?
I used TXMLDocument component to load and parse the xml file. I want to validate that xml file before parsing with xsd file. for this i set the parse options for xmldocument1 like below
xmldocument1 .ParseOptions := xmldocument1 .ParseOptions + [poValidateOnParse];
after that i used below statements
xmldocument1 .LoadFromXML(filename);
xmldocument1 .Active;
when i tried to exute my program i am getting the following error.
"EDomParse error: Invalid at the top level of the document".
can any body give the suggestions on this?
what is you XML file ?
Perhaps the first line of the XML document contains the <?xml ...> tag that needs to be removed?
Alternately, here's another way to validate an XML model against its schema. This can be done with the validateOnParse property of the MSXML.DOMDocument, as follows:
Alternately, here's another way to validate an XML model against its schema. This can be done with the validateOnParse property of the MSXML.DOMDocument, as follows:
var
XML, XSDL: Variant;
begin
XSDL := CreateOLEObject('MSXML2.XMLSchemaCache.4.0');
XSDL.validateOnLoad := True;
XSDL.add('','MySchema.xsd'); // 1st argument is target namespace
ShowMessage('Schema Loaded');
XML := CreateOLEObject('MSXML2.DOMDocument.4.0');
XML.validateOnParse := True;
XML.resolveExternals := True;
XML.schemas := XSDL;
XML.load('file.xml');
ShowMessage(XML.parseError.reason);
end.
ASKER
Try to remove the first line with <?xml version="1.0" encoding="UTF-8"?>
Do you also have a corresponding xmlFileValidation.xsd which is mentioned in the first actual XML line for the xsi:noNamespaceSchemaLocat ion ?
With my XML2XSD tool, I can generate a XSD file as follows:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="updateinformation" type="updateinformationType"/>
<xs:complexType name="updateinformationType">
<xs:sequence>
<xs:element name="UpdateNumber" type="xs:integer"/>
<xs:element name="ManufacturerCode" type="xs:string"/>
<xs:element name="ExeVerNumber" type="xs:integer"/>
<xs:element name="DBStructVerNumber" type="xs:integer"/>
<xs:element name="PrevExeVerNumber" type="xs:integer"/>
<xs:element name="PrevDBStructVerNumber" type="xs:integer"/>
<xs:element name="PrevUpdateNumber" type="xs:integer"/>
<xs:element name="Mandatory" type="xs:string"/>
<xs:element name="Description" type="xs:string"/>
<xs:element name="UpdateType" type="xs:string"/>
<xs:element name="FilesToDownload" type="FilesToDownloadType"/>
</xs:sequence>
<xs:attribute name="noNamespaceSchemaLocation" type="xs:string"/>
</xs:complexType>
<xs:complexType name="FilesToDownloadType">
<xs:sequence>
<xs:element name="F1" type="xs:string"/>
<xs:element name="F2" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
HI Ebob,
Thank you for your example. Can you give me an example in which TxmlDocument component is used and parseoptions are set. like the below
xmlDocu: TXMLDocument;
xmlDocu.ParseOptions := xmlDocu.ParseOptions + [poValidateOnParse];
xmlDocu.LoadFromXML(xmlFil eName);
xmlDocu.Active;
if you gave this it will be very helpful for me
thanks
Thank you for your example. Can you give me an example in which TxmlDocument component is used and parseoptions are set. like the below
xmlDocu: TXMLDocument;
xmlDocu.ParseOptions := xmlDocu.ParseOptions + [poValidateOnParse];
xmlDocu.LoadFromXML(xmlFil
xmlDocu.Active;
if you gave this it will be very helpful for me
thanks
It was just a matter of incorrect loading the file. Your call to "Active" is not a call, it's a property.
The following code works for me: calling LoadFromFile and then checking the Active property, or setting the FileName and then Active to True.
The following code works for me: calling LoadFromFile and then checking the Active property, or setting the FileName and then Active to True.
procedure TExpertExchangeForm.Button5Click(Sender: TObject);
const
xmlFileName = 'c:\Updateinformation.xml';
begin
xmlDocu.ParseOptions := xmlDocu.ParseOptions + [poValidateOnParse];
//xmlDocu.FileName := xmlFileName;
//xmlDocu.Active := True;
xmlDocu.LoadFromFile(xmlFileName);
if xmlDocu.Active then ShowMessage('OK');
end;
ASKER
HI ebob,
I am getting "EOLeSysError : Invalid class string" error when i used your code at the line stated below
XSDL := CreateOLEObject('MSXML2.XM LSchemaCac he.4.0');
thanks
I am getting "EOLeSysError : Invalid class string" error when i used your code at the line stated below
XSDL := CreateOLEObject('MSXML2.XM
thanks
ASKER
HI ebob,
i wrote the same code but for me its throwing error that "iInvalid at the top level of the document".
I am using
MSXML 6.0 parser, windows xp sp2 and Delphi 2010.
is there anything related to them.
i wrote the same code but for me its throwing error that "iInvalid at the top level of the document".
I am using
MSXML 6.0 parser, windows xp sp2 and Delphi 2010.
is there anything related to them.
You could try a different DOMVendor (see the DOMVendor property of the TXMLDocument component).
I'm also using Delphi 2010 on WIndows XP here. It works for me ;-)
I'm also using Delphi 2010 on WIndows XP here. It works for me ;-)
ASKER
HI,
I am using MSXML as domvendor. can you tell me the domvendor you used? Becuase i am not able to run mycode still i am getting same errors as stated above.
thanks
I am using MSXML as domvendor. can you tell me the domvendor you used? Becuase i am not able to run mycode still i am getting same errors as stated above.
thanks
I also used MSXML...
ASKER
which version of MSXML?
I see MSXML 4.0 SP2 as well as 6.0 Parser on my system.
Try playing with the ParseOptions. Can you open the document with empty ParseOptions, or with only the ValidateOnParse?
xmlDocu.ParseOptions := [poValidateOnParse];
ASKER
HI Ebob,
You did an excellent job. Thanks for the help.
You did an excellent job. Thanks for the help.