Skip to content

Commit dca4955

Browse files
committed
LinqToXml C sharp
0 parents  commit dca4955

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+105050
-0
lines changed

Xml_Processing/Xml_Processing.sln

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 2013
4+
VisualStudioVersion = 12.0.21005.1
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xml_Processing", "Xml_Processing\Xml_Processing.csproj", "{FC35CCF7-CFD5-4D7A-9528-9F9780A957EB}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{FC35CCF7-CFD5-4D7A-9528-9F9780A957EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{FC35CCF7-CFD5-4D7A-9528-9F9780A957EB}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{FC35CCF7-CFD5-4D7A-9528-9F9780A957EB}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{FC35CCF7-CFD5-4D7A-9528-9F9780A957EB}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal

Xml_Processing/Xml_Processing.v12.suo

17 KB
Binary file not shown.
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<configSections>
4+
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
5+
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
6+
</configSections>
7+
<startup>
8+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
9+
</startup>
10+
<entityFramework>
11+
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
12+
<parameters>
13+
<parameter value="mssqllocaldb" />
14+
</parameters>
15+
</defaultConnectionFactory>
16+
<providers>
17+
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
18+
</providers>
19+
</entityFramework>
20+
</configuration>
+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Xml.Linq;
7+
8+
namespace Xml_Processing
9+
{
10+
class Program
11+
{
12+
static void Main(string[] args)
13+
{
14+
Console.WriteLine("/*********************************--Using XElement--**********************************************/");
15+
/*********************************--Using XElement--**********************************************/
16+
XElement xelement = XElement.Load(@"C:\Users\Umar\Desktop\sample.xml");
17+
//Manipulate Directly
18+
foreach (XElement doc in xelement.Elements())
19+
{
20+
Console.WriteLine(doc);
21+
}
22+
//FirstltChangeObjectIntoIEnumerable&& then manipulate
23+
24+
IEnumerable<XElement> employess = xelement.Elements();
25+
foreach (var item in employess)
26+
{
27+
Console.WriteLine(item);
28+
}
29+
Console.WriteLine("/*********************************--Using XDocument--**********************************************/");
30+
/*********************************--Using XDocument--**********************************************/
31+
XDocument xdocument = XDocument.Load(@"C:\Users\Umar\Desktop\sample.xml");
32+
IEnumerable<XElement> demployess = xdocument.Elements();
33+
foreach (var ditem in demployess)
34+
{
35+
Console.WriteLine(ditem);
36+
}
37+
//_________________________________________________________________________________________________________//
38+
//2. How Do I Access a Single Element using LINQ to XML
39+
Console.WriteLine("2. How Do I Access a Single Element using LINQ to XML");
40+
XElement xEle = XElement.Load(@"C:\Users\Umar\Desktop\sample.xml");
41+
IEnumerable<XElement> docs = xEle.Elements();
42+
foreach (var iuy in docs)
43+
{
44+
Console.WriteLine(iuy.Element("Name").Value);
45+
}
46+
//_________________________________________________________________________________________________________//
47+
//3. How Do I Access Multiple Elements using LINQ to XML
48+
Console.WriteLine("3. How Do I Access Multiple Elements using LINQ to XML");
49+
XElement fiu = XElement.Load(@"C:\Users\Umar\Desktop\sample.xml");
50+
IEnumerable<XElement> fiuy = fiu.Elements();
51+
foreach(var oiu in fiuy)
52+
{
53+
Console.WriteLine("{0} has Employee Id {1}", oiu.Element("Name").Value, oiu.Element("EmpId").Value);
54+
}
55+
//_________________________________________________________________________________________________________//
56+
//4. How Do I Access all Elements having a Specific Attribute using LINQ to XML
57+
Console.WriteLine("4. How Do I Access all Elements having a Specific Attribute using LINQ to XML");
58+
XElement ciu = XElement.Load(@"C:\Users\Umar\Desktop\sample.xml");
59+
IEnumerable<XElement> hjj = ciu.Elements();
60+
var query = from m in hjj
61+
where (string)m.Element("Sex") == "Female"
62+
select m;
63+
//_________________________________________________________________________________________________________//
64+
//5. How Do I access Specific Element having a Specific Attribute using LINQ to XML
65+
Console.WriteLine("5. How Do I access Specific Element having a Specific Attribute using LINQ to XML");
66+
XElement drf = XElement.Load(@"C:\Users\Umar\Desktop\sample.xml");
67+
IEnumerable<XElement> ftr = drf.Elements();
68+
foreach (var uiui in ftr)
69+
{
70+
Console.WriteLine("{0} has Employee Id {1} and its Attribute is {2}", uiui.Element("Name").Value, uiui.Element("EmpId").Value,uiui.Element("Phone").Attribute("Type").Value);
71+
}
72+
//_________________________________________________________________________________________________________//
73+
//How Do I Find Nested Elements (using Descendants Axis) using LINQ to XML
74+
Console.WriteLine("How Do I Find Nested Elements (using Descendants Axis) using LINQ to XML");
75+
Console.WriteLine("5. How Do I access Specific Element having a Specific Attribute using LINQ to XML");
76+
XElement sdf = XElement.Load(@"C:\Users\Umar\Desktop\sample.xml");
77+
IEnumerable<XElement> ftfsdr = drf.Elements();
78+
foreach (XElement dasd in xelement.Descendants("Zip"))
79+
{
80+
Console.WriteLine((string)dasd);
81+
}
82+
83+
Console.ReadKey();
84+
85+
}
86+
}
87+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("Xml_Processing")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("Xml_Processing")]
13+
[assembly: AssemblyCopyright("Copyright © 2018")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("eb789577-66d1-49cb-992b-b7245e55f56c")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{FC35CCF7-CFD5-4D7A-9528-9F9780A957EB}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>Xml_Processing</RootNamespace>
11+
<AssemblyName>Xml_Processing</AssemblyName>
12+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<PlatformTarget>AnyCPU</PlatformTarget>
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<PlatformTarget>AnyCPU</PlatformTarget>
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<Reference Include="System" />
36+
<Reference Include="System.Core" />
37+
<Reference Include="System.Xml.Linq" />
38+
<Reference Include="System.Data.DataSetExtensions" />
39+
<Reference Include="Microsoft.CSharp" />
40+
<Reference Include="System.Data" />
41+
<Reference Include="System.Xml" />
42+
</ItemGroup>
43+
<ItemGroup>
44+
<Compile Include="Program.cs" />
45+
<Compile Include="Properties\AssemblyInfo.cs" />
46+
</ItemGroup>
47+
<ItemGroup>
48+
<None Include="App.config" />
49+
</ItemGroup>
50+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
51+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
52+
Other similar extension points exist, see Microsoft.Common.targets.
53+
<Target Name="BeforeBuild">
54+
</Target>
55+
<Target Name="AfterBuild">
56+
</Target>
57+
-->
58+
</Project>
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
5+
</startup>
6+
</configuration>
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
5+
</startup>
6+
</configuration>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
3+
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
4+
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
5+
<security>
6+
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
7+
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
8+
</requestedPrivileges>
9+
</security>
10+
</trustInfo>
11+
</assembly>

Xml_Processing/Xml_Processing/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs

Whitespace-only changes.

Xml_Processing/Xml_Processing/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs

Whitespace-only changes.

Xml_Processing/Xml_Processing/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
C:\Users\Umar\Downloads\Xml_Processing\Xml_Processing\Xml_Processing\bin\Debug\Xml_Processing.exe.config
2+
C:\Users\Umar\Downloads\Xml_Processing\Xml_Processing\Xml_Processing\bin\Debug\Xml_Processing.exe
3+
C:\Users\Umar\Downloads\Xml_Processing\Xml_Processing\Xml_Processing\bin\Debug\Xml_Processing.pdb
4+
C:\Users\Umar\Downloads\Xml_Processing\Xml_Processing\Xml_Processing\obj\Debug\Xml_Processing.csprojResolveAssemblyReference.cache
5+
C:\Users\Umar\Downloads\Xml_Processing\Xml_Processing\Xml_Processing\obj\Debug\Xml_Processing.exe
6+
C:\Users\Umar\Downloads\Xml_Processing\Xml_Processing\Xml_Processing\obj\Debug\Xml_Processing.pdb
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="EntityFramework" version="6.2.0" targetFramework="net45" />
4+
</packages>
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<configuration>
2+
<configSections>
3+
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
4+
</configSections>
5+
</configuration>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<configuration>
2+
<configSections>
3+
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
4+
</configSections>
5+
</configuration>

0 commit comments

Comments
 (0)