error while converting string xml to xml using xelement
-
Hi All I am making a string from dataset and then converting to xml.while converting its giving me error unexpected symbol "=" at location
For Each row In dsGetBVItemDetails.Tables(0).Rows
strxmlString += _
"<ItemDetails>" & _
"<Item code=" + dsGetBVItemDetails.Tables
(0).Rows(i)(0).ToString() + ">" & _
"<Description>" +
dsGetBVItemDetails.Tables(0).Rows(i)(1).ToString() + "</Description>" & _
"</Item>" & _
"<ItemQty>" + dsGetBVItemDetails.Tables
(0).Rows(i)(2).ToString() + "</ItemQty>" & _
"<Message>" + dsGetBVItemDetails.Tables
(0).Rows(i)(3).ToString() + "</Message>" & _
"</ItemDetails>"
i = i + 1
NextIt is giving error while converting only when adding attribute "code" in element Item pls suggest and then converting like this
XFinalXML = XElement.Parse(strxmlString.ToString())
xmlResponse = XElement.Parse(XFinalXML.ToString()) xmlResponseDoc = New XDocument(xmlResponse) schemaResponse.Add(Constants.TARGETNAMESPACE, AppDomain
.CurrentDomain.BaseDirectory & "Schema\" & Constants.GetBVItemsResponse)
nsResponse = xmlResponseDoc.Root.Name.NamespaceNameAnkit Aneja "Nothing is impossible. The word itself says - I M possible"
-
Hi All I am making a string from dataset and then converting to xml.while converting its giving me error unexpected symbol "=" at location
For Each row In dsGetBVItemDetails.Tables(0).Rows
strxmlString += _
"<ItemDetails>" & _
"<Item code=" + dsGetBVItemDetails.Tables
(0).Rows(i)(0).ToString() + ">" & _
"<Description>" +
dsGetBVItemDetails.Tables(0).Rows(i)(1).ToString() + "</Description>" & _
"</Item>" & _
"<ItemQty>" + dsGetBVItemDetails.Tables
(0).Rows(i)(2).ToString() + "</ItemQty>" & _
"<Message>" + dsGetBVItemDetails.Tables
(0).Rows(i)(3).ToString() + "</Message>" & _
"</ItemDetails>"
i = i + 1
NextIt is giving error while converting only when adding attribute "code" in element Item pls suggest and then converting like this
XFinalXML = XElement.Parse(strxmlString.ToString())
xmlResponse = XElement.Parse(XFinalXML.ToString()) xmlResponseDoc = New XDocument(xmlResponse) schemaResponse.Add(Constants.TARGETNAMESPACE, AppDomain
.CurrentDomain.BaseDirectory & "Schema\" & Constants.GetBVItemsResponse)
nsResponse = xmlResponseDoc.Root.Name.NamespaceNameAnkit Aneja "Nothing is impossible. The word itself says - I M possible"
-
Are you adding double quote characters around the attribute value that follows
"<Item code="
? You can check this by looking at the generated string in your debugger.The best things in life are not things.
yes below is my code For Each row In dsGetBVItemDetails.Tables(0).Rows strxmlString += _ "<ItemDetails>" & _ "<Item code=" + dsGetBVItemDetails.Tables (0).Rows(i)(0).ToString() + ">" & _ "<Description>" + dsGetBVItemDetails.Tables(0).Rows(i)(1).ToString() + "</Description>" & _ "</Item>" & _ "<ItemQty>" + dsGetBVItemDetails.Tables (0).Rows(i)(2).ToString() + "</ItemQty>" & _ "<Message>" + dsGetBVItemDetails.Tables (0).Rows(i)(3).ToString() + "</Message>" & _ "</ItemDetails>" i = i + 1 Next
Ankit Aneja "Nothing is impossible. The word itself says - I M possible"
-
Hi All I am making a string from dataset and then converting to xml.while converting its giving me error unexpected symbol "=" at location
For Each row In dsGetBVItemDetails.Tables(0).Rows
strxmlString += _
"<ItemDetails>" & _
"<Item code=" + dsGetBVItemDetails.Tables
(0).Rows(i)(0).ToString() + ">" & _
"<Description>" +
dsGetBVItemDetails.Tables(0).Rows(i)(1).ToString() + "</Description>" & _
"</Item>" & _
"<ItemQty>" + dsGetBVItemDetails.Tables
(0).Rows(i)(2).ToString() + "</ItemQty>" & _
"<Message>" + dsGetBVItemDetails.Tables
(0).Rows(i)(3).ToString() + "</Message>" & _
"</ItemDetails>"
i = i + 1
NextIt is giving error while converting only when adding attribute "code" in element Item pls suggest and then converting like this
XFinalXML = XElement.Parse(strxmlString.ToString())
xmlResponse = XElement.Parse(XFinalXML.ToString()) xmlResponseDoc = New XDocument(xmlResponse) schemaResponse.Add(Constants.TARGETNAMESPACE, AppDomain
.CurrentDomain.BaseDirectory & "Schema\" & Constants.GetBVItemsResponse)
nsResponse = xmlResponseDoc.Root.Name.NamespaceNameAnkit Aneja "Nothing is impossible. The word itself says - I M possible"
You're missing quotes around the value for
code
. Concatentating string together to build an XML document is doing it the hard way and it's less forgiving of typos and invalid characters in the contents. You might want to look into building it this way:Dim xml As New XDocument xml.Declaration = New XDeclaration("1.0", "utf-8", "yes") Dim rootNode As New XElement("RootNode") For index = 1 To 3 rootNode.Add(<ItemDetails> <Item code=<%= index %>> <Description>Some description text <%= index %></Description> </Item> <ItemQty><%= index %></ItemQty> <Message>Item Message <%= index %></Message> </ItemDetails>) Next xml.Add(rootNode) Debug.WriteLine(xml.ToString)
Notice that any values are automatically put into quotes when needed. Plus, you get full Intellisense support and syntax checking in Visual Studio 2010.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
yes below is my code For Each row In dsGetBVItemDetails.Tables(0).Rows strxmlString += _ "<ItemDetails>" & _ "<Item code=" + dsGetBVItemDetails.Tables (0).Rows(i)(0).ToString() + ">" & _ "<Description>" + dsGetBVItemDetails.Tables(0).Rows(i)(1).ToString() + "</Description>" & _ "</Item>" & _ "<ItemQty>" + dsGetBVItemDetails.Tables (0).Rows(i)(2).ToString() + "</ItemQty>" & _ "<Message>" + dsGetBVItemDetails.Tables (0).Rows(i)(3).ToString() + "</Message>" & _ "</ItemDetails>" i = i + 1 Next
Ankit Aneja "Nothing is impossible. The word itself says - I M possible"
No, you're not. The resulting string code should be closer to:
" & \_
But, you shouldn't even be doing it this way. You're code is nearly impossible to read and makes it very difficult yo see what's going on. Look at my other reply.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
yes below is my code For Each row In dsGetBVItemDetails.Tables(0).Rows strxmlString += _ "<ItemDetails>" & _ "<Item code=" + dsGetBVItemDetails.Tables (0).Rows(i)(0).ToString() + ">" & _ "<Description>" + dsGetBVItemDetails.Tables(0).Rows(i)(1).ToString() + "</Description>" & _ "</Item>" & _ "<ItemQty>" + dsGetBVItemDetails.Tables (0).Rows(i)(2).ToString() + "</ItemQty>" & _ "<Message>" + dsGetBVItemDetails.Tables (0).Rows(i)(3).ToString() + "</Message>" & _ "</ItemDetails>" i = i + 1 Next
Ankit Aneja "Nothing is impossible. The word itself says - I M possible"
To add to Dave's comments, you have ignored my suggestion and merely reposted the original code, minus the <pre> tags, so it's almost impossible to read. And it obviously does not include the double quotes; had you used your debugger you would have spotted that fairly quickly.
The best things in life are not things.