small xml question

  • Thread starter Thread starter deepak
  • Start date Start date
D

deepak

Hi
i want to write the follwoing in vb.net in asp.net.How to write it?

<SXPDictionaryItemsGet Revision="7.5.0">
<DictionaryTypes>
<Item ID="80" />
</DictionaryTypes>
</SXPDictionaryItemsGet>

Cuurently i m using the following code

Function GetDictionaryValues()

Dim strmread As StreamReader
Dim str_response As String
Dim sxp_getdictionaryvalues As String

Dim objInProc As Object
Dim dictionayID As String = "80"

sxp_getdictionaryvalues = "<SXPDictionaryItemsGet Revision=""7.5.0""> "
sxp_getdictionaryvalues = sxp_getdictionaryvalues &
"<DictionaryTypes>"
sxp_getdictionaryvalues = sxp_getdictionaryvalues & " <Item ID>" &
dictionayID & "</Item ID> "
sxp_getdictionaryvalues = sxp_getdictionaryvalues &
"</DictionaryTypes> "
sxp_getdictionaryvalues = sxp_getdictionaryvalues &
"</SXPDictionaryItemsGet> "

but its giving me 50 and not "50" i.e.

<SXPDictionaryItemsGet Revision="7.5.0">
<DictionaryTypes>
<Item ID=50 />
</DictionaryTypes>
</SXPDictionaryItemsGet>

in sxp_getdictionaryvalues variable

which is wrong.Kindly help me

Thanks,
Deepak
(e-mail address removed)
 
sorry,i tried but its not workign as u said.May u try on your side and if it
is working then tell me plz with code....
 
deepak explained :
Hi
Dim dictionayID As String = "80"
sxp_getdictionaryvalues = sxp_getdictionaryvalues & " <Item ID>" &
dictionayID & "</Item ID> "
but its giving me 80 and not "80" i.e.

The value of dictionayID is '80', without the ' s.
If you want to have " in your output, you have to put them in:
sxp_getdictionaryvalues = sxp_getdictionaryvalues & " <Item ID="""
&
dictionayID & """/> "


An other approach would be to use an XmlTextWriter:
(Note: C# syntax, but the objects are the same)

StringBuilder sb = new StringBuilder();
using(StringWriter sw = new StringWriter(sb))
{
XmlTextWriter xw = new XmlTextWriter(sw);
xw.WriteStartElement("SXPDictionaryItemsGet");
xw.WriteAttributeString("Revision", "7.5.0");
xw.WriteStartElement("DictionaryTypes");
xw.WriteStartElement("Item");
xw.WriteAttributeString("ID", dictionaryID);
xw.WriteEndElement();
xw.WriteEndElement();
xw.WriteEndElement();
}
sxp_getdictionaryvalues = sb.ToString();


Hans Kesting
 
Back
Top