goxhparser

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 3, 2022 License: MIT Imports: 8 Imported by: 0

README

goxhparser

See example folder

SIMPLE

    parser := goxhparser.NewParser("./example/golang_useful.xml")
    err := parser.Exec()
    if err != nil {
        log.Fatalln(err)
    }

    for _, content := range parser.Content {
        fmt.Println(content)
    }	

GOROUTINES

   var wg sync.WaitGroup
   var mu sync.Mutex
   parser := goxhparser.NewParser("./example/golang_useful.xml")
   err := parser.XMLToStruct()
   if err != nil {
       log.Fatalln(err)
   }
   for _, value := range parser.Service.Sources {
       wg.Add(1)
       go func(source goxhparser.Source) {
           content,err := parser.Parse(source)
           if err != nil {
               log.Fatalln(err)
           }

           mu.Lock()
           parser.Content = append(parser.Content,content...)
           mu.Unlock()

           wg.Done()
       }(value)
   }
   wg.Wait()

   for _, content := range parser.Content {
       fmt.Println(content)
   }

Documentation

Index

Constants

View Source
const (
	ErrorContentNotFound      = "content not found"
	ErrorServerResponseNot200 = "server response not 200"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Content

type Content struct {
	Title        string
	Link         string
	ShortContent string
	FullContent  string
	Author       string
	Rating       string
	Date         time.Time
	Tags         []string

	SourceTagName string
}

type ContentRuleField

type ContentRuleField struct {
	Field         string `xml:",chardata"`
	Prefix        string `xml:"prefix,attr"`
	Postfix       string `xml:"postfix,attr"`
	BottomPadding int    `xml:"bottom_padding,attr"`
	TopPadding    int    `xml:"top_padding,attr"`
	Bold          bool   `xml:"bold,attr"`
	Italic        bool   `xml:"italic,attr"`
	Features      string `xml:"features,attr"`
	FeaturesSlice
}

type FeaturesSlice

type FeaturesSlice map[string][]string

type Parser

type Parser struct {
	File    []byte
	Service Service
	Content []Content
}

func NewParser

func NewParser(filename string) (*Parser, error)

func (*Parser) Exec

func (parser *Parser) Exec(delay time.Duration) error

func (*Parser) Parse

func (parser *Parser) Parse(source Source) ([]Content, error)

Parse ...

func (*Parser) XMLToStruct

func (parser *Parser) XMLToStruct() error

type Rule

type Rule struct {
	Name      string `xml:"name,attr"`
	Block     string `xml:"block"`
	TagsBlock string `xml:"tags_block"`
	Tags      string `xml:"tags"`
	Title     string `xml:"title"`
	Link      struct {
		Href   string `xml:",chardata"`
		Prefix string `xml:"prefix,attr"`
	} `xml:"link"`
	ShortContent string `xml:"short_content"`
	FullContent  string `xml:"full_content"`
	Author       string `xml:"author"`
	Rating       string `xml:"rating"`
	Date         struct {
		Time      string `xml:",chardata"`
		Layout    string `xml:"layout,attr"`
		Attribute string `xml:"attribute,attr"`
	} `xml:"date"`
}

type Service

type Service struct {
	XMLName     xml.Name `xml:"xml"`
	Title       string   `xml:"title"`
	Name        string   `xml:"name"`
	EntityID    string   `xml:"entity_id"`
	EntityType  string   `xml:"entity_type"`
	Sources     []Source `xml:"source"`
	Rules       []Rule   `xml:"rule"`
	ContentRule struct {
		Content []ContentRuleField `xml:"content"`
	} `xml:"content_rule"`
}

type Source

type Source struct {
	Link     string `xml:",chardata"`
	RuleName string `xml:"rule,attr"`
	TagName  string `xml:"tag,attr"`
	Rule     Rule
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL