私は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("//*")
を使用すると、すべてのノードが正常に返されます。ここで私の問題は何ですか?
私はまた、このような
/Package/Applications/Application
Applications/Application
Applications/*
何もかかわらず、単一のノードを取得するために表示されないなどというXPathクエリに多くのバリエーションを試してみました。理想的には、ノードにApplication
ノードがすべて含まれているようにしたい
タイトルはXDocumentについて語りますが、コードではXmlDocumentが使用されています。 XMLにLINQを使っているのであれば、Descendantsを使うことをお勧めします... LINQ to XMLはオプションですか? –
@JonSkeet悲しいことに、私たちは.Net 2.0をターゲットにしているのでLinqをXMLに使うことはできません。しかし、私はXmlDocumentを置くことを意味しました。私はいつも2つを混乱させます – Earlz