I have a slew of classes that I generated with xsd.exe for a restful web service I'm trying to consume. The primary request class has a number of other classes as properties, but one of them is expected to be serialized and inserted in a CDATA tag. But I can't for the life of me figure out how to do this effeciently... The best I've come up with is a function that looks like this:
There HAS to be a better way to do this. What am I missing? (I have about 8 different classes I'd have to do this for if there's no better way!)Code:Function getCData(ByVal req as DetailsRequest) Dim dummy as New XMLDocument Dim s as New XmlSerializer(GetType(DetailsRequest)) Dim w as New StringWriter s.Serialize(w, req) dummy.Load(w.ToString()) 'see notes below Dim nodes as XmlNodeList = dummy.GetElementsByTagName("DetailsRequest") Dim cdataContent as String = "<![CDATA[" & yada yada & "]]>" return cdataContent End Function
The xml being generated by w.ToString() looks like this:
What I need this function to ouput:Code:<?xml version="1.0" encoding="utf-16"> <DetailsRequest xmlns:si = "http://www.w3.org/2001/XMLSchema-instance" xmlns:sd = "http://www.w3.org/2001/XMLSchema"> <TaskId>123456789</TaskId> </DetailsRequest>
Code:<![CDATA[<DetailsRequest xmlns:si = "http://www.w3.org/2001/XMLSchema-instance" xmlns:sd = "http://www.w3.org/2001/XMLSchema"><TaskId>123456789</TaskId></DetailsRequest>]]>




Reply With Quote
