"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?
sbondalapatiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Emmanuel PASQUIERFreelance Project ManagerCommented:
what is you XML file ?
0
ebob42Commented:
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:


  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.

Open in new window

0
sbondalapatiAuthor Commented:
hi,

  I am attaching xml file.
Updateinformation.xml
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

ebob42Commented:
Try to remove the first line with <?xml version="1.0" encoding="UTF-8"?>
0
ebob42Commented:
Do you also have a corresponding xmlFileValidation.xsd which is mentioned in the first actual XML line for the xsi:noNamespaceSchemaLocation ?
0
ebob42Commented:
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>

Open in new window

0
ebob42Commented:
And then I can pass your XML document and the generated XSD to the following program, which tells me the XML is valid:
program ValidateXML;
{$APPTYPE CONSOLE}
uses
  SysUtils,
  Ole2, OleAuto;

var
  XML, XSDL: Variant;
begin
  if ParamCount = 0 then
  begin
    writeln('Usage: ValidateXML XML XSD');
    writeln
  end
  else // validate
  try
    XSDL := CreateOLEObject('MSXML2.XMLSchemaCache.4.0');
    XSDL.validateOnLoad := True;
    XSDL.add('',ParamStr(2)); // 1st argument is target namespace
    writeln('Schema Loaded');
    XML := CreateOLEObject('MSXML2.DOMDocument.4.0');
    XML.validateOnParse := True;
    XML.resolveExternals := True;
    XML.schemas := XSDL;
    XML.load(ParamStr(1));
    writeln(XML.parseError.reason);
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sbondalapatiAuthor Commented:
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(xmlFileName);
  xmlDocu.Active;

if you gave this it will be very helpful for me

thanks
0
ebob42Commented:
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.
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;

Open in new window

0
sbondalapatiAuthor Commented:
HI ebob,

   I am getting "EOLeSysError : Invalid class string" error when i used your code at the line stated below

XSDL := CreateOLEObject('MSXML2.XMLSchemaCache.4.0');

thanks
0
sbondalapatiAuthor Commented:
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.
0
ebob42Commented:
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 ;-)
0
sbondalapatiAuthor Commented:
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
0
ebob42Commented:
I also used MSXML...
0
sbondalapatiAuthor Commented:
which version of MSXML?
0
ebob42Commented:
I see MSXML 4.0 SP2 as well as 6.0 Parser on my system.
0
ebob42Commented:
Try playing with the ParseOptions. Can you open the document with empty ParseOptions, or with only the ValidateOnParse?
  xmlDocu.ParseOptions := [poValidateOnParse];

Open in new window

0
sbondalapatiAuthor Commented:
HI Ebob,

   You did an excellent job. Thanks for the help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.