结合许多XML文件
发布时间:2020-12-16 23:19:48 所属栏目:百科 来源:网络整理
导读:我可以使用什么语言来组合多个 XML文件.多个10个文件. PHP,java还是什么? 我试图使用XSLT,但我不知道我是否需要像Saxon这样的“处理器”. 文档令人困惑,因为我不知道从哪里开始. 总而言之,我需要有人指出我正确的方向. 有人请帮忙.我一直在努力解决这个问题
我可以使用什么语言来组合多个
XML文件.多个10个文件.
PHP,java还是什么? 我试图使用XSLT,但我不知道我是否需要像Saxon这样的“处理器”. 文档令人困惑,因为我不知道从哪里开始. 总而言之,我需要有人指出我正确的方向. 有人请帮忙.我一直在努力解决这个问题 <xml version="1.0"> <products> <price>Price List Here</price> <model>Model Number Here</model> </product> 解决方法
您可以使用任何允许您直接操作xml的语言.我建议用DOM而不是SAX找东西.如果你使用SAX,你必须自己基本遍历xml – 根据我的经验,这是一个皮塔饼. DOM允许您以更多OOP方式对xml执行操作.
立即产生的东西将是围绕xml“文档”的包装xml. 所以类似于: <documents> <document> <!-- Your xml here --> </document> <document> <!-- Your xml here --> </document> <document> <!-- Your xml here --> </document> </documents> 伪代码将是: 编辑 <?php // Replace the strings below with the actual filenames,add or decrease as fit $filenames = array(0 => "test.xml",1 => "test2.xml",2 => "test3.xml" ); $docList = new DOMDocument(); $root = $docList->createElement('documents'); $docList->appendChild($root); foreach($filenames as $filename) { $doc = new DOMDocument(); $doc->load($filename); $xmlString = $doc->saveXML($doc->documentElement); $xpath = new DOMXPath($doc); $query = "//product"; // this is the name of the ROOT element $nodelist = $xpath->evaluate($query,$doc->documentElement); if( $nodelist->length > 0 ) { $node = $docList->importNode($nodelist->item(0),true); $xmldownload = $docList->createElement('document'); $xmldownload->setAttribute("filename",$filename); $xmldownload->appendChild($node); $root->appendChild($xmldownload); } } echo $docList->saveXML(); ?> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |