Skip to content

Consistent Select/Query interface with xmlquery #7

Open
@Maldris

Description

@Maldris

In the sibling xmlquery package, the Node struct has public methods;
SelectElement(name string) *Node and
SelectElements(name string []*Node

jsonquery by comparison only has SelectElement.

Given both packages export the global function Find and FindOne both can obviously be implemented for JSON, as they already are.

I propose a change where jsonquery's SelectElement implementation mimics xmlquery's and internally calls FindOne, and similarly add SelectElements that internally calls Find.

To this end, both node types can be identified and used with an interface of

type Selector interface {
	InnerText() string
	SelectElement(name string) Selector
	SelectElements(name string) []Selector
}

Allowing basic manipulation of both file types to only differ during load.

The alternative to this being using Query and QueryAll to allow errors to be returned, instead of simply returning a nil result/panicking, or implementing both sets as methods in each package and allowing users to make the selection.

Is this proposal sound and within the intended scope of this project?
If so I will make the changes and a pull request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions