ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Validating data at data entry and XSD (https://www.excelbanter.com/excel-programming/369545-validating-data-data-entry-xsd.html)

HSalim[MVP]

Validating data at data entry and XSD
 
Hi,
Apologies for the multi-post; I am not sure where this question belongs. I
am fairly new to XML.

I have an XML Schema that includes restrictions (such as data types, valid
values, data length ...) - see snippet below

Although Excel will validate the data against the schema at save time, I
need real-time validation. I thought it might be possible to achieve this
with some vba code byu copying the restrictions to Excel's own validation.

I can import(Add) the schema into an XML map, but then I don't know how to
read the schema to set the data validation
The example in the help file is not very helpful - or it indicates that the
programmer must know the schema before addng it to an XML Map.

The pseudo code for what I want to achieve is
import schema file
create list object
for each element or attribute in schema,
map to column
read element restrictions
add column validation - this may not be fully implementable as XSD
schema restrictions can be fairly powerful
move to next column
next element

Thanks in advance for any suggestions /advice

HS
--------------------------------
<?xml version="1.0" encoding="UTF-8"?
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
<xsd:element name="Dalexml" nillable="true"
<xsd:complexType
<xsd:sequence minOccurs="0"
<xsd:element name="inventoryItem" form="unqualified" nillable="true"
minOccurs="0" maxOccurs="unbounded"
<xsd:complexType
<xsd:sequence
<xsd:element name="handle" minOccurs="0"/
<xsd:element name="name" form="unqualified" nillable="true"
minOccurs="0"
<xsd:simpleType
<xsd:restriction base="xsd:string"/
</xsd:simpleType
</xsd:element
<xsd:element name="displayName" form="unqualified" nillable="true"
minOccurs="0"
<xsd:simpleType
<xsd:restriction base="xsd:string"
<xsd:maxLength value="60"/
<xsd:minLength value="1"/
<xsd:whiteSpace value="preserve"/
</xsd:restriction
</xsd:simpleType
</xsd:element
<!-- snip remaining elements --
</xsd:sequence
</xsd:complexType
</xsd:element
</xsd:sequence
</xsd:complexType
</xsd:element
</xsd:schema

-----------------------------


strSchemaLocation = "C:\temp\testschema3.xsd"
ActiveWorkbook.XmlMaps.Add(strSchemaLocation, "Dalexml").Name =
"Dalexml_Map"

' Specify the schema map to use.
Set InvMap = ActiveWorkbook.XmlMaps("Dalexml_Map")

' Create a new list.
Set lstInv = ActiveSheet.ListObjects.Add

' Specify the first element to map.Can I "extract" the path for dynamic
mapping?
strXPath = "/Dalexml/inventoryItem/Name" ' <<< do I have to know the
path?

' Map the element.
lstContacts.ListColumns(1).XPath.SetValue InvMap, strXPath






All times are GMT +1. The time now is 04:57 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com