ATOUTFOX
COMMUNAUTÉ FRANCOPHONE DES PROFESSIONNELS FOXPRO
Visual FoxPro : le développement durable

Forum AtoutFox : Re: [SEPA] fichier XSD   

Sujet

rss Flux RSS des derniers messages

Vous devez vous identifier pour pouvoir poser une question ou répondre.

lun. 10 juin 2013, 17h48
Gregory Adam
Belgique Belgique

atoutfox.public.association

Re: [SEPA] fichier XSD

Hello Cesar,

Interesting question - have done some research

(1) HeadCount.xsd
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<xs:schema xmlns="xsdHeadCount" targetNamespace="xsdHeadCount" xmlns:xs="http://www.w3.org/2001/XMLSchema";>
 <xs:element name='HeadCount' type="HEADCOUNT"/>
 <xs:complexType name="HEADCOUNT">
 <xs:sequence>
 <xs:element name='Name' type='xs:string' maxOccurs='unbounded'/>
 </xs:sequence>
 <xs:attribute name='division' type='xs:int' use='optional' default='8'/>
 </xs:complexType>
</xs:schema>


(2) HeadCount.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<hc:HeadCount xmlns:hc='xsdHeadCount' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
 <Name divisioN='7'>Waldo Pepper</Name>
 <Name Division='88'>Red Pepper</Name>
</hc:HeadCount>


You will notice that the attribute division is misspelled twice

Code to return all errors (source http://msdn.microsoft.com/en-us/library/windows/desktop/ms754649(v=vs.85).aspx )
function XmlValidateTest()

  local xmlFile, xsdFile
  xmlFile = 'd:\tmp\xml\HeadCount.xml'
  xsdFile = 'd:\tmp\xml\HeadCount.xsd'

  local xsdObj, schemaObj, xmlObj

  && read schema
  xsdObj = createObject('Msxml2.DOMDocument.6.0')
  xsdObj.Async = .f.
  xsdObj.ValidateOnParse = .t.

  =m.xsdObj.Load( m.xsdFile)


  schemaObj = createObject('Msxml2.XmlSchemaCache.6.0')
  local nameSpace
  nameSpace = 'xsdHeadCount'

  =m.schemaObj.Add(m.nameSpace, m.xsdObj)

  xmlObj = createObject('Msxml2.DOMDocument.6.0')
  xmlObj.Async = .f.
  xmlObj.ValidateOnParse = .f.

  =xmlObj.setProperty('MultipleErrorMessages', .t.)


  =m.xmlObj.Load(m.xmlFile)
  xmlObj.Schemas = m.schemaObj


  local parseError
  parseError = m.xmlObj.Validate()

  if( parseError.errorCode == 0 )
    ?'OK'
  else
    ? 'There are ', parseError.allErrors.length, ' parse errors'

     i = 0
     for i = 0 to  parseError.allErrors.length-1
       ? replicate('_', 50)
      errorObj= parseError.allErrors.Item(i)
      ? 'Error #', m.i+1

      ? 'error validating ', errorObj .errorCode
       ? 'error: ' , errorObj .errorCode
      ? 'reason:' , errorObj .reason
       ? 'source: ', errorObj .srcText
      ? 'location: ', errorObj .errorXPath
    endfor
   endif


endfunc


Journal

Cesar Ch pense que ce message est la bonne réponse ou qu'il est utile
Permalink : http://www.atoutfox.org/nntp.asp?ID=0000012089
20 286 messages dans le forum • Liste complète des messages

www.atoutfox.org - Site de la Communauté Francophone des Professionnels FoxPro - v3.4.0 - © 2004-2026.
Cette page est générée par un composant COM+ développé en Visual FoxPro 9.0-SP2-HF3