Skip to content

Commit

Permalink
Merge pull request #8 from webability-go/late-night
Browse files Browse the repository at this point in the history
patch v0.0.7
  • Loading branch information
metalwolf committed Apr 9, 2020
2 parents 7def795 + 39712a7 commit bcdcb0b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -20,6 +20,10 @@ TO DO:
Version Changes Control
=======================

v0.0.7 - 2020-03-08
------------------------
- Added MarshalXML on Node to build XML code from nodes

v0.0.6 - 2020-03-08
------------------------
- Correction on assigning the node data (concatened, only if some info into it: will ignore spaces and line formatting characters)
Expand Down
29 changes: 27 additions & 2 deletions node.go
Expand Up @@ -34,7 +34,7 @@ type NodeDef interface {

// DecodeAttributes(xml.StartElement)
UnmarshalXML(*xml.Decoder, xml.StartElement) error
MarshalXML(*xml.Encoder) error
MarshalXML(*xml.Encoder, xml.StartElement) error
UnmarshalJSON([]byte) error
MarshalJSON() ([]byte, error)
}
Expand Down Expand Up @@ -229,7 +229,32 @@ func (n *Node) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
return nil
}

func (n *Node) MarshalXML(*xml.Encoder) error {
func (n *Node) MarshalXML(e *xml.Encoder, start xml.StartElement) error {

start.Name = xml.Name{"", n.SuperType}
attr := []xml.Attr{}
if n.Type != "" {
attr = append(attr, xml.Attr{xml.Name{"", "type"}, n.Type})
}
if n.ID != "" {
attr = append(attr, xml.Attr{xml.Name{"", "id"}, n.ID})
}
for akey, avalue := range n.attributes {
attr = append(attr, xml.Attr{xml.Name{"", akey}, avalue})
}
start.Attr = attr
e.EncodeToken(start)

if n.Data != "" {
e.EncodeToken(xml.CharData(n.Data))
}

for _, child := range n.children {
if err := e.Encode(child); err != nil {
return err
}
}
e.EncodeToken(start.End())
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion wajaf.go
Expand Up @@ -7,7 +7,7 @@
package wajaf

// VERSION is the used version nombre of the XCore library.
const VERSION = "0.0.6"
const VERSION = "0.0.7"

// LOG is the flag to activate logging on the library.
// if LOG is set to TRUE, LOG indicates to the XCore libraries to log a trace of functions called, with most important parameters.
Expand Down
10 changes: 7 additions & 3 deletions wajaf_test.go
Expand Up @@ -49,16 +49,20 @@ func TestWajaf(t *testing.T) {

func TestWajafLoad(t *testing.T) {

app := NewApplication("manual_application")
app := NewApplication("loaded_application")

data := readfile("testunit/app.code", t)
xml.Unmarshal(data, app)

// fmt.Printf("XML TO APP: %#v\n", app)

s, err := json.Marshal(app)
x, err := xml.Marshal(app)

fmt.Println("XML = ", string(x), err)

// s, err := json.Marshal(app)

fmt.Println("JSON = ", string(s), err)
// fmt.Println("JSON = ", string(s), err)

return
}

0 comments on commit bcdcb0b

Please sign in to comment.