Skip to main content

ET.fromstring gives ParseError

I am trying to parse an xml string and I want just the PackageReference Include attribute details and the Version of it. When I say ET.fromstring(xml) it gives error like xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 284, column 84. I verified if the xml is valid on multiple websites and there seems to be no issues with my xml and it is well formed. Please see my Edit below.

xml parse error

    import xml.etree.ElementTree as ET
    
    thisDict={}
    
    def parseXMLInCsProj(xml):
      tree = ET.fromstring(xml)
      for packageReference in tree.findall('.//PackageReference'):
         if packageReference is None:
            continue
         if 'Include' in packageReference:
            key=packageReference.get('Include')
         child_item=packageReference.find('.//Version').text
         thisDict[key]=child_item
    
    
    xmlstr=f'''<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Castle.Core" version="5.1.1" targetFramework="net481" />
  <package id="Moq" version="4.18.4" targetFramework="net481" />
  <package id="System.Runtime.CompilerServices.Unsafe" version="4.5.3" targetFramework="net481" />
  <package id="xunit.runner.visualstudio" version="2.4.5" targetFramework="net481" developmentDependency="true" />
</packages>'''

xmlstr1=f'''<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProductVersion>8.0.30703</ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>fdgfdgfg</ProjectGuid>
    <OutputType>Exe</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>Labcyte.Echo.Server</RootNamespace>
    <AssemblyName>EchoServer</AssemblyName>
    <TargetFrameworkVersion>v4.8.1</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <PublishUrl>publish\</PublishUrl>
    <Install>true</Install>
    <InstallFrom>Disk</InstallFrom>
    <UpdateEnabled>false</UpdateEnabled>
    <UpdateMode>Foreground</UpdateMode>
    <UpdateInterval>7</UpdateInterval>
    <UpdateIntervalUnits>Days</UpdateIntervalUnits>
    <UpdatePeriodically>false</UpdatePeriodically>
    <UpdateRequired>false</UpdateRequired>
    <MapFileExtensions>true</MapFileExtensions>
    <ApplicationRevision>0</ApplicationRevision>
    <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
    <IsWebBootstrapper>false</IsWebBootstrapper>
    <UseApplicationTrust>false</UseApplicationTrust>
    <BootstrapperEnabled>true</BootstrapperEnabled>
    <TargetFrameworkProfile />
    <SccProjectName>
    </SccProjectName>
    <SccLocalPath>
    </SccLocalPath>
    <SccAuxPath>
    </SccAuxPath>
    <SccProvider>
    </SccProvider>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>TRACE;DEBUG</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <Prefer32Bit>false</Prefer32Bit>
    <PlatformTarget>x64</PlatformTarget>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>none</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <Prefer32Bit>false</Prefer32Bit>
    <PlatformTarget>x64</PlatformTarget>
  </PropertyGroup>
  <PropertyGroup>
    <StartupObject>
    </StartupObject>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
    <DebugSymbols>true</DebugSymbols>
    <OutputPath>bin\\x86\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <DebugType>full</DebugType>
    <PlatformTarget>x86</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
    <Prefer32Bit>false</Prefer32Bit>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
    <OutputPath>bin\\x86\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <Optimize>true</Optimize>
    <DebugType>pdbonly</DebugType>
    <PlatformTarget>x86</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
  </PropertyGroup>
  <PropertyGroup>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
    <DebugSymbols>true</DebugSymbols>
    <OutputPath>bin\\x64\Debug\</OutputPath>
    <DefineConstants>TRACE;DEBUG</DefineConstants>
    <DebugType>full</DebugType>
    <PlatformTarget>x64</PlatformTarget>
    <LangVersion>7.3</LangVersion>
    <ErrorReport>prompt</ErrorReport>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
    <OutputPath>bin\\x64\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <Optimize>true</Optimize>
    <PlatformTarget>x64</PlatformTarget>
    <LangVersion>7.3</LangVersion>
    <ErrorReport>prompt</ErrorReport>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="InstallerUtil">
      <HintPath>..\..\..\Library\EchoNET\EchoNETServer\InstallerUtil.dll</HintPath>
    </Reference>
    <Reference Include="Labcyte.Core.CommonInterface">
      <HintPath>..\..\..\Library\Core\CoreClient\Labcyte.Core.CommonInterface.dll</HintPath>
    </Reference>
    <Reference Include="Labcyte.Core.EventServer">
      <HintPath>..\..\..\Library\Core\CoreClient\Labcyte.Core.EventServer.dll</HintPath>
    </Reference>
    <Reference Include="Labcyte.Core.Interface">
      <HintPath>..\..\..\Library\Core\CoreClient\Labcyte.Core.Interface.dll</HintPath>
    </Reference>
    <Reference Include="Labcyte.EchoNET.Common, Version=0.0.1.0, Culture=neutral, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>..\..\..\Library\EchoNET\EchoNETServer\Labcyte.EchoNET.Common.dll</HintPath>
    </Reference>
    <Reference Include="Labcyte.EchoNET.Data, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>..\..\..\Library\EchoNET\EchoNETServer\Labcyte.EchoNET.Data.dll</HintPath>
    </Reference>
    <Reference Include="Labcyte.EchoNET.EchoNETScripts, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>..\..\..\Library\EchoNET\EchoNETServer\Labcyte.EchoNET.EchoNETScripts.dll</HintPath>
    </Reference>
    <Reference Include="Labcyte.EchoNET.HostServices">
      <HintPath>..\..\..\Library\EchoNET\EchoNETServer\Labcyte.EchoNET.HostServices.dll</HintPath>
    </Reference>
    <Reference Include="Labcyte.EchoNET.Instrument, Version=0.0.1.0, Culture=neutral, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>..\..\..\Library\EchoNET\EchoNETServer\Labcyte.EchoNET.Instrument.dll</HintPath>
    </Reference>
    <Reference Include="Labcyte.EchoNET.Interface, Version=0.0.1.0, Culture=neutral, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>..\..\..\Library\EchoNET\EchoNETServer\Labcyte.EchoNET.Interface.dll</HintPath>
    </Reference>
    <Reference Include="Labcyte.EchoNET.ServiceEndpoints, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>..\..\..\Library\EchoNET\EchoNETServer\Labcyte.EchoNET.ServiceEndpoints.dll</HintPath>
    </Reference>
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System" />
    <Reference Include="System.ComponentModel.Composition" />
    <Reference Include="System.Configuration" />
    <Reference Include="System.Configuration.Install" />
    <Reference Include="System.IdentityModel" />
    <Reference Include="System.Runtime.Serialization" />
    <Reference Include="System.ServiceModel" />
    <Reference Include="System.ServiceProcess" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Config.cs" />
    <Compile Include="EchoCallBack_HostService.cs" />
    <Compile Include="Echo_HostService.cs" />
    <Compile Include="Host.cs">
      <SubType>Component</SubType>
    </Compile>
    <Compile Include="Program.cs" />
    <Compile Include="ProjectInstaller.cs">
      <SubType>Component</SubType>
    </Compile>
    <Compile Include="ProjectInstaller.designer.cs">
      <DependentUpon>ProjectInstaller.cs</DependentUpon>
    </Compile>
    <Compile Include="Properties\AssemblyInfo.cs" />
    <Compile Include="Properties\Settings.Designer.cs">
      <AutoGen>True</AutoGen>
      <DesignTimeSharedInput>True</DesignTimeSharedInput>
      <DependentUpon>Settings.settings</DependentUpon>
    </Compile>
  </ItemGroup>
  <ItemGroup>
    <None Include="app.config">
      <SubType>Designer</SubType>
    </None>
    <None Include="Properties\Settings.settings">
      <Generator>SettingsSingleFileGenerator</Generator>
      <LastGenOutput>Settings.Designer.cs</LastGenOutput>
    </None>
  </ItemGroup>
  <ItemGroup>
    <BootstrapperPackage Include=".NETFramework,Version=v4.0">
      <Visible>False</Visible>
      <ProductName>Microsoft .NET Framework 4 %28x86 and x64%29</ProductName>
      <Install>true</Install>
    </BootstrapperPackage>
    <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
      <Visible>False</Visible>
      <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
      <Install>false</Install>
    </BootstrapperPackage>
    <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
      <Visible>False</Visible>
      <ProductName>.NET Framework 3.5 SP1</ProductName>
      <Install>false</Install>
    </BootstrapperPackage>
    <BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
      <Visible>False</Visible>
      <ProductName>Windows Installer 3.1</ProductName>
      <Install>true</Install>
    </BootstrapperPackage>
  </ItemGroup>
  <ItemGroup>
    <WCFMetadata Include="Service References\" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\..\..\Pico\Medman\AppsWrapper\AppsWrapper.vcxproj">
      <Project>hghjgj</Project>
      <Name>AppsWrapper</Name>
    </ProjectReference>
    <ProjectReference Include="..\..\..\Pico\Medman\FluidTransferInterface\FluidTransferInterface.csproj">
      <Project>434554</Project>
      <Name>FluidTransferInterface</Name>
    </ProjectReference>
    <ProjectReference Include="..\..\..\Pico\Medman\HarrierFluidTransfer\HarrierFluidTransfer.csproj">
      <Project>7686877</Project>
      <Name>HarrierFluidTransfer</Name>
    </ProjectReference>
    <ProjectReference Include="..\..\EchoServerAPI\EchoServerAPI.csproj">
      <Project>89798798879</Project>
      <Name>EchoServerAPI</Name>
    </ProjectReference>
    <ProjectReference Include="..\..\Labcyte.Echo.EchoScripts\Labcyte.Echo.EchoScripts.csproj">
      <Project>7687687878787</Project>
      <Name>Labcyte.Echo.EchoScripts</Name>
    </ProjectReference>
    <ProjectReference Include="..\EchoServerAPI.Server\EchoServerAPI.Server.csproj">
      <Project>76567687887</Project>
      <Name>EchoServerAPI.Server</Name>
    </ProjectReference>
    <ProjectReference Include="..\Labcyte.Echo.Commands\Labcyte.Echo.Commands.csproj">
      <Project>878989808899</Project>
      <Name>Labcyte.Echo.Commands</Name>
    </ProjectReference>
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.ML">
      <Version>2.0.1</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.ML.CpuMath">
      <Version>2.0.1</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.ML.DataView">
      <Version>2.0.1</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.ML.OnnxRuntime">
      <Version>1.14.1</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.ML.OnnxTransformer">
      <Version>2.0.1</Version>
    </PackageReference>
    <PackageReference Include="Mono.pdb2mdb">
      <Version>0.1.0.20130128</Version>
    </PackageReference>
    <PackageReference Include="System.Runtime.InteropServices.RuntimeInformation">
      <Version>4.3.0</Version>
    </PackageReference>
  </ItemGroup>
  <ItemGroup>
    <EmbeddedResource Include="ProjectInstaller.resx">
      <DependentUpon>ProjectInstaller.cs</DependentUpon>
    </EmbeddedResource>
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <PropertyGroup>
    <PreBuildEvent>rmdir /S /Q "$(TargetDir)ScriptClasses"
mkdir "$(TargetDir)ScriptClasses"
rmdir /S /Q "$(SolutionDir)..\Library\Echo\EchoServer"
mkdir "$(SolutionDir)..\Library\Echo\EchoServer"
mkdir "$(SolutionDir)..\Library\Echo\EchoServer\ScriptClasses"

</PreBuildEvent>
  </PropertyGroup>
  <PropertyGroup>
    <PostBuildEvent>copy "$(TargetDir)*.dll"  "$(SolutionDir)..\Library\Echo\EchoServer"\"
copy "$(TargetDir)*.pdb"  "$(SolutionDir)..\Library\Echo\EchoServer"\"
copy  "$(SolutionDir)..\Library\EchoNET\EchoNETServer\ScriptClasses\*.cs" "$(TargetDir)ScriptClasses\"
copy  "$(TargetDir)ScriptClasses\" "$(SolutionDir)..\Library\Echo\EchoServer"\ScriptClasses\"
copy  "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\\v4.8.1\Facades\System.Linq.*"  "$(TargetDir)"
copy  "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\\v4.8.1\System.Core.dll"  "$(TargetDir)"
copy  "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\\v4.8.1\Facades\\netstandard.dll"  "$(TargetDir)"
</PostBuildEvent>
  </PropertyGroup>
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->
</Project>'''
    
    parseXMLInCsProj(xmlstr1)

EDIT: As suggested I updated my xml string. Now I don't see the error. But as soon as the debugger comes to the line for packageReference in tree.findall('.//PackageReference'):, the program terminates. Please help.



source https://stackoverflow.com/questions/77018449/et-fromstring-gives-parseerror

Comments

Popular posts from this blog

ValueError: X has 10 features, but LinearRegression is expecting 1 features as input

So, I am trying to predict the model but its throwing error like it has 10 features but it expacts only 1. So I am confused can anyone help me with it? more importantly its not working for me when my friend runs it. It works perfectly fine dose anyone know the reason about it? cv = KFold(n_splits = 10) all_loss = [] for i in range(9): # 1st for loop over polynomial orders poly_order = i X_train = make_polynomial(x, poly_order) loss_at_order = [] # initiate a set to collect loss for CV for train_index, test_index in cv.split(X_train): print('TRAIN:', train_index, 'TEST:', test_index) X_train_cv, X_test_cv = X_train[train_index], X_test[test_index] t_train_cv, t_test_cv = t[train_index], t[test_index] reg.fit(X_train_cv, t_train_cv) loss_at_order.append(np.mean((t_test_cv - reg.predict(X_test_cv))**2)) # collect loss at fold all_loss.append(np.mean(loss_at_order)) # collect loss at order plt.plot(np.log(al...

Sorting large arrays of big numeric stings

I was solving bigSorting() problem from hackerrank: Consider an array of numeric strings where each string is a positive number with anywhere from to digits. Sort the array's elements in non-decreasing, or ascending order of their integer values and return the sorted array. I know it works as follows: def bigSorting(unsorted): return sorted(unsorted, key=int) But I didnt guess this approach earlier. Initially I tried below: def bigSorting(unsorted): int_unsorted = [int(i) for i in unsorted] int_sorted = sorted(int_unsorted) return [str(i) for i in int_sorted] However, for some of the test cases, it was showing time limit exceeded. Why is it so? PS: I dont know exactly what those test cases were as hacker rank does not reveal all test cases. source https://stackoverflow.com/questions/73007397/sorting-large-arrays-of-big-numeric-stings

How to load Javascript with imported modules?

I am trying to import modules from tensorflowjs, and below is my code. test.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title </head> <body> <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@2.0.0/dist/tf.min.js"></script> <script type="module" src="./test.js"></script> </body> </html> test.js import * as tf from "./node_modules/@tensorflow/tfjs"; import {loadGraphModel} from "./node_modules/@tensorflow/tfjs-converter"; const MODEL_URL = './model.json'; const model = await loadGraphModel(MODEL_URL); const cat = document.getElementById('cat'); model.execute(tf.browser.fromPixels(cat)); Besides, I run the server using python -m http.server in my command prompt(Windows 10), and this is the error prompt in the console log of my browser: Failed to loa...