2012-09-10 64 views
1

将源XML文档转换为目标XML文档的直接方式是什么?源和目标之间只有很小的差异:具体而言,我想删除每个UnitIDGroup节点中的第一个UnitIDRecord节点。使用C++将一个XML文档转换为另一个XML文档

  • 什么是这个任务适当的模型DOM或SAX?
  • 什么XML库最适合这个问题(它保证源和目的地只在被删除的节点中有所不同,没有缺失的名称空间,属性,编码......)?
  • 我读了约XSLT,可以这样做吗?

的XML文档看起来像以下:

<?xml version="1.0" encoding="UTF-8"?> 
<ExPostInformationRealGeneration xmlns="http://schemas.seven2one.de/EEX/TransparencyPlatform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schemas.seven2one.de/EEX/TransparencyPlatform EEXTransparencyPlatform.xsd"> 
    <DispatcherID>XYZ</DispatcherID> 
    <CreationDateTime>2012-05-22T13:57:00Z</CreationDateTime> 
    <MessageText>1 - Positiv - Meldung mit Quality-Tag - L000</MessageText> 
    <UnitIDGroup> 
     <UnitID>E110200-001</UnitID> 
     <UnitIDRecord><Quantity>16.9</Quantity><Starttime>2008-04-30T22:00:00Z</Starttime><Period>PT1H</Period><MessageText></MessageText></UnitIDRecord> 
     <UnitIDRecord><Quantity>16.6</Quantity><Starttime>2008-04-30T23:00:00Z</Starttime><Period>PT1H</Period><MessageText></MessageText></UnitIDRecord> 
     <UnitIDRecord><Quantity>16.4</Quantity><Starttime>2008-05-01T00:00:00Z</Starttime><Period>PT1H</Period><MessageText></MessageText></UnitIDRecord> 
    </UnitIDGroup> 
    <UnitIDGroup> 
     <UnitID>E110200-002</UnitID> 
     <UnitIDRecord><Quantity>16.9</Quantity><Starttime>2008-04-30T22:00:00Z</Starttime><Period>PT1H</Period><MessageText></MessageText></UnitIDRecord> 
     <UnitIDRecord><Quantity>16.6</Quantity><Starttime>2008-04-30T23:00:00Z</Starttime><Period>PT1H</Period><MessageText></MessageText></UnitIDRecord> 
     <UnitIDRecord><Quantity>16.4</Quantity><Starttime>2008-05-01T00:00:00Z</Starttime><Period>PT1H</Period><MessageText></MessageText></UnitIDRecord> 
    </UnitIDGroup> 
    <UnitIDGroup> 
     <UnitID>E110201-001</UnitID> 
     <UnitIDRecord><Quantity>7.0</Quantity><Starttime>2008-04-30T22:00:00Z</Starttime><Period>PT1H</Period><MessageText></MessageText></UnitIDRecord> 
     <UnitIDRecord><Quantity>7.1</Quantity><Starttime>2008-04-30T23:00:00Z</Starttime><Period>PT1H</Period><MessageText></MessageText></UnitIDRecord> 
     <UnitIDRecord><Quantity>7.1</Quantity><Starttime>2008-05-01T00:00:00Z</Starttime><Period>PT1H</Period><MessageText></MessageText></UnitIDRecord> 
    </UnitIDGroup> 
    <!-- other UnitIDGroup elements --> 
</ExPostInformationRealGeneration> 
+1

问:我读过关于XSLT的问题,这可能是一个选项吗?答:是的。实际上,它可能是*首选*选项:)如果你碰巧在Windows上,这里有一个很好的教程:http://msdn.microsoft.com/en-us/library/windows/desktop/ms759206%28v=vs .85%29.aspx – paulsm4

+0

它应该发生在Windows上,谢谢你的教程。看来,我可以从链接中拿出例子,剩下的就是编写适当的XSL文件(希望这不是太困难:-)。 –

回答

0

我会考虑的读取文件中的字符串和写入字符串到另一个文件,如果您的条件匹配的可能性。这是一个5行程序,并避免任何解析等。它会运行速度快,很简单。但是,这是特定于这个问题,不可重用。因此,我提出这个建议不是正确的解决方案!