web stats
XML namespace manipulation - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 02-08-2018, 08:30 AM
collinsmj collinsmj is offline
OBX.1 Kenobi
 
Join Date: Jun 2014
Location: Southern USA
Posts: 27
collinsmj is on a distinguished road
Default XML namespace manipulation

Mirth Connect V. 3.5.1
Message Format: XML
I have unchecked the strip namespaces on source, destination, and template.

I have found several other posts that deal with namespaces but I have an issue with the namespace on a particular attribute.
I am reading in a xml file that has 4 in scope namespaces. It is an .xml file generated by MS Excel.

I cannot figure out how to get the namespaces of the rows and cells correct via a javascript transformer. Here is the declaration of the name spaces and the section of the xml i am trying to alter. The goal is to change the Data value of 1 into some other number say 1000. I am aware the default namespace and the ss are the same. This cannot be changed.

Code:
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:o="urn:schemas-microsoft-com:office:office"
 xmlns:x="urn:schemas-microsoft-com:office:excel"
 xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:html="http://www.w3.org/TR/REC-html40">
<Worksheet>
  <Table>
  <Row ss:AutoFitHeight="0">
    <Cell ss:StyleID="s67">
      <Data ss:Type="Number">1</Data>
    </Cell>
  </Row>
</Table>
</Worksheet>
</Workbook>
My issue is when i do the following i get a second tag.
Code:
  msg['Worksheet']['Table']['Row'][5]['Cell'][0]['Data'] = '1000'
  
  Results in 
  
  <Cell ss:StyleID="s67">
      <Data ss:Type="Number">1</Data>
      <ss:Data>1000</ss:Data>
  </Cell>
A ss:data tag is created and assigned the value instead of changing the existing Data tag.

but when i access it ignoring namespaces it gains a incorrect namespace.
Code:
  msg['Worksheet']['Table']['Row'][5]['Cell'][0].*::['Data'] = '1000'
  
  Results in 
  
  <Cell ss:StyleID="s67">
      <Data xmlns="" ss:Type="Number">1</Data>
  </Cell>
so i attempted to create my own Data tag and add type back with the following but Type doesn't have the proper namespace.
Code:
  msg['Worksheet']['Table']['Row'][5]['Cell'][0].*::['Data'] = '1000'
  msg['Worksheet']['Table']['Row'][5]['Cell'][0]['Data']['@Type'] = 'Number';
  
  Results in 
  
  <Cell ss:StyleID="s67">
      <Data Type="Number">1</Data>
  </Cell>
I have found many posts on E4X and namespace issues. But none of them have resolved this issue for me. This post was particularly helpful

http://www.mirthcorp.com/community/f...ight=namespace

I have started to play with the template but am not having luck either.
Reply With Quote
  #2  
Old 02-08-2018, 10:28 AM
collinsmj collinsmj is offline
OBX.1 Kenobi
 
Join Date: Jun 2014
Location: Southern USA
Posts: 27
collinsmj is on a distinguished road
Default

Wow, i have continued to play with this and have discovered my own solution. I decided to work off of a clean tmp and not worry about access issues. I avoid using .*:: because that wrecks the namespace hierarchy.


Code:
  var reg = new Namespace('', 'urn:schemas-microsoft-com:office:spreadsheet');
  var ss = new Namespace('ss', 'urn:schemas-microsoft-com:office:spreadsheet'); 

  tmp['Worksheet']['Table']['Row'][5]['Cell']['Data'] = 1000;
  tmp['Worksheet']['Table']['Row'][5]['Cell']['Data'].setNamespace(reg);
  tmp['Worksheet']['Table']['Row'][5]['Cell']['Data']['@Type'] = "Number";
  tmp['Worksheet']['Table']['Row'][5]['Cell']['Data']['@Type'].setNamespace(ss)
declare the same namespace, prefix pair as it exists in the xml file. Set the data using what is most likely the wrong namespace. set the attributes using the wrong namespace as well. Then go back and setNamespace to the expected ones on the tag or attribute element. This solution is clean but requires about 3 times more code than expected. I was under the impression i could set namespace while declaring the tag or attribute.

this syntax doesn't work but tmp['Worksheet']['Table'].reg::[Cell].reg::[Data].ss["Type"] = "Number".


Is there another syntax or shortcut? Perhaps something easier to read or less verbose?
Reply With Quote
Reply

Tags
e4x, namespace

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 01:52 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation