Added document.Verbose field which prints errors to Stderr while reading xml data. Set to false by default.
This commit is contained in:
parent
b95492ab55
commit
4246be06b8
|
@ -12,22 +12,6 @@
|
||||||
Nodes now simply become collections and don't require you to read them in the
|
Nodes now simply become collections and don't require you to read them in the
|
||||||
order in which the xml.Parser finds them.
|
order in which the xml.Parser finds them.
|
||||||
|
|
||||||
xmlx.Document implements both these interfaces:
|
|
||||||
|
|
||||||
type ILoader interface {
|
|
||||||
LoadFile(string) os.Error;
|
|
||||||
LoadString(string) os.Error;
|
|
||||||
LoadStream(*io.Reader) os.Error;
|
|
||||||
}
|
|
||||||
|
|
||||||
type ISaver interface {
|
|
||||||
SaveFile(string) os.Error;
|
|
||||||
SaveString(string) (string, os.Error);
|
|
||||||
SaveStream(*io.Writer) os.Error;
|
|
||||||
}
|
|
||||||
|
|
||||||
This allows you to load/save xml data to and from pretty much any source.
|
|
||||||
|
|
||||||
The Document currently implements 2 simple search functions which allow you to
|
The Document currently implements 2 simple search functions which allow you to
|
||||||
look for specific nodes.
|
look for specific nodes.
|
||||||
|
|
||||||
|
@ -56,6 +40,7 @@ type Document struct {
|
||||||
SaveDocType bool;
|
SaveDocType bool;
|
||||||
Root *Node;
|
Root *Node;
|
||||||
Entity map[string]string;
|
Entity map[string]string;
|
||||||
|
Verbose bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
func New() *Document {
|
func New() *Document {
|
||||||
|
@ -64,7 +49,8 @@ func New() *Document {
|
||||||
Encoding: "utf-8",
|
Encoding: "utf-8",
|
||||||
StandAlone: "yes",
|
StandAlone: "yes",
|
||||||
SaveDocType: true,
|
SaveDocType: true,
|
||||||
Entity: make(map[string]string)
|
Entity: make(map[string]string),
|
||||||
|
Verbose: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,6 +89,9 @@ func (this *Document) LoadString(s string) (err os.Error) {
|
||||||
for {
|
for {
|
||||||
tok, err := xp.Token();
|
tok, err := xp.Token();
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if err != os.EOF && this.Verbose {
|
||||||
|
fmt.Fprintf(os.Stderr, "Xml Error: %s\n", err);
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue