Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetXML implementation using antchfx/xmlquery #9031

Closed
wants to merge 1 commit into from

Conversation

vanbroup
Copy link
Contributor

An XML data implementation of GetXML using https://github.com/antchfx/xmlquery

Exposing the Node type which allows users to get sub elements, attributes and use xpath filters.

Fixing #4470

@CLAassistant
Copy link

CLAassistant commented Oct 12, 2021

CLA assistant check
All committers have signed the CLA.

@jmooring
Copy link
Member

This PR should also update:

  • docs/content/en/templates/data-templates.md
  • docs/content/en/getting-started/configuration.md

@jmooring
Copy link
Member

I don't understand how I am supposed to use this. With this XML, how do I retrieve the value of body?

{{ $d := getXML "https://www.w3schools.com/xml/note.xml" }}
{{ $d.body }} --> error
{{ $d.note.body }} --> error

@vanbroup
Copy link
Contributor Author

This is an example usage for reading an RSS feed:

{{ $rss := getXML "https://www.example.com/feed/" }}
{{ $items = $items | append ($rss.SelectElements "//item") }}
{{ range $items }}
    <strong>{{ (.SelectElement "title").InnerText }}</strong><br />
    <p>{{ (.SelectElement "description").InnerText | plainify | htmlUnescape }}</p>
    {{ $link := (.SelectElement "link").InnerText }}
    <a href="{{ $link }}">{{ $link }}</a><br />
    <hr>
{{ end }}

@vanbroup
Copy link
Contributor Author

I don't understand how I am supposed to use this. With this XML, how do I retrieve the value of body?

{{ $d := getXML "https://www.w3schools.com/xml/note.xml" }}
{{ $d.body }} --> error
{{ $d.note.body }} --> error
{{ $note := getXML "https://www.w3schools.com/xml/note.xml" }}
{{ ($note.SelectElement "//note//body").InnerText }}

@jmooring
Copy link
Member

@vanbroup Thanks. This is very different than getJSON/getCSV, and as it stands is going to be difficult to explain/support.

@bep
Copy link
Member

bep commented Oct 12, 2021

Thanks for this,

The code looks good, but I'm not merging this now.

I have two comments about this:

  • When we add XML as a data format in Hugo it should work as a new data format where the others work (more or less), e.g. /data and transform.Unmarshal.
  • There is another issue that talks about replacing getJSON (and friends with a resources.GetRemote (or something), which would be format agnostic (also hopefully).
  • I'm not sure how I would expect an XML structure to look like in the templates, but it should be similar to what we have now and not require some special knowledge about some special API.

@bep bep closed this Oct 12, 2021
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants