0

Given a single XML node like this

<MachineLogFileName overwrite="[bool]"></MachineLogFileName>

and assigned to a variable like this

$validationNode = $validation.xml.SelectSingleNode("//Settings/$($node.name)")

where of course $node.name is 'MachineLogFileName', and a variable $attribute.name of 'overwrite', I want to be able to get the value of that attribute, but only as an attribute. I can use $validationNode.($attribute.name), but IF there was a child node called <overwrite> and wasn't an attribute called 'overwrite' I would end up getting the inner text of the child node. So in a sense I want something like $validationNode.Attributes.($attribute.name). It seems like there is a collection there, with a single attribute in this case, but I can't seem to get the value this way. Ultimately this needs to work with highly variable attribute and child node names, and I could just loop through all the attributes, but I need this in an IF so something like $validationNode.Attributes.($attribute.name) would be ideal. And seems like it should be possible and I am just missing one aspect? I hope.

1

1 Answer 1

1

I want to be able to get the value of that attribute, but only as an attribute. I can use $validationNode.($attribute.name), but IF there was a child node called <overwrite> and wasn't an attribute called 'overwrite'

Use GetAttribute():

$validationNode = $validation.xml.SelectSingleNode("//Settings/$($node.name)")
$attributeValue = $validationNode.GetAttribute($attribute.name)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.