Skip to content

Stripping optional XML attributes #441

Closed Answered by TomWright
dkx0stv asked this question in Q&A
Discussion options

You must be logged in to vote

OK here's what I came up with:

$ dasel -f in.xml 'response.result.entry.all().filter(or(equal(-name,123),equal(-name,456))).variable.entry.all().filter(equal(-name,ipv4)).type.orDefault(ip.#text,ip)'
1.2.3.4
5.6.7.8

Two parts worth mentioning...

You can extend the query to include multiple serials like this if desired to save you a loop.
filter(or(equal(-name,123),equal(-name,456)))

The change that gives you the expected output here is: orDefault(ip.#text,ip)

If it can't find the ip.#text element, it will fallback and just return ip.

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@dkx0stv
Comment options

@TomWright
Comment options

Answer selected by TomWright
Comment options

You must be logged in to vote
1 reply
@TomWright
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants