-
-
Notifications
You must be signed in to change notification settings - Fork 79
/
schema.go
46 lines (41 loc) · 1.23 KB
/
schema.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright 2020 - 2024 The xgen Authors. All rights reserved. Use of this
// source code is governed by a BSD-style license that can be found in the
// LICENSE file.
//
// Package xgen written in pure Go providing a set of functions that allow you
// to parse XSD (XML schema files). This library needs Go version 1.10 or
// later.
package xgen
import "encoding/xml"
func (opt *Options) prepareLocalNameNSMap(element xml.StartElement) {
for _, ele := range element.Attr {
if ele.Name.Space == "xmlns" {
opt.LocalNameNSMap[ele.Name.Local] = ele.Value
}
}
}
func (opt *Options) prepareNSSchemaLocationMap(element xml.StartElement) {
var currentNS string
for _, ele := range element.Attr {
if ele.Name.Local == "namespace" {
currentNS = ele.Value
}
if ele.Name.Local == "schemaLocation" {
if _, ok := opt.NSSchemaLocationMap[currentNS]; ok {
continue
}
if isValidURL(ele.Value) {
continue
// TODO: fetch remote schema
// var err error
// if opt.RemoteSchema[ele.Value], err = fetchSchema(ele.Value); err != nil {
// continue
// }
}
opt.NSSchemaLocationMap[currentNS] = ele.Value
}
}
}
func (opt *Options) parseNS(str string) (ns string) {
return opt.LocalNameNSMap[getNSPrefix(str)]
}