2

Can anybody help me to create function that will accept for parameter xml string and return a formatted string as response that after can Example:

<cars>
      <ford>
        <model>fiesta</model>
        <model>focus</model>
      </ford>
      <renault>
        <model>twingo</model>
        <model>clio</model>
      </renault>
</cars>

should return

cars:
     ford:
          model=fiesta
          model=focus
     renault:
          model=twingo
          model=clio

1 Answer 1

1

VBScript:

set xmldoc = CreateObject("Microsoft.XMLDOM")
xmldoc.async = false
xmldoc.loadXML ""               & _
  "<cars>"                      & _
  "    <ford>"                  & _
  "      <model>fiesta</model>" & _
  "      <model>focus</model>"  & _
  "    </ford>"                 & _
  "    <renault>"               & _
  "      <model>twingo</model>" & _
  "      <model>clio</model>"   & _
  "    </renault>"              & _
  "</cars>"

test.value = buildStructure(xmlDoc.DocumentElement, "")

function buildStructure(xmlParent, identLevel)

  dim result, xmlNode
  result = identLevel & xmlParent.nodeName & ": " & chr(13)

    for each xmlNode in xmlParent.SelectNodes("*")
        if not xmlNode.SelectSingleNode("*") is nothing Then
           result = result & buildStructure(xmlNode, identLevel & "   ")
        else
           result = result & identLevel & "   " & _
                    xmlNode.nodeName & " = " & xmlNode.text & chr(13)
        End if
    next

    buildStructure = result

end function
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.