Click here to Skip to main content
15,850,753 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I tried to read the data from a XML file. And it's working fine with one project. But the same code is not working with other project which could not figure it out... for the difference.

With one project, I am able to read the content properly with:
xrReader.GetAttribute(0) ' Output example : BANKNIFTY23101244200CE

With other project by using the same code, I am able to get the wrong output data....' Output example: BANKNIFTY.......44200CE
I need to know what could be the reason for not getting the proper data reading from two different projects.

What I have tried:

Using xrReader As XmlReader = XmlReader.Create(source)
Do While xrReader.Read()
If xrReader.GetAttribute(0).ToString.StartsWith("BANKNIFTY") Then
BankNiftyMappingPresentExpiryDateTextBox.Text = xrReader.GetAttribute(0)
End If
End Using

Please find out here the sample XML source file for your reference. Using thw same for both projects from same data path.
<mapping symbol="BANKNIFTY23101244200CE" name="44200CE" exchange="">
<mapping symbol="BANKNIFTY23101244200PE" name="44200PE" exchange="">
<mapping symbol="BANKNIFTY23101244300CE" name="44300CE" exchange="">
<mapping symbol="BANKNIFTY23101244300PE" name="44300PE" exchange="">
Updated 5-Nov-23 1:39am
Richard MacCutchan 29-Oct-23 10:52am    
Is this the exact text you see in the TextBox, with 7 dots?
Out put example : BANKNIFTY.......44200CE
OMG_Live 29-Oct-23 11:03am    
Sour file example :
<mapping symbol="BANKNIFTY01NOV2344200CE" name="44200CE" exchange="">
<mapping symbol="BANKNIFTY01NOV2344200PE" name="44200PE" exchange="">
<mapping symbol="BANKNIFTY01NOV2344300CE" name="44300CE" exchange="">
<mapping symbol="BANKNIFTY01NOV2344300PE" name="44300PE" exchange="">

Out put example on second project : BANKNIFTY.................44200CE
Richard MacCutchan 29-Oct-23 12:26pm    
Well that is just a repeat (but not an accurate one) of what you posted earlier, rather than actually answering my question. It also disproves your assertion to M Imran Ansari below, that the XML data is exactly the same. So we are left guessing as to what actually happens on your different systems.
Richard Deeming 30-Oct-23 6:14am    
Firstly, before Dave shouts at you :) - GetAttribute returns a string. There is absolutely no need to call .ToString on it.

Secondly, try debugging your code to check that:

a) the source is exactly the same in both applications, and points to exactly the same file; and
b) what the exact value returned from GetAttribute(0) is. Perhaps your display control in the second application is truncating the value if it's too long to display fully?
OMG_Live 30-Oct-23 11:30am    
Thanks for your reply. As per your guidance I verified.

01. The source file which is common form both the project.
02. I am getting the value from GetAttribute(0) as BANKNIFTY.................44200CE.

The same output is showing on message box and even on TextBox also.

1 solution

When dealing with XML files, it's crucial to ensure that the structure and the data of the XML file is consistent and the data you are trying to access exists in the same format across different projects. It's possible that the XML file structure or data might be slightly different in the two projects. In the second project it's eliminating the date part of XML.
In the first output the date value '231012' is coming between BANKNIFTY and 44200CE, which is eliminating in the second project.
Further, you can ensure the XML structure, attribute index and data integrity to identify the root cause of the issue and ensure that the data reading process is consistent across both projects.
Share this answer
OMG_Live 29-Oct-23 10:20am    
Thank you Mr.Imran for your reply and guidance.

Structure and the data of the XML file is same which I am using in both projects as the XML data source is same by default.

One thing I could not figure it out that, on first project Date value is coming as "BANKNIFTY23101244200CE" and why not getting Date Value on second project?. As you said, on second project Date value is getting converted into "BANKNIFTY.......44200CE".

Please guide how do I solve this issue. Is there any other way to read the Exact Value from the source value ?

Thanks in advance.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900