forked from lestrrat-go/libxml2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First pass at solving lestrrat-go#67
- Loading branch information
Showing
8 changed files
with
237 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package option | ||
|
||
const ( | ||
OptKeyWithURI = `with-uri` | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package option | ||
|
||
type Interface interface { | ||
Name() string | ||
Value() interface{} | ||
} | ||
|
||
type Option struct { | ||
name string | ||
value interface{} | ||
} | ||
|
||
func New(name string, value interface{}) *Option { | ||
return &Option{ | ||
name: name, | ||
value: value, | ||
} | ||
} | ||
|
||
func (o *Option) Name() string { | ||
return o.name | ||
} | ||
func (o *Option) Value() interface{} { | ||
return o.value | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<xs:schema targetNamespace="http://xmlsoft.org/" | ||
xmlns="http://xmlsoft.org/" | ||
xmlns:libxml2="http://xmlsoft.org/" | ||
xmlns:xs="http://www.w3.org/2001/XMLSchema" | ||
elementFormDefault="qualified" | ||
attributeFormDefault="unqualified"> | ||
|
||
|
||
<xs:include schemaLocation="../lib/types/cksum.xsd"/> | ||
<xs:include schemaLocation="../lib/types/std.xsd"/> | ||
|
||
<xs:element name="libxml2"> | ||
<xs:complexType> | ||
<xs:sequence minOccurs="1" maxOccurs="unbounded"> | ||
<xs:element name="sub"> | ||
<xs:complexType> | ||
<xs:sequence minOccurs="1" maxOccurs="unbounded"> | ||
<xs:element name="sub2" type="xs:string" minOccurs="0"/> | ||
<xs:element name="nestedInclude" type="t_cksum_hash" minOccurs="1" maxOccurs="1"/> | ||
</xs:sequence> | ||
<xs:attribute name="attrOpt" use="optional" default="none specified" type="xs:string"/> | ||
<xs:attribute name="attrReq" use="required" type="t_std_nonempty"/> | ||
<xs:attribute name="attrBoolNoDef" use="optional" type="xs:boolean"/> | ||
</xs:complexType> | ||
</xs:element> | ||
</xs:sequence> | ||
</xs:complexType> | ||
</xs:element> | ||
|
||
</xs:schema> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package xsd | ||
|
||
import ( | ||
"net/url" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/lestrrat-go/libxml2/internal/option" | ||
) | ||
|
||
// WithPath provides a hint to the XSD parser as to where the | ||
// document being parsed is located at. | ||
// | ||
// This is useful when you must resolve relative paths inside a | ||
// document, because to use relative paths the parser needs to | ||
// know the reference location (i.e. location of the document | ||
// being parsed). In case where you are parsing using `ParseFromFile()` | ||
// this is handled automatically by the `ParseFromFile` method, | ||
// but if you are using `Parse` method this is required | ||
// | ||
// If the path is provided as a relative path, the current directory | ||
// should be obtainable via `os.Getwd` when this call is made, otherwise | ||
// path resolution may fail in weird ways. | ||
func WithPath(path string) Option { | ||
if !filepath.IsAbs(path) { | ||
if curdir, err := os.Getwd(); err == nil { | ||
path = filepath.Join(curdir, path) | ||
} | ||
} | ||
|
||
return WithURI( | ||
(&url.URL{ | ||
Scheme: `file`, | ||
Path: path, | ||
}).String(), | ||
) | ||
} | ||
|
||
func WithURI(v string) Option { | ||
return option.New(option.OptKeyWithURI, v) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters