简体   繁体   English

Node.js中的XML(使用Javascript)

[英]XML in Node.js (Using Javascript)

I've got simulated XML data stored the hard disk (called simmedData.xml). 我已经将模拟的XML数据存储在硬盘上(称为simmedData.xml)。 I've also got 'real' data (the 'real' data is dynamic) vended through a web endpoint ( http://localhost:8079/realData ). 我还通过Web端点( http://localhost:8079/realData )获得了“真实”数据(“真实”数据是动态的)。

The format of the XML documents are exactly the same, but I would like to 'merge' them into one endpoint available at http://localhost:8080/mergedData . XML文档的格式完全相同,但我想将它们“合并”到http://localhost:8080/mergedData一个端点。

I want to use node.js to host the mergedData endpoint -- Is there a simple way to merge these xml documents together when mergedData is requested? 我想使用node.js来托管mergedData端点 - 在请求mergedData时,是否有一种简单的方法将这些xml文档合并在一起?

For example: 例如:

simmedData.xml simmedData.xml

<site:Tracks xmlns:site='http://mysite/site'>
  <site:track id='1' latitude='37.82091918923291' longitude='128.87375778822812' altitude='9753.6005859375' bearing='10.542624087704585' speedInKnots='454.6067199707031' />
  <site:track id='2' latitude='37.45048387959727' longitude='129.49111126654887' altitude='9144.0' bearing='190.90400586790983' speedInKnots='436.89837646484375' />
</site:Tracks>

http://localhost:8079/realData HTTP://本地主机:8079 / realData

<site:Tracks xmlns:site='http://mysite/site'>
  <site:track id='1001' latitude='39.82093291' longitude='128.87375722812' altitude='9753.60375' bearing='10.542704585' speedInKnots='454.6707031' />
  <site:track id='1002' latitude='39.387959727' longitude='129.4126654887' altitude='9144.0' bearing='90.90790983' speedInKnots='436.8984375' />
  <site:track id='1003' latitude='40.82093291' longitude='138.87375722812' altitude='9753.5' bearing='10.542704585' speedInKnots='454.6707031' />
  <site:track id='1004' latitude='40.387959727' longitude='139.4126654887' altitude='9124.0' bearing='90.90790983' speedInKnots='436.8984375' />
</site:Tracks>

http://localhost:8080/mergedData HTTP://本地主机:8080 / mergedData

<site:Tracks xmlns:site='http://mysite/site'>
  <site:track id='1' latitude='37.82091918923291' longitude='128.87375778822812' altitude='9753.6005859375' bearing='10.542624087704585' speedInKnots='454.6067199707031' />
  <site:track id='2' latitude='37.45048387959727' longitude='129.49111126654887' altitude='9144.0' bearing='190.90400586790983' speedInKnots='436.89837646484375' />
  <site:track id='1001' latitude='39.82093291' longitude='128.87375722812' altitude='9753.60375' bearing='10.542704585' speedInKnots='454.6707031' />
  <site:track id='1002' latitude='39.387959727' longitude='129.4126654887' altitude='9144.0' bearing='90.90790983' speedInKnots='436.8984375' />
  <site:track id='1003' latitude='40.82093291' longitude='138.87375722812' altitude='9753.5' bearing='10.542704585' speedInKnots='454.6707031' />
  <site:track id='1004' latitude='40.387959727' longitude='139.4126654887' altitude='9124.0' bearing='90.90790983' speedInKnots='436.8984375' />
</site:Tracks>

If you want to do any kind of intelligent "XML-aware" merge then you probably would be looking at an XML parser to do DOM manipulation or an XSLT transformer to run a stylesheet that would merge the two. 如果你想进行任何类型的智能“XML感知”合并,那么你可能会看到一个XML解析器来执行DOM操作或者一个XSLT转换器来运行一个可以合并这两者的样式表。 I am sure there are libxml/libxslt wrappers for node: 我确信节点有libxml / libxslt包装器:

I recently answered a question here at SO about XML merge with XSLT but if you just do a straightforward "append" then it will be much less trickier. 我最近在这里回答了一个关于XML与XSLT合并的问题,但是如果你只是做一个简单的“追加”那么它就会变得更加棘手。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM