0

I want to assign below mentioned xml values to a string like this

Dim test As String

test = ... ?

Where the XML should contain:

      <RptVer>1</RptVer>

      <RptTyp>1</RptTyp>

    </RptInfo>

</InstRptRoot>

How can I do this and also preserve the formatting (ie linebreaks, spacing, etc.)?

2
  • 2
    test = "<RptInfo><RptVer>1</RptVer><RptTyp>1</RptTyp></RptInfo>" ? Commented May 30, 2018 at 15:36
  • how to add spaces if it goes beyond one line? Commented May 30, 2018 at 15:52

1 Answer 1

3

Mark answered your question, I'll answer your second question:

Dim test As String

test = "<RptInfo>" & vbCrLf & vbCrLf & _
       vbTab & "<RptVer>1</RptVer>" & vbCrLf & vbCrLf & _
       vbTab & "<RptTyp>1</RptTyp> & vbCrLf & vbCrLf & _
      "</RptInfo>"

Assuming you want it double-spaced and indented. You had also missed the leading tag, but MarkL caught that as well.

Sign up to request clarification or add additional context in comments.

2 Comments

It can also be worth mentioning that xml processing wise, the CrLf and Tabs are not necessary. They only make it more human readable.
Thanks, that's what I was looking for

Your Answer

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