Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 12th, 2004, 04:39 AM
Registered User
 
Join Date: Feb 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default XML Validation

All,

I am new to XML, and trying to validate some xml via delphi.
The xml validates not problem via XMLSPY

but throws an error when I try, I have looked at numerous examples but an stuck. Can anyone help.

  XSDL := CreateOLEObject('MSXML2.XMLSchemaCache.4.0');
  XSDL.add(NSEdit.Text,'aaa.xsd');
  XSDL.add(NSEdit.Text,'bbb.xsd');
  XSDL.add(NSEdit.Text,'ccc.xsd');

NSEdit.text is a target namespace

The simple types declared in ccc.xsd
xsd:simpleType name="IdType">
        <xsd:restriction base="xsd:string">
            <xsd:maxLength value="8"/>
            <xsd:pattern value="[A-Z,0-9,+,-,_]+"/>
        </xsd:restriction>
    </xsd:simpleType>

is not being found in bbb.xsd

    <xsd:element name="MY_ID" type="nnn:IdType"/>

bbb.xsd and ccc.xsd are included in aaa.xsd

    <xsd:include schemaLocation="bbb.xsd"/>
    <xsd:include schemaLocation="ccc.xsd"/>



 
Old February 12th, 2004, 10:03 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

If the bbb.xsd and ccc.xsd documents are included in aaa.xsd, do you need to add them to the schema cache as well? Shouldn't the pareser do this for you?

--

Joe
 
Old February 15th, 2004, 09:07 AM
Registered User
 
Join Date: Feb 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by joefawcett
 If the bbb.xsd and ccc.xsd documents are included in aaa.xsd, do you need to add them to the schema cache as well? Shouldn't the pareser do this for you?

--

Joe
I have tried this. The xml validates in xmlspy, but fails to validate using

 XML := CreateOLEObject('MSXML2.DOMDocument.4.0');
  Xml.validateOnParse := False;
  XML.resolveExternals := true;
  XML.async := false;
  XML.load('aaa.xML');

is there a bug with msxml2 ?
 
Old February 15th, 2004, 10:18 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I believe you first need to create a SchemaCollection with validateOnLoad set to true if you want to automatically bring in included/imported schemas (I don't know Delphi so check syntax):
Code:
XSDL := CreateOLEObject('MSXML2.XMLSchemaCache.4.0');
XSDL.validateOnLoad = True; 
XSDL.add(NSEdit.Text,'aaa.xsd');
Then create dom with validateOnParse set to true:
Code:
XML := CreateOLEObject('MSXML2.DOMDocument.4.0');
XML.validateOnParse := True;
XML.resolveExternals := true;
XML.async := false;
XML.schemas = XSDL;
XML.load(<pathToXml>);
If this doesn't work email me the files and I'll try on my machine.

Joe (MVP - xml)
 
Old February 16th, 2004, 04:37 PM
Registered User
 
Join Date: Feb 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have tried this, and it still fails.
I started off with this added all my XSDs in as XSDL.add(...)

Still getting a undeclared xsd.

What is the best way to send the files. They are noddy so it has to be something basic that is wrong.

How do other people validate XMLs from within code. So many other people have similar problems to this.
If I have to buy some 3rd party product, so be it.
 
Old February 17th, 2004, 11:41 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I have emailed files back. Basically you are using an old schema system not recognised by the newer msxml parser. I have corrected the schema to be inline with current usage, hope this helps.

Joe (MVP - xml)





Similar Threads
Thread Thread Starter Forum Replies Last Post
XML validation with XSD ksskumar XML 0 October 12th, 2007 04:46 AM
XML validation error alz6z XML 1 May 3rd, 2007 11:06 AM
XML Validation AdamPengelly C# 4 September 8th, 2006 06:36 AM
xml validation with xsd amolkad XML 0 June 24th, 2004 06:02 AM
xml validation error kreddy XML 0 August 20th, 2003 12:16 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.