-6

要求:如果您无法提供帮助或不想提供帮助,请不要投反对票。谢谢你。

你能帮我解析这个 XAML 吗?

<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment"
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
       EntryPointAssembly="Hello" EntryPointType="Hello.App" RuntimeVersion="4.7.50308.0">
  <Deployment.Parts>
    <AssemblyPart x:Name="Hello" Source="Hello.dll" />
  </Deployment.Parts>
</Deployment>

我尝试过 XmlDocument、XElement 和 XamlReader。没有人能够加载 XAML 并获取我的值。

更新 - 我试过的代码

     var appXaml = ... ; //the XAML string mentioned above

xml文档:

     var x = new XmlDocument();
     x.LoadXml(appXaml);

还,

 //I created XSD from the XAML using xsd.exe
 //Placed it in "D:\AppManifest.xsd"
            var n = new XmlDocument();
            var ss = new XmlSchemaSet();
            var s = new XmlSchema() { SourceUri = @"D:\AppManifest.xsd" };
            ss.Add(s);
            ss.Compile();
            n.Schemas.Add(ss);
            n.LoadXml(appXaml);

XSD 代码:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="NewDataSet" targetNamespace="http://schemas.microsoft.com/client/2007/deployment" xmlns:mstns="http://schemas.microsoft.com/client/2007/deployment" xmlns="http://schemas.microsoft.com/client/2007/deployment" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" attributeFormDefault="qualified" elementFormDefault="qualified" xmlns:app1="http://schemas.microsoft.com/winfx/2006/xaml">
  <xs:element name="Deployment">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Deployment.Parts" minOccurs="0" maxOccurs="unbounded">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="AssemblyPart" minOccurs="0" maxOccurs="unbounded">
                <xs:complexType>
                  <xs:attribute name="Name" msdata:Prefix="x" type="xs:string" />
                  <xs:attribute name="Source" form="unqualified" type="xs:string" />
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
      <xs:attribute name="EntryPointAssembly" form="unqualified" type="xs:string" />
      <xs:attribute name="EntryPointType" form="unqualified" type="xs:string" />
      <xs:attribute name="RuntimeVersion" form="unqualified" type="xs:string" />
    </xs:complexType>
  </xs:element>
  <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
    <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element ref="Deployment" />
      </xs:choice>
    </xs:complexType>
  </xs:element>
</xs:schema>

元素:

     var z = XElement.Parse(appXaml);

XamlReader:

var l = XamlReader.Parse(appXaml);
4

2 回答 2

1

try passing xml to parse.

        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.Load(@"D:\OldDesktop\Try\app.xaml");
        XElement.Parse(xmlDoc.InnerXml);

or iterate through xmldoc

        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.Load(@"D:\OldDesktop\Try\app.xaml");
        foreach (XmlElement xElement in xmlDoc.DocumentElement)
        {
           //do somthing
        }
于 2013-08-05T13:00:03.927 回答
1

我发现我从文件中读取的 XAML 内容包含BOM

I BOM 被剥离,XAML 代码是可解析的。

我使用 Visual Studio 2010。调试模式下的“文本可视化器”没有显示任何 BOM 迹象(XAML 字符串为 UTF8)。但是,当我不小心从可视化工具中复制文本并粘贴到 Notepad++ 中时,它显示“?” 符号(在本例中为 BOM。)

呸。VS中的奇怪问题。

于 2013-08-05T13:11:05.290 回答