XML 문서를 구문 분석하려고합니다. 해당 문서는 AppxManifest 파일입니다.내 노드를 검색하기 위해 XmlDocument.SelectNodes를 가져올 수 없습니다?
예 문서는 다음과 같습니다
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/2010/manifest" xmlns:build="http://schemas.microsoft.com/developer/appx/2012/build" IgnorableNamespaces="build">
<Identity Name="uytury" Publisher="hygj" Version="1.0.0.12" ProcessorArchitecture="neutral" />
<Properties>
<DisplayName>jhjj</DisplayName>
<PublisherDisplayName>bhhjb</PublisherDisplayName>
<Logo>Assets\StoreLogo.png</Logo>
</Properties>
<Prerequisites>
<OSMinVersion>6.2.1</OSMinVersion>
<OSMaxVersionTested>6.2.1</OSMaxVersionTested>
</Prerequisites>
<Resources>
<Resource Language="EN" />
</Resources>
<Applications>
<Application Id="App" Executable="gfg.exe" EntryPoint="gfg.App">
<VisualElements DisplayName="fdsf" Logo="Assets\Logo.png" SmallLogo="Assets\SmallLogo.png" Description="gfdsg" ForegroundText="light" BackgroundColor="#2672EC">
<DefaultTile ShowName="allLogos" WideLogo="Assets\WideLogo.png" ShortName="gfdsg" />
<SplashScreen Image="Assets\SplashScreen.png" BackgroundColor="#2672EC" />
<InitialRotationPreference>
<Rotation Preference="portrait" />
<Rotation Preference="landscape" />
<Rotation Preference="portraitFlipped" />
<Rotation Preference="landscapeFlipped" />
</InitialRotationPreference>
</VisualElements>
<Extensions>
<Extension Category="windows.search" />
<Extension Category="windows.shareTarget">
<ShareTarget>
<DataFormat>Text</DataFormat>
</ShareTarget>
</Extension>
</Extensions>
</Application>
</Applications>
<build:Metadata>
<build:Item Name="TargetFrameworkMoniker" Value=".NETCore,Version=v4.5" />
<build:Item Name="VisualStudio" Version="11.0" />
<build:Item Name="OperatingSystem" Version="6.2.9200.16384 (win8_rtm.120725-1247)" />
<build:Item Name="Microsoft.Build.AppxPackage.dll" Version="11.0.50727.1" />
<build:Item Name="Microsoft.Windows.UI.Xaml.Build.Tasks.dll" Version="11.0.50727.1" />
</build:Metadata>
</Package>
나는과 같이 구문 분석하려고 :
var xml=new XmlDocument();
xml.Load(myfile);
var mgr=new XmlNamespaceManager(xml.NameTable);
mgr.AddNamespace("", "http://schemas.microsoft.com/appx/2010/manifest");
var nodes=xml.SelectNodes("Applications");
그러나, 나는이를 실행 한 후, nodes
아무것도 포함하지 않습니다. xml 문서가로드됩니다. SelectNodes("//*")
을 사용하면 모든 노드가 예상대로 반환됩니다. 내 문제는 뭐지?
나는 또한
아무것도 비록 단일 노드를 검색하기 위해 나타납니다
Applications/*
/Package/Applications/Application
Applications/Application
- 으로 그 XPath 쿼리에 많은 변화를 시도했습니다. 이상적으로 노드에
Application
노드가 모두 포함되도록하고 싶습니다.
제목은 XDocument에 대해 이야기하지만 코드는 XmlDocument를 사용합니다. LINQ to XML을 실제로 사용했다면 Descendants ... LINQ to XML 옵션을 사용하는 것이 좋습니다. –
@JonSkeet 안타깝게도 .Net 2.0을 대상으로하기 때문에 XML에 Linq를 사용할 수 없습니다. 그러나 나는 XmlDocument를 넣으려고했다. 나는 항상 두 가지를 혼동합니다. – Earlz