cleaned up the LoadString() loop a bit.
This commit is contained in:
parent
b62b923ed2
commit
b95492ab55
|
@ -109,39 +109,33 @@ func (this *Document) LoadString(s string) (err os.Error) {
|
||||||
t1, ok := tok.(xml.SyntaxError);
|
t1, ok := tok.(xml.SyntaxError);
|
||||||
if ok {
|
if ok {
|
||||||
err = os.NewError(t1.String());
|
err = os.NewError(t1.String());
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
t2, ok := tok.(xml.CharData);
|
t2, ok := tok.(xml.CharData);
|
||||||
if ok {
|
if ok && ct != nil {
|
||||||
if ct != nil {
|
ct.Value = strings.TrimSpace(string(t2));
|
||||||
ct.Value = strings.TrimSpace(string(t2))
|
|
||||||
}
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
t3, ok := tok.(xml.Comment);
|
t3, ok := tok.(xml.Comment);
|
||||||
if ok {
|
if ok && ct != nil {
|
||||||
t := NewNode(NT_COMMENT);
|
t := NewNode(NT_COMMENT);
|
||||||
t.Value = strings.TrimSpace(string(t3));
|
t.Value = strings.TrimSpace(string(t3));
|
||||||
if ct != nil {
|
ct.AddChild(t);
|
||||||
ct.AddChild(t)
|
|
||||||
}
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
t4, ok := tok.(xml.Directive);
|
t4, ok := tok.(xml.Directive);
|
||||||
if ok {
|
if ok && ct != nil {
|
||||||
t := NewNode(NT_DIRECTIVE);
|
t := NewNode(NT_DIRECTIVE);
|
||||||
t.Value = strings.TrimSpace(string(t4));
|
t.Value = strings.TrimSpace(string(t4));
|
||||||
if ct != nil {
|
ct.AddChild(t);
|
||||||
ct.AddChild(t)
|
|
||||||
}
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
t5, ok := tok.(xml.StartElement);
|
t5, ok := tok.(xml.StartElement);
|
||||||
if ok {
|
if ok && ct != nil {
|
||||||
t := NewNode(NT_ELEMENT);
|
t := NewNode(NT_ELEMENT);
|
||||||
t.Name = t5.Name;
|
t.Name = t5.Name;
|
||||||
t.Attributes = make([]Attr, len(t5.Attr));
|
t.Attributes = make([]Attr, len(t5.Attr));
|
||||||
|
@ -149,9 +143,7 @@ func (this *Document) LoadString(s string) (err os.Error) {
|
||||||
t.Attributes[i].Name = v.Name;
|
t.Attributes[i].Name = v.Name;
|
||||||
t.Attributes[i].Value = v.Value;
|
t.Attributes[i].Value = v.Value;
|
||||||
}
|
}
|
||||||
if ct != nil {
|
ct.AddChild(t);
|
||||||
ct.AddChild(t)
|
|
||||||
}
|
|
||||||
ct = t;
|
ct = t;
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -186,13 +178,11 @@ func (this *Document) LoadString(s string) (err os.Error) {
|
||||||
pos = strings.Index(this.StandAlone, `"`);
|
pos = strings.Index(this.StandAlone, `"`);
|
||||||
this.StandAlone = this.StandAlone[0:pos];
|
this.StandAlone = this.StandAlone[0:pos];
|
||||||
}
|
}
|
||||||
} else {
|
} else if ct != nil {
|
||||||
t := NewNode(NT_PROCINST);
|
t := NewNode(NT_PROCINST);
|
||||||
t.Target = strings.TrimSpace(t6.Target);
|
t.Target = strings.TrimSpace(t6.Target);
|
||||||
t.Value = strings.TrimSpace(string(t6.Inst));
|
t.Value = strings.TrimSpace(string(t6.Inst));
|
||||||
if ct != nil {
|
ct.AddChild(t);
|
||||||
ct.AddChild(t)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue