A Place to Learn Ur-self…






Example1:

  1. String rawXml =
  2.           @"<root>
  3.                 <person firstname=""Riley"" lastname=""Scott"" />
  4.                 <person firstname=""Thomas"" lastname=""Scott"" />
  5.             </root>";
  6.             XmlDocument xmlDoc = new XmlDocument();
  7.             xmlDoc.LoadXml(rawXml);

Example2:

  1. String rawXml =
  2.           @"<root>
  3.                 <person firstname=""Riley"" lastname=""Scott"" />
  4.                 <person firstname=""Thomas"" lastname=""Scott"" />
  5.             </root>";
  6.             XElement xmlDoc = XElement.Parse(rawXml);

Example3:

  1. String rawXml =
  2.           @"<root>
  3.                 <person firstname=""Riley"" lastname=""Scott"" />
  4.                 <person firstname=""Thomas"" lastname=""Scott"" />
  5.             </root>";
  6.             XDocument xd = XDocument.Parse(rawXml);


Sample XML:

  1. <Employees>
  2.   <Employee Id="1" EmpName="Chikkanti" Sal="2000"/>
  3.   <Employee Id="2" EmpName="Karthik" Sal="2500"/>
  4.   <Employee Id="3" EmpName="Kishore" Sal="3000"/>
  5.   <Employee Id="4" EmpName="Raju" Sal="3500"/>
  6. </Employees>

(Method 1)Sample Code to delete XML Node Using linq C#:

  1. using System;
  2. using System.Linq;
  3. using System.Xml.Linq;
  4. using System.Xml.XPath;
  5.  
  6. namespace ConsoleApplication1
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             //Loading XML file
  13.             XElement xdoc = XElement.Load("D:/Employees.xml");
  14.             //Selecting XML Node to delete
  15.             var x = (from elemet in xdoc.Elements("Employee")
  16.                      where elemet.Attribute("Id").Value == "1"
  17.                      select elemet);
  18.             Console.Write(xdoc);
  19.             //Removing XML Node
  20.             x.Remove();
  21.             Console.Write(xdoc);
  22.         }
  23.     }
  24. }

(Method 2)Sample Code to delete XML Node Using linq C#:

 

  1. using System;
  2. using System.Linq;
  3. using System.Xml.Linq;
  4. using System.Xml.XPath;
  5.  
  6. namespace ConsoleApplication1
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             //Loading XML file
  13.             XElement xdoc = XElement.Load("D:/Employees.xml");
  14.             Console.Write(xdoc);
  15.             //Removing XML Node
  16.             xdoc.XPathSelectElement("Employee[@Id = '1']").Remove();//Add System.Xml.XPath for XPathSelectElement
  17.             Console.Write(xdoc);
  18.         }
  19.     }
  20. }


We have may plug-ins to read Query string values in JavaScript. But we don’t know what is happening inside plug-in.

let’s learn how to read Query String values with plain JavaScript.

Example URL:

Script to read Query String Value.

<script type="text/javascript">
    function getParameterByName(name) {
        name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
        var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
            results = regex.exec(location.search);
        return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
    }
</script>

Method Call:

  1. var postNo = getParameterByName("PostNo");//OutPut:100