Jump to content
Tuts 4 You

Read a xml without start format <?xml version="1.0" encoding="utf-8"?> in C# ???


CodeExplorer

Recommended Posts

Posted

Read a xml without start format <?xml version="1.0" encoding="utf-8"?> in C#
how to do it?

.csproj file format old:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProductVersion>9.0.21022</ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{B18A33EF-0831-44A1-84A9-DD1D16301856}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>SolutionConverterLib</RootNamespace>
    <AssemblyName>SolutionConverterLib</AssemblyName>
    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>

.csproj file format changed:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
  </PropertyGroup>
 
  <ItemGroup>
    <PackageReference Include="Microsoft.Diagnostics.Runtime" Version="2.2.343001" />
  </ItemGroup>

 

Posted (edited)

Silly me! the xml is readed.
I just have to read from childs not root:
        foreach (XElement element in this.project.Root.Elements())
            {
                if (element.Name=="PropertyGroup")
                {
                int found = 1;
                }
            }
 

Edited by CodeExplorer
  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...