How to make the code less redundant xml

@sereganator
maybe you can share the exact element name of the two xml structures on where you want to avoid redundancy.

However there are a few options, that can be checked:

  • extract Workflows / seperate XAML for each structure type: KZVU, KVOKS

  • invoking the relevant branch can be done by a switch statement reacting on Root Elementname or defaultnamespace (was answered in one of your others topics)

  • writing generic retrievals with an injected namespace variable like:

    • first check which structure type you have to process (see above: switch)
    • currentNameSpaceVar = nsVarX
    • retrieval: xDoc.Root.Descendants(currentNameSpaceVar +“Elementname”)(0)…

For setting up retrievals with XPath have a look here (was already shared with you in one of your others topic):

Do some exploration of the String.Format method as well. Could be used as e.g:
String.Format("//{0}:ElementName", varCurrentPrefix)

Also have a look on how to formulate the retrieval with local name only:

//*[local-name()='Element1']//*[local-name()='Element2'] .....

how to refer to an element within an element, and then to its attribute.

in general: xDoc.Root(xnsVar + “ParentElementName”)(0).Element(xnsVar + “ChildElementName”).Attribute(“AttributeName”).Value