How to parse YAML file and create a XML template?
I have a yaml file file which looks like below:
ElementAttr1Format: basic
ElementAttr1Name: Common Name
ElementAttr1Updated: true
ElementAttr1Value:
Derived:
Name: field1
Provider: profile
Shared: false
Value: displayName
FieldNum: 13
ElementAttr2Format: basic
ElementAttr2Name: Email Address
ElementAttr2Value:
Derived:
Name: field2
Provider: profile
Shared: false
Value: mail
FieldNum: 7
I want to parse this YAML file and find in resultant dictionary all keys which are like "ElementAttrName". Map all dictionary values identified by creating a xml template for those identified keys in yaml with their values mapped to a specific xml value.
For Ex-
yaml attr | xml value |
---|---|
common name | cn |
So, I have to maintain this map for each specified key identified in yaml which needs to be mapped to a specific xml value when creating a template.
I am maintaining the yaml and corresponding value as a dataframe now. Below is code snippet for same.
attrmap = {
"yamlattr" : ["Email Address,Last Name","First Name","Department","Common Name"]
"xmlValue" : ["mail","sn","givenName","dept","cn"]
}
Sample XML Template:
<root>
<child alias="/an">
<Attribute name="map">
<Value>mail=email</Value>
<Value>Common Name=cn</Value>
</Attribute>
</child>
</root>
Can someone please suggest me with an approach or a sample example with doc. which I can refer to so that I can implement the same for my use case.