4

The Data Binding Wizard in Delphi XE generates classes and interfaces that inherit from Delphi's own implementation of the DOM (ADOM XML v4), which doesn't appear to support validation against schemas - the 'validate on parse' option only works with the MSXML vendor type - as can be seen from the VCL source code and also the behavior of XMLDocument component in the IDE. All validation support seems to be based on the MSXML implementation, which makes the wizard useless if you need schema validation. Am I missing something here?

Is there a way to configure the binding wizard (or some underlying utility) to generate classes and interfaces based on MSXML, which supports validation?

Or are there calls/interfaces that support schema validation using Delphi's implementation of ADOM XML that I haven't come across?

MNG

Vector
  • 10,879
  • 12
  • 61
  • 101
  • It would help if you could give some sample XSD + code in your question that works with the currently generated code (but doesn't do validation) + some MSXML sample code that does validation against the XSD. Then the community can have a look and try to mix the two. Please edit your question and add the above things. – Jeroen Wiert Pluimers Apr 28 '11 at 10:47

1 Answers1

2

The code generated by the XML Data Binding Wizard depends on the units XMLDoc and XMLIntf (the document references are TXMLDocument and IXMLDocument).

IXMLDocument is implemented by TXMLDocument, which is the generic wrapper around XML DOMs supported by Delphi. The DOM used by TXmlDocument depends on the value of the DOMVendor property.

If a DOMVendor is not specified when activating a TXMLDocument instance (it isn't as the XML Data Binding Wizard generates DOM neutral code), then the actual XML DOM used depends on these two members of the XMLDOM unit:

var
  DefaultDOMVendor: string;
  DOMVendors: TDOMVendorList;

In your case, it appears that the MSXML DOM is either the default XML DOM, or the only XML DOM available.

So you should check the values of DefaultDOMVendor and the DOMVendors list.

It would certainly help if you can edit your question with the values of the above, and a reproducible case that shows how you observed the MSXML DOM is being used.

Edit:

You can fore the run-time use of a specific XML DOM vendor right before you load your XML root node, or create a new XML root node like this:

DefaultDOMVendor = 'MSXML';
Jeroen Wiert Pluimers
  • 23,965
  • 9
  • 74
  • 154
  • @Jeroen - The default in the binding Wizard is for the generic implementation and I found no option to force it to use MSXML - that's my question: can that be done, and if so, how. Maybe the wizard runs a command line tool and you can pass it parameters to generate MSXML interfaces - but this option is not exposed in the wizard. – Vector Apr 25 '11 at 13:00
  • Since you can change the DOM at run-time (see my edit): why would you want to have it bound to a vendor specific XML DOM of which the behaviour is specific which MSXML version is installed on your end-user system? (see for instance these links for issues with MSXML 6 http://stackoverflow.com/questions/4346060/msxml6-error-loading-valid-windows-1252-document-system-error-2146697210 and MSXML 4+ http://stackoverflow.com/questions/5511844/delphi-xpath-xml-query/5512248#5512248 ) – Jeroen Wiert Pluimers Apr 25 '11 at 16:13
  • @Jeroen - not sure you understand my question. I'm talking about something that happens at compile time - if you give the databinding util a schema, it generates classes and interfaces that allow you to access any document complying with your schema with you having to write any XML parsing code - the generated code encapsulates it all. You use that generated unit at run time in your project to access and manipulate XML data in your application. However the generated classes are not based on MSXML and don't seem to support schema validation, which is something I like to rely on. – Vector Apr 25 '11 at 23:36
  • And User not having MSXML is no problem-I determine what is installed on users' machines -locked down corporate environment. – Vector Apr 25 '11 at 23:50
  • @Mikey: I did understand the first part of your question (the generated code not being bound to MSXML at compile time). That is no problem, as at run-time you can force it to use MSXML (see the edit in my answer). – Jeroen Wiert Pluimers Apr 27 '11 at 09:32
  • @Mikey: about the second part of your question (validate-on-parse), I think you can get that to work. It would help if you could give some sample XSD + code in your question that works with the currently generated code (but doesn't do validation) + some MSXML sample code that does validation against the XSD. Then the community can have a look and try to mix the two. – Jeroen Wiert Pluimers Apr 27 '11 at 09:35
  • @Jeroen - I gather that you mean I can create and manipulate the XMLdoc using the ADOM API and once I have the XMLDoc I can flip the vendor type and validate, etc. This might work - will have to have hack around. Tnx, MNG – Vector Apr 27 '11 at 19:16
  • @Jeroen -maybe can do **exactly** what I want in the 'options' dialog of the bindWizard-gives there option to define names of types generated. So setting to MSXML types, generating the unit, and using MSXML2_TLB instead of the Delphi units should give me what I need. Tried it now but some reason the wizard didn't generate the types I asked for - DK if it's because I goofed at something, or because there's a bug in the wizard or because it won't allow to set to the MSXML types (although you can set it to types that the compiler won't recognize by default with units generated and used) – Vector Apr 28 '11 at 05:33