1

I've got simulated XML data stored the hard disk (called simmedData.xml). I've also got 'real' data (the 'real' data is dynamic) vended through a web endpoint (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.

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?

For example:

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

<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

<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>

1 Answer 1

3

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. I am sure there are libxml/libxslt wrappers for node:

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.