Java Code – Appostrophe (most likely spelled wrong)
Question:
In the code found below, Can someon tell me what the apostrophe is used for? What is its purpose?
resp = resp + “<BusinessName id=’”+BusinessId+”‘>”+BusinessName+”</BusinessName>”;
Solution:
“<BusinessName id=’”+BusinessId+”‘>”+BusinessName+”</BusinessName>”
“<BusinessName id=’1′>Sample Business Name</BusinessName>”
resp = resp — indicates concatenation with older entry present in resp
+ — concatenate
“<BusinessName id=’” — This will indicate one string
+ — concatenate
BusinessId — The business Id to be used
+ — concatenate
“‘>” — one more part of the string
+ — concatenate
BusinessName — The business name
+ — concatenate
“</BusinessName>”
So a string would be inside “”
now we have
“<BusinessName id=’” — a single quote after the equals sign/ apostrophe
“‘>” — similarly here
This is used because id is an attribute of the BusinessName and all XML attribute values must be quoted
like id=’1′ or id = “1″
if we need to add “” double quotes we need to escape it with \
“<BusinessName id=\”"+BusinessId+”\”>”+BusinessName+”</BusinessName>”
hence the above snytax.
Hope this is clear.













Comments (0)
Trackbacks - Pingbacks (0)
Leave a Reply