2016-07-05 3 views
-1

나는 오랫동안 stringbuilder를 사용 해왔다. 이 경우에는 stringbuilder를 사용하여 긴 XML 청크를 작성한 다음 끝에 웹 서비스에 제출하기 위해 문자열에 넣습니다. ToString에서 모든 큰 따옴표는 큰 따옴표로 바뀝니다.vb.net stringbuilder 큰 따옴표

Dim tXML As New StringBuilder 
Dim tt As String 

tXML.Append("<?xml version=" & """" & "1.0" & """" & " encoding=" & """" & "UTF-8" & """" & "?>") 
tt = tXML.ToString 


'At this point the value of tXML is what I'd expect: 
    {<?xml version="1.0" encoding="UTF-8"?>} 

'However the value of tt is 
    "<?xml version=""1.0"" encoding=""UTF-8""?>" 

'this method of double-quotes produces the same result 
    tXML.Append("<?xml version=""1.0"" encoding=""UTF-8""?>") 

이것은 간단해야하지만 실종 상태입니다. 감사.

+1

당신이 이중 따옴표를 참조하는 것이 정상 디버거를 사용하여 해당 문자열 보면 당신은 AppendFormat – Plutonix

+0

볼 수 있었다. 그들은 실제로 거기에 있지 않습니다. – Steve

+1

이것은 완전히 정상입니다. 디버거는 소스 코드에 작성한 방식대로 문자열을 표시합니다. 텍스트 시각화기를 사용하려면 망원경 아이콘을 클릭하십시오. 그리고 당신은 진짜 문제가 없다는 것을 알게 될 것입니다. –

답변

0

StringBuilder를 사용하여 XML을 어셈블하는 것이 가장 좋은 방법은 아닙니다. VB.Net의 XML 리터럴과 함께 사용할 수있는 Xml 클래스를 사용하지 않는 이유는 무엇입니까?

Imports System.Xml.Linq 

Private Sub createXml() 

    Dim xDoc As New XDocument() 

    xDoc.Declaration = New XDeclaration("1.0", "utf-8", "yes") 

    xDoc.Add(<Root attr="x"> 
       <SomeElement>Some Value</SomeElement> 
      </Root>) 

    xDoc.Save("c:\somefolder\myfile.xml") 

End Sub