Monday, 17 December 2012

Getting the value of XElement containing xlink and colon


Recently I faced one problem while reading the value of attribute for the XElement, I have XML in following format :


<document>
<figure xmlns:xlink="http://www.w3.org/1999/xlink" id="F1" xlink:href="image#F1.1" class="figure">
  <label>Fig. 1.</label>
  <caption> XYZ</caption>
</figure>
</document>


I have written following code to get the value of the href attribute of figure.


XDocument _xDocument = XDocument.Load(XXXXX);
// XXXXX - specify the path here

List<XElement> imageElements = _xDocument.Descendants("Figure").ToList(); 

foreach (XElement imageElement in imageElements)
{
    if (imageElement.Attribute("xlink:" + "href") != null)
     {
        string href = imageElement.Attribute("xlink:" + "href").Value;
     }
}


But I end up with the following exception :

The ':' character, hexadecimal value 0x3A, cannot be included in a name.


   at System.Xml.ValidateNames.ThrowInvalidName(String s, Int32 offsetStartChar, Int32 offsetBadChar)
   at System.Xml.ValidateNames.ParseNCNameInternal(String s, Boolean throwOnError)
   at System.Xml.XmlConvert.VerifyNCName(String name)
   at System.Xml.Linq.XName..ctor(XNamespace ns, String localName)
   at System.Xml.Linq.XNamespace.GetName(String localName, Int32 index, Int32 count)
   at System.Xml.Linq.XNamespace.GetName(String localName)
   at System.Xml.Linq.XName.Get(String expandedName)
   at System.Xml.Linq.XName.op_Implicit(String expandedName)

The solution for this is to use XNamespace as below:


XNamespace xlink = "http://www.w3.org/1999/xlink";

if (imageElement.Attribute(xlink  + "href") != null)
{
  string href = imageElement.Attribute(xlink + "href").Value;
}



Issue resolved yipee :)


Tuesday, 11 December 2012

Improve the SharePoint web application performance


Following are few quick tips for improving your SharePoint/ASP.Net web application performance :

1. Use minified or compressed version of the JavaScript files

While referring any third party JavaScript files, try to use their release version for example if we are planning to use the jQuery in your application you should refer minified and Gzipped version (32KB)

<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script>

instead of development version (252 KB)

<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.js"></script>

You can also minify and compress your js files using Visual studio extension available at

http://visualstudiogallery.msdn.microsoft.com/5469b7e2-90d7-4f54-b299-ae47e26323e6

You can install it in visual studio and at the time of development it self it get compressed. So you can refer the compressed version on your pages.

2. Using Script manager to composite the JavaScript files 

If you are using ASP.NET AJAX in your application, you can create a composite script automatically by using the ScriptManager control. To combine scripts, add the CompositeScript element and list the script references in the order that you want them included in the composite script. 


   <asp:ScriptManager ID="ScriptManager1" runat="server">
    <CompositeScript>
     <Scripts>
      <asp:ScriptReference Path="~/Scripts/Script1.js" />
      <asp:ScriptReference Path="~/Scripts/Script2.js" />
      <asp:ScriptReference Path="~/Scripts/Script3.js" />
     </Scripts>
     </CompositeScript>
  </asp:ScriptManager>



You can find more details about it at -
http://msdn.microsoft.com/en-us/library/cc488552%28v=vs.90%29.aspx



 


Migration issues for SAP.Connector.dll from Win 2003 to Win 2019 server

Recently I got task of migration of asmx web services from windows 2003 to windows 2019 server. These web services fetch data from SAP us...