Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
xml-validation
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
vaclab
xml-validation
Commits
91abd2e0
Commit
91abd2e0
authored
6 years ago
by
wactbprot
Browse files
Options
Downloads
Patches
Plain Diff
first working version
parent
32778f68
No related branches found
No related tags found
No related merge requests found
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
README.md
+6
-0
6 additions, 0 deletions
README.md
server.py
+20
-7
20 additions, 7 deletions
server.py
utils.py
+18
-3
18 additions, 3 deletions
utils.py
xsd/DCC_v1.8.1.xsd
+688
-0
688 additions, 0 deletions
xsd/DCC_v1.8.1.xsd
with
732 additions
and
10 deletions
README.md
+
6
−
0
View file @
91abd2e0
...
...
@@ -34,4 +34,10 @@ xmllint --valid --noout 11044_17_DCC_v1.8.1_Au.xml
> source bin/activate
> pip install flask flask_cors xmlschema requests
> ./server
```
### Example
'
``
curl -X POST -H "Content-Type: text/xml" -d @11044_17_DCC_v1.8.1_Au.xml http://localhost:5005/is_valid
``
`
\ No newline at end of file
This diff is collapsed.
Click to expand it.
server.py
+
20
−
7
View file @
91abd2e0
from
flask
import
Flask
,
request
,
Response
from
flask_cors
import
CORS
import
xmlschema
import
utils
as
utils
config
=
utils
.
get_config_dict
()
git_cmd
=
utils
.
git_cmd
(
config
)
## komt später vom server
xsd_file_name
=
'
DCC_v1.8.1.xsd
'
app
=
Flask
(
__name__
)
CORS
(
app
)
...
...
@@ -20,16 +19,30 @@ def version():
@app.route
(
'
/update_xsd
'
,
methods
=
[
'
post
'
])
def
update_xsd
():
app
.
logger
.
debug
(
'
hit update xsd
'
)
## komt später vom server
file_name
=
'
DCC_v1.8.3.xsd
'
xsd_str
=
utils
.
get_xsd
(
config
,
file_name
)
xsd_str
=
utils
.
get_xsd
(
config
,
xsd_file_name
,
from_server
=
True
)
xsd_xml
=
utils
.
parse
(
xsd_str
)
if
xsd_xml
:
res
=
utils
.
save_xsd
(
config
,
xsd_str
,
file_name
)
res
=
utils
.
save_xsd
(
config
,
xsd_str
,
xsd_
file_name
)
return
Response
(
res
,
content_type
=
'
text/xml; charset=utf-8
'
)
@app.route
(
'
/is_valid
'
,
methods
=
[
'
post
'
])
def
is_valid
():
app
.
logger
.
debug
(
'
hit validate
'
)
xml_str
=
request
.
data
xml_tree
=
utils
.
parse
(
xml_str
)
if
xml_tree
:
xsd_str
=
utils
.
get_xsd
(
config
,
xsd_file_name
,
from_server
=
False
)
res
=
utils
.
is_valid
(
xml_str
=
xml_str
,
xsd_str
=
xsd_str
)
if
res
:
ret
=
'
<ok/>
'
else
:
ret
=
'
<error/>
'
return
Response
(
ret
,
content_type
=
'
text/xml; charset=utf-8
'
)
if
__name__
==
'
__main__
'
:
app
.
run
(
host
=
config
[
'
server
'
][
'
host
'
],
port
=
config
[
'
server
'
][
'
port
'
])
\ No newline at end of file
This diff is collapsed.
Click to expand it.
utils.py
+
18
−
3
View file @
91abd2e0
...
...
@@ -2,6 +2,7 @@ import json
import
git
import
requests
from
xml.etree
import
ElementTree
as
ET
import
xmlschema
def
get_config_dict
():
## sollte vielleicht doch xml-datei werden
...
...
@@ -13,9 +14,13 @@ def get_config_dict():
def
git_cmd
(
config
):
return
git
.
cmd
.
Git
(
config
[
'
git
'
][
'
dir
'
])
def
get_xsd
(
config
,
xsd_name
):
url
=
"
{uri}/{xsd_name}
"
.
format
(
uri
=
config
[
'
xsd
'
][
'
url
'
],
xsd_name
=
xsd_name
)
xsd_str
=
requests
.
get
(
url
).
text
def
get_xsd
(
config
,
xsd_name
,
from_server
=
True
):
if
from_server
:
url
=
"
{uri}/{xsd_name}
"
.
format
(
uri
=
config
[
'
xsd
'
][
'
url
'
],
xsd_name
=
xsd_name
)
xsd_str
=
requests
.
get
(
url
).
text
else
:
path_file
=
"
{dir}/{xsd_name}
"
.
format
(
dir
=
config
[
'
xsd
'
][
'
dir
'
],
xsd_name
=
xsd_name
)
xsd_str
=
open
(
path_file
).
read
()
return
xsd_str
...
...
@@ -32,3 +37,13 @@ def parse(xml_str):
tree
=
None
return
tree
def
is_valid
(
xml_str
,
xsd_str
):
tree
=
parse
(
xml_str
)
if
tree
:
schema
=
xmlschema
.
XMLSchema
(
xsd_str
)
return
schema
.
is_valid
(
tree
)
else
:
return
False
\ No newline at end of file
This diff is collapsed.
Click to expand it.
xsd/DCC_v1.8.1.xsd
0 → 100644
+
688
−
0
View file @
91abd2e0
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment