[xml] Sorting/Building sorted DOM tree



Hi,

Is there any way to sort an xml document so that it conforms to a given schema? ( assuming it is correct and has all the relevant nodes).

I am getting a random stream of data that I am using to build an xml document. It is being built correctly now, but I need to actually "order" the data because the input stream is not necessarily in the correct order.

eg:

<Invoice>
 <InvoiceDetail>
   ...
 </InvoiceDetail>
 <InvoiceHeader>
   ...
 </InvoiceHeader>
 <InvoiceFooter>
   ...
 </InvoiceFooter>
</Invoice>

Needs to end up being
<Invoice>
 <InvoiceHeader>
   ...
 </InvoiceHeader>
 <InvoiceDetail>
   ...
 </InvoiceDetail>
 <InvoiceFooter>
   ...
 </InvoiceFooter>
</Invoice>

The one way I figure to do it is to actually insert the nodes into the appropriate linked list in the correct order as I build the DOM model in memory.

My brain hurts, I know I am not going to explain this well.

Basically, I need the functionality of xmlNewChild, but rather than inserting the new node at the END of the parent children list, I need to insert it in a specific spot.

The only way that I can figure how to do it is to just call xmlNewNode, then brute force insert the new node in the correct spot in the linked list by manually changing prev, current, and potentially the parent->last pointer (as xmlNewChild does).

It just seems wrong to have to go to this low level to accomplish what I want, so is there a better way to do this?

Thanks for any pointers on the "proper" way to do this....

Steve Williams





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]