Skip to content

Commit

Permalink
fix list keys in xmlstore
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Nightingale committed Oct 13, 2024
1 parent f24d5b1 commit eedb79d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
24 changes: 18 additions & 6 deletions internal/xmlstore/xmlstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ func (el xmlElement) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
if err := e.EncodeToken(start); err != nil {
return err
}
e.EncodeElement(el.Children, start)
if el.Value != "" {
e.EncodeToken(xml.CharData(el.Value))
} else {
e.EncodeElement(el.Children, start)
}

return e.EncodeToken(start.End())
}
Expand All @@ -66,20 +70,28 @@ func (el *xmlElement) insert(yangMod *yang.Entry, path []string) {
} else {
// Add new element, then insert into that
// fmt.Printf("Adding %v to x%vx\n", ss[0], el.XMLName.Local)
nv := strings.Split(ss[0], "=")
if el.XMLName.Local == "" {
el.XMLName.Local = ss[0]
el.XMLName.Local = nv[0]
if len(nv) > 1 {
el.Value = nv[1]
}
el.XMLName.Space = yangMod.Namespace().Name
el.Children = append(el.Children, &xmlElement{xml.Name{Space: "", Local: ss[1]}, "", []xmlElementInterface{}})
if len(ss) == 2 {
return
}
el.Children[len(el.Children)-1].insert(nil, ss[2:])
} else {
el.Children = append(el.Children, &xmlElement{xml.Name{
Local: ss[0],
child := xmlElement{xml.Name{
Local: nv[0],
// Space: el.XMLName.Space
},
"", []xmlElementInterface{}})
}, "", []xmlElementInterface{}}
if len(nv) > 1 {
child.Value = nv[1]
}

el.Children = append(el.Children, &child)
if len(ss) == 1 {
return
}
Expand Down
7 changes: 6 additions & 1 deletion netconf_lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,10 @@ func getYangModule(s *netconf.Session, yangMod string) *yang.Module {
fmt.Printf("Request reply error1: %v\n", error)
return nil
}
if reply.Errors != nil && len(reply.Errors) > 0 {
fmt.Printf("Request reply error1: %v\n", reply.Errors[0])
return nil
}
// log.Debugf("Request reply: %v, error: %v\n", reply.Data, error)
// re, _ := regexp.Compile("\n#[0-9]+\n")
// strs := re.FindAllStringSubmatch(reply.Data, 10)
Expand Down Expand Up @@ -643,7 +647,8 @@ func sendNetconfRequest(s *netconf.Session, requestLine string, requestType requ
} else if requestType == validate {
error = s.Validate(context.Background(), netconf.Candidate)
log.Debugf("Request reply: %v, error: %v\n", reply, error)
} else if requestType == getConf || requestType == getOper {
// } else if requestType == getConf || requestType == getOper {
} else {
rpc := ncRequest
reply, error = s.Do(context.Background(), &rpc)
if error != nil {
Expand Down

0 comments on commit eedb79d

Please sign in to comment.