Seite 1 von 1

lxml Schematron Problem

Verfasst: Mittwoch 6. April 2011, 14:27
von m0ps1234
hi,
folgendes Problem:
Ich möchte den Schematron-Validierer von lxml nutzen.
Implementiert habe ich das Ganze so (natürlich wurden hier nur die Teile gepostet, welche zum validieren nötig sind...):

Code: Alles auswählen

from lxml import etree, isoschematron

self.__schematron = isoschematron.Schematron(etree.parse('d:/Schematron.sch'))
self.__xmlDoc = etree.parse(xmlFileName, parser=etree.XMLParser(strip_cdata=False))

self.__schematron.validate(self.__xmlDoc)
Mein Schematron sieht so aus:

Code: Alles auswählen

<?xml version="1.0" encoding="utf-8"?>
<schema xmlns="http://www.ascc.net/xml/schematron">
    
    <pattern name="test">
        <rule context="TestNode">
            <assert test="@name">Kein name-Attribut</assert>
        </rule>
    </pattern>
 
</schema>
Meine xml sieht grob so aus:

Code: Alles auswählen

<TestNode>
    <DeviceTest name="BlaBlaBla">
        <parent name="IrgendeinName">
             ...

        </parent>
    </DeviceTest>
</TestNode>
Nun einige Frage:
1. Ich habe 2 Validatoren getestet: lxml und jing. Wieso benötige ich für den lxml im Schematron diesen Namespace: http://purl.oclc.org/dsdl/schematron
in jing jedoch diesen: http://www.ascc.net/xml/schematron ??? Beide unterscheiden sich schon heftig voneinander...

2. Egal was ich in mein report-test-Attribute schreibe bzw in mein context-Attribute (auch das Beispiel oben), es wird irgendwie immer zu True ausgewertet?? Sowohl bei Jing, als auch bei lxml... Was passt da denn nicht?

Bin am verzweifeln. -.-*

Re: lxml Schematron Problem

Verfasst: Mittwoch 6. April 2011, 16:51
von sma
Ich kann dir nur das Informationsbröckchen anbieten, dass http://www.ascc.net/xml/schematron eine veraltete Version ist.

Auf deren Webseite steht:
What about Schema­tron 1.5?

Schema­tron 1.n were the orig­i­nal pre-stan­dard ver­sion of Schema­tron from Academia Sinica, Taiwan. Schema­tron 1.6 was the last ver­sion of that line, and the ISO Schema­tron im­ple­men­ta­tion has taken over. Schema­tron 1.n and ISO Schema­tron use dif­fer­ent names­paces, but a Schema­tron 1.n schema can be con­vert­ed into an ISO Schema­tron schema with min­i­mal changes. Schema­tron 1.n is now ob­so­lete and the Schema­tron 1.n skele­ton is no longer main­tained; ISO Schema­tron is the ap­pro­pri­ate choice for new pro­jects.
Was jing ist, weiß ich nicht, aber ich würde mal vermuten, das wurde nicht auf die "offizielle" Version umgestellt. Vielleicht prüfst du mal auf http://www.schematron.com/, ob dich dich an den Standard hälst mit deinem Schema.

Stefan