2012-04-12 4 views
0

APIを使用して、org.w3c.domとXPathを解析しようとしているXMLファイルを取得します。 XMLファイルの一部は、HTMLコンテンツを説明します。私はこれを実現する方法のJava org.w3c.domを使用してXMLを解析する

<p>Since 2001, state and local health departments in the US have accelerated efforts to prepare for bioterrorism and other high-impact public health emergencies. These activities have been spurred by federal funding and guidance from the US Centers for Disease Control and Prevention (CDC) and the Health Resources and Services Administration (HRSA) 
    <a href="link/B1">1</a> 
    <a href="link/B2">3</a> . Over time, the emphasis of this guidance has expanded from bioterrorism to include "terrorism and non-terrorism events, including infectious disease, environmental and occupational related emergencies" 
    <a href="link/B4">4</a> as well as pandemic influenza. 
</p> 

任意の提案:

<Para>Since 2001, state and local health departments in the US have accelerated efforts to prepare for bioterrorism and other high-impact public health emergencies. These activities have been spurred by federal funding and guidance from the US Centers for Disease Control and Prevention (CDC) and the Health Resources and Services Administration (HRSA) 
    <CitationRef CitationID="B1">1</CitationRef> 
    <CitationRef CitationID="B2">2</CitationRef> . Over time, the emphasis of this guidance has expanded from bioterrorism to include "terrorism and non-terrorism events, including infectious disease, environmental and occupational related emergencies" 
    <CitationRef CitationID="B4">4</CitationRef> as well as pandemic influenza. 
</Para> 

これは、のようなものになるでしょうか?主な問題は、タグを取得し、その位置を保持しながらタグを置き換えることです。ここで

+0

これはXSLTのための完璧な仕事のように聞こえます。 XSLTコードのヘルプが必要な場合は、XSLTタグを質問に追加してください。 –

答えて

1

あなたはXSLTであることを行うことができる方法である:いくつかの他のXML形式にまたはHTMLにXML入力を変換するための言語であるよう

<xsl:stylesheet 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    version="1.0"> 

<xsl:template match="@* | node()"> 
    <xsl:copy> 
    <xsl:apply-templates select="@* | node()"/> 
    </xsl:copy> 
</xsl:template> 

<xsl:template match="Para"> 
    <p> 
    <xsl:apply-templates select="@* | node()"/> 
    </p> 
</xsl:template> 

<xsl:template match="CitationRef[@CitationID]"> 
    <a href="link/{@CitationID}"> 
    <xsl:apply-templates/> 
    </a> 
</xsl:template> 

</xsl:stylesheet> 
+0

あなたの回答をお寄せいただきありがとうございます。私はXSLT(http://www.rgagnon.com/javadetails/java-0407.html)を探しています。提供しているXSLファイルをどのように手に入れることができるか、必要なXMLパースされ、出力はすべて文字列になります(ファイルではありません)? – user485659

+0

JAXPでは文字列として入力、スタイルシート、結果が得られると確信しています。これは正しいソースを使用するための質問ですhttp://docs.oracle.com/javase/6/docs/api/javax/xml /transform/stream/StreamSource.htmlと結果の型(例えば、StringReaderを介したStreamSource)。私はJava APIに精通している人たちに、私が残しておきます。 –

+0

あなたのヒントをありがとう、私はそれが働いている!入力XMLについては、次のコードを使用しました。 'nl =(Node)xpath.evaluate(" // expression/here "、doc、XPathConstants.NODE); DOMSource source =新しいDOMSource(nl); ' – user485659

関連する問題