从 xmi 文件中检索 src 值

  • 本文关键字:src 检索 xmi 文件 xslt
  • 更新时间 :
  • 英文 :


我有一组xml文件,我必须从中检索src之后存在的值。

例:

<?xml version="1.0" encoding="UTF-8"?>
<org.eclipse.epf.uma:ContentDescription xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:org.eclipse.epf.uma="http://www.eclipse.org/epf/uma/1.0.6/uma.ecore" xmlns:rmc="http://www.ibm.com/rmc" rmc:version="7.5.1" xmlns:epf="http://www.eclipse.org/epf" epf:version="1.5.1" xmi:id="-ES_igec88m8mZhEXekVK3A" name="fs_evms,_zl9y8FCTEd6XXocT9rJgNQ" guid="-ES_igec88m8mZhEXekVK3A" changeDate="2009-08-01T13:54:29.422-0400" version="7.5.0">
  <mainDescription>&lt;p>&#xD;
    &lt;img alt=&quot;&quot; src=&quot;resources/IPMS_As-Is_75.jpg&quot; width=&quot;587&quot; height=&quot;346&quot; />&#xD;
&lt;/p></mainDescription>
</org.eclipse.epf.uma:ContentDescription>

 <sections xmi:id="_vlul8AKaEd6N9prBktGuYg" name="Update the opportunity information in Siebel" guid="_vlul8AKaEd6N9prBktGuYg">
    <sectionDescription>&lt;img alt=&quot;&quot; src=&quot;resources/UpdateOpportunity.JPG&quot; width=&quot;597&quot; height=&quot;360&quot; /></sectionDescription>
  </sections>

从一个 xml 文件到另一个 xml 文件的节点的层次结构和值。请让我知道如何使用 xslt 从上述数据中检索 src 的值。

问候基兰

使用 XSLT 会严重限制您的输入,因为转义的标记不是 XML。您需要使用字符串函数提取所需的部分 - 例如:

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:template match="/">
    <output>
        <xsl:for-each select="//*[contains(text(), 'src=&quot;')]">
            <url>
                <xsl:value-of select="substring-before(substring-after(., 'src=&quot;'), '&quot;')"/>
            </url>
        </xsl:for-each>    
    </output>
</xsl:template>
</xsl:stylesheet>

您可以像这样直接访问任何xml文件。

using System;
using System.IO;
using System.Xml;
public class Sample
{
public static void Main()
{
XmlDocument doc = new XmlDocument();
doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" +
            "<title>Pride And Prejudice</title>" +
            "</book>");
XmlElement root = doc.DocumentElement;
// Check to see if the element has a genre attribute. 
if (root.HasAttribute("genre")){
  String genre = root.GetAttribute("genre");
  Console.WriteLine(genre);

}

}}

最新更新