Skip to content

Adding xml element with attribute to logback.xml #1125

Answered by mikefarah
MarcoHuigen asked this question in Q&A

You must be logged in to vote

Hi - sorry for the late response.

So when yq parses this xml, 'appender-ref' is an array (as it appears multiple times). All you need to do is add another item to that array.

If it helps (it did for me) first keep the output as yaml (omit the -o=xml) to get an understanding of what happening under the hood.

Regardless:

yq '.configuration.root.appender-ref += {"+ref": "YETANOTHERLOG"}' sample.xml -p=xml  -o=xml

Replies: 3 comments 7 replies

You must be logged in to vote
2 replies
@MarcoHuigen

@mikefarah

Answer selected by MarcoHuigen

You must be logged in to vote
3 replies
@mikefarah

@mikefarah

@austinarbor

You must be logged in to vote
2 replies
@code-sergeant

@mikefarah

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