如何在一个文件中加入多个3 xmls?
在XML FILE:01.xml
中 <xmlResponse>
<Person>
<FirstName>FirstName_1</FirstName>
<LastName>LastName_1</LastName>
</Person>
<Person>
<FirstName>FirstName_2</FirstName>
<LastName>LastName_2</LastName>
</Person>
</xmlResponse>
在XML FILE:02.xml
中<xmlResponse>
<Person>
<FirstName>FirstName_2</FirstName>
<LastName>LastName_2</LastName>
</Person>
<Person>
<FirstName>FirstName_3</FirstName>
<LastName>LastName_3</LastName>
</Person>
<Person>
<FirstName>FirstName_4</FirstName>
<LastName>LastName_4</LastName>
</Person>
</xmlResponse>
在XML FILE:03.xml
中<xmlResponse>
<Person>
<FirstName>FirstName_5</FirstName>
<LastName>LastName_5</LastName>
</Person>
</xmlResponse>
我需要输出如下(01.xml + 02.xml + 03.XML)
<xmlResponse>
<Person>
<FirstName>FirstName_1</FirstName>
<LastName>LastName_1</LastName>
</Person>
<Person>
<FirstName>FirstName_2</FirstName>
<LastName>LastName_2</LastName>
</Person>
<Person>
<FirstName>FirstName_2</FirstName>
<LastName>LastName_2</LastName>
</Person>
<Person>
<FirstName>FirstName_3</FirstName>
<LastName>LastName_3</LastName>
</Person>
<Person>
<FirstName>FirstName_4</FirstName>
<LastName>LastName_4</LastName>
</Person>
<Person>
<FirstName>FirstName_5</FirstName>
<LastName>LastName_5</LastName>
</Person>
</xmlResponse>
希望你的回复, TKS ...
答案 0 :(得分:0)
试试这个XSLT 2.0样式表...
<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="2.0"
exclude-result-prefixes="xsl xs fn">
<xsl:output indent="yes" encoding="UTF-8" />
<xsl:param name="doc2" /> <!-- File 02.xml -->
<xsl:param name="doc3" /> <!-- File 03.xml -->
<xsl:variable name="doc2-doc" select="document($doc2)" />
<xsl:variable name="doc3-doc" select="document($doc3)" />
<xsl:template match="/">
<xmlResponse>
<xsl:apply-templates />
<xsl:apply-templates select="$doc2-doc/*" />
<xsl:apply-templates select="$doc3-doc/*" />
</xmlResponse>
</xsl:template>
<!-- Identity transform follows. -->
<xsl:template match="element()">
<xsl:copy>
<xsl:apply-templates select="@*,node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="attribute()|text()|comment()|processing-instruction()">
<xsl:copy/>
</xsl:template>
</xsl:stylesheet>
对于转换,输入文档将是您的第一个文档(File 01.xml),另外两个将作为转换参数传入。
如果您仅限于XSLT 1.0,则需要进行一些修改,但这不应该太难。
答案 1 :(得分:0)
您可以使用XSLT,但在ASP Classic(或实际上是其他任何东西)下执行此任务是一种过度杀伤。
(假设你没有错误标记你的问题)
Function GetDom(pathToFile)
Set GetDom = CreateObject("MSXML2.DOMDocument.3.0")
GetDom.async = False
GetDom.setProperty "SelectionLanguage", "XPath"
GetDom.load pathToFile
End Function
Sub CopyElements(xmlPrimeRoot, xmlDonor)
Dim elem
For Each elem In xmlDonor.documentElement.selectNodes("*")
xmlPrimeRoot.appendChild elem
Next
End Sub
Dim xmlPrime: Set xmlPrime = GetDom(pathToFile1)
CopyElements xmlPrime.documentElement, GetDom(pathToFile2)
CopyElements xmlPrime.documentElement, GetDom(pathToFile3)
xmlPrime.save pathToDestinationFile
如果目标输出是ASP响应,那么最后一行可以是
xmlPrime.save Response