Validate WebDAV

S-Soft 646 Reputation points
2023-03-02T09:58:06.8733333+00:00

Hi,

Found this:

    Private DAVErrors As String = Nothing
    Public Function DAVDetector(ByVal InputXML As String) As String
        Dim MyXML As New XmlDocument
        MyXML.LoadXml(File.ReadAllText(InputXML))
        Dim MySchema As XmlReader = XmlReader.Create(New StringReader(My.Resources.AppResources.webdav))
        MyXML.Schemas.Add("", MySchema)
        MyXML.Validate(AddressOf ValidationEventHandler)
        DAVDetector = DAVErrors
    End Function
    Sub ValidationEventHandler(ByVal sender As Object, ByVal e As Schema.ValidationEventArgs)
        DAVErrors += e.Message + vbCrLf + vbCrLf
    End Sub

My webdav.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="DAV:" xmlns:dav="DAV:" elementFormDefault="qualified">
  <element name="propfind">
    <complexType>
      <choice>
        <sequence>
          <element name="allprop" />
          <element name="include" type="dav:include" minOccurs="0" />
        </sequence>
        <element name="propname" />
        <element name="prop" type="dav:prop" />
      </choice>
    </complexType>
  </element>

  <element name="multistatus">
    <complexType>
      <sequence maxOccurs="1">
        <element ref="dav:response" minOccurs="0" maxOccurs="unbounded" />
        <element name="responsedescription" type="string" minOccurs="0" />
      </sequence>
    </complexType>
  </element>

  <element name="response">
    <complexType>
      <sequence>
        <element name="href" type="anyURI" />
        <choice>
          <sequence>
            <element name="href" type="anyURI" minOccurs="0" maxOccurs="unbounded" />
            <element name="status" type="string" />
          </sequence>
          <element name="propstat" type="dav:propstat" maxOccurs="unbounded" />
        </choice>
        <element ref="dav:error" minOccurs="0" />
        <element name="responsedescription" type="string" minOccurs="0" />
      </sequence>
    </complexType>
  </element>

  <element name="propertyupdate">
    <complexType>
      <choice minOccurs="0" maxOccurs="unbounded">
        <element name="remove" type="dav:prop-remove" />
        <element name="set" type="dav:prop-set" />
      </choice>
    </complexType>
  </element>

  <element name="lockinfo">
    <complexType>
      <sequence>
        <element name="lockscope" type="dav:lockscope" />
        <element name="locktype" type="dav:locktype" />
        <element name="owner" minOccurs="0" type="dav:owner" />
      </sequence>
    </complexType>
  </element>

  <element name="prop" type="dav:prop" />

  <element name="supportedlock">
    <complexType>
      <sequence>
        <element name="lockentry" minOccurs="0" maxOccurs="unbounded">
          <complexType>
            <sequence>
              <element name="lockscope" type="dav:lockscope" />
              <element name="locktype" type="dav:locktype" />
            </sequence>
          </complexType>
        </element>
      </sequence>
    </complexType>
  </element>

  <complexType name="owner" mixed="true">
    <sequence>
      <any namespace="##other" minOccurs="0" maxOccurs="unbounded" />
    </sequence>
    <anyAttribute />
  </complexType>

  <complexType name="lockscope">
    <choice>
      <element name="shared" />
      <element name="exclusive" />
    </choice>
  </complexType>

  <complexType name="locktype">
    <choice>
      <element name="write" />
    </choice>
  </complexType>

  <complexType name="prop-remove">
    <sequence>
      <element name="prop" type="dav:prop" />
    </sequence>
  </complexType>

  <complexType name="prop-set">
    <sequence>
      <element name="prop" type="dav:prop" />
    </sequence>
  </complexType>

  <complexType name="prop">
    <sequence>
      <any namespace="##any" minOccurs="0" maxOccurs="unbounded" />
    </sequence>
  </complexType>

  <complexType name="activelock">
    <sequence>
      <element name="lockscope" type="dav:lockscope" />
      <element name="locktype" type="dav:locktype" />
      <element name="depth">
        <simpleType>
          <restriction base="string">
            <enumeration value="0" />
            <enumeration value="1" />
            <enumeration value="infinity" />
          </restriction>
        </simpleType>
      </element>
      <element name="owner" type="dav:owner" minOccurs="0" />
      <element name="timeout" type="dav:timeout" />
      <element name="locktoken" type="dav:locktoken" minOccurs="0" />
      <element name="lockroot" type="dav:lockroot" />
    </sequence>
  </complexType>

  <simpleType name="timeout">
    <restriction base="string">
      <pattern value="(Infinite)|(Second-\d+)" />
    </restriction>
  </simpleType>

  <complexType name="lockentry">
    <sequence>
      <element name="lockscope" type="dav:lockscope" />
      <element name="locktype" type="dav:locktype" />
    </sequence>
  </complexType>

  <complexType name="lockroot">
    <sequence>
      <element name="href" type="anyURI" />
    </sequence>
  </complexType>

  <complexType name="locktoken">
    <sequence>
      <element name="href" type="anyURI" />
    </sequence>
  </complexType>

  <complexType name="include">
    <sequence>
      <any namespace="##any" minOccurs="0" maxOccurs="unbounded" />
    </sequence>
  </complexType>

  <element name="error">
    <complexType>
      <choice maxOccurs="unbounded">
        <element name="lock-token-matches-request-uri" />
        <element name="lock-token-submitted">
          <complexType>
            <sequence>
              <element name="href" type="anyURI" maxOccurs="unbounded" />
            </sequence>
          </complexType>
        </element>
        <element name="no-conflicting-lock">
          <complexType>
            <sequence>
              <element name="href" type="anyURI" minOccurs="0" maxOccurs="unbounded" />
            </sequence>
          </complexType>
        </element>
        <element name="no-external-entities" />
        <element name="preserved-live-properties" />
        <element name="propfind-finite-depth" />
        <element name="cannot-modify-protected-property" />
        <any namespace="##other" />
      </choice>
    </complexType>
  </element>

  <complexType name="propstat">
    <sequence>
      <element name="prop" type="dav:prop" />
      <element name="status" type="string" />
      <element ref="dav:error" minOccurs="0" />
      <element name="responsedescription" type="string" minOccurs="0" />
      <element name="location" type="dav:location" minOccurs="0" />
    </sequence>
  </complexType>

  <complexType name="location">
    <sequence>
      <element name="href" type="anyURI" />
    </sequence>
  </complexType>
</schema>

My webdav.xsd:

<?xml version="1.0" encoding="utf-8"?>
<g:propertyupdate xmlns:g="DAV:" xmlns:c="urn:schemas:contacts:" xmlns:e="http://schemas.microsoft.com/exchange/" xmlns:mapi="http://schemas.microsoft.com/mapi/" xmlns:x="xml:" xmlns:cal="urn:schemas:calendar:" xmlns:mail="urn:schemas:httpmail:">
  <g:set>
    <g:prop>
      <g:contentclass>urn:content-classes:person</g:contentclass>
      <e:outlookmessageclass>IPM.Contact</e:outlookmessageclass>
      <mail:subject>Mr. Sub Contact</mail:subject>
      <c:givenName>Sub</c:givenName>
      <c:middlename />
      <c:sn>Contact</c:sn>
      <c:cn>Mr. Sub Contact</c:cn>
      <c:fileas />
      <mail:textdescription>		Sub Contact Notes</mail:textdescription>
      <c:fileasid>0</c:fileasid>
      <c:initials />
      <c:nickname />
      <c:namesuffix>Mr.</c:namesuffix>
      <mapi:emaillisttype>1</mapi:emaillisttype>
      <c:o>Blah Co.</c:o>
      <c:department />
      <c:profession />
      <c:title />
      <c:manager />
      <c:secretarycn />
      <c:spousecn />
      <c:personalHomePage />
      <c:businesshomepage />
      <c:ftpsite />
      <c:hobbies />
      <c:customerid />
      <c:account />
      <c:language />
      <c:location />
      <c:governmentid />
    </g:prop>
  </g:set>
</g:propertyupdate>

And I get error:

The targetNamespace parameter '' should be the same value as the targetNamespace 'DAV:' of the schema.

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,169 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,556 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 111.5K Reputation points
    2023-03-02T11:24:59.5433333+00:00

    To solve the first problem, try specifying the name according to the error message:

     MyXML.Schemas.Add("DAV:", MySchema) ' instead of  MyXML.Schemas.Add("", MySchema)
    

    However the input file does not seem to correspond to the schema. For example, the <contentclass> element is not defined. Maybe you should use a different schema.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful