Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON input to XML output renders empty xmlns attributes in narrative #193

Closed
cknaap opened this issue Apr 26, 2016 · 5 comments
Closed

JSON input to XML output renders empty xmlns attributes in narrative #193

cknaap opened this issue Apr 26, 2016 · 5 comments

Comments

@cknaap
Copy link
Member

cknaap commented Apr 26, 2016

Originally mentioned as issue #81 on Spark. See there for an example.

@angusmillar
Copy link
Contributor

I'm seeing much the same problem but I'm not using Spark, I'm only using the FHIR API (STU3 May2016) creating a ValueSet and setting the narrative with a very simple table like so:

        StringBuilder NarrativeString = new StringBuilder();
        NarrativeString.Append("<div>");        
          NarrativeString.Append("<p>This is some explanatory text</p>");
          NarrativeString.Append("<table>");
          NarrativeString.Append("<tr>");
              NarrativeString.Append("<td>");
                NarrativeString.Append("<span>Cell1</span>");
              NarrativeString.Append("</td>");
              NarrativeString.Append("<td>");
                NarrativeString.Append("<span>Cell1</span>");
              NarrativeString.Append("</td>");
          NarrativeString.Append("</tr>");
          NarrativeString.Append("</table>");
        NarrativeString.Append("</div>");
        Resource.Text = new Narrative();
        Resource.Text.Div = NarrativeString.ToString();

What comes out after seriaizing to XML is this narative element :

  <text>
    <div xmlns="http://www.w3.org/1999/xhtml">
      <p xmlns="">This is some explanatory text</p>
      <table xmlns="">
        <tr>
          <td>
            <span>Cell1</span>
          </td>
          <td>
            <span>Cell1</span>
          </td>
        </tr>
      </table>
    </div>
  </text>

@brianpos
Copy link
Collaborator

brianpos commented May 4, 2016

I note that your div element that you are putting into the structure doesn't have the namespace already declared. I believe you should be putting this into the content when you create it.
Are you expecting that the dotnet fhir client should detect that you didn't put it there and do it for you?
I would have expected that you code should have looked like this:
NarrativeString.AppendLine("<div xmlns=\"http://www.w3.org/1999/xhtml\">");

This is what I have in all my Narratives that I generate in sqlonfhir.

@angusmillar
Copy link
Contributor

Thanks, Brian that worked a treat! I guess, given that without me specifying the namespace the fact that it did add the correct namespace to the first element lead me to believe that it was trying to do it for me, yet had a bug. Although now I know the trick all is good. Thanks again for you help.

@brianpos
Copy link
Collaborator

brianpos commented Aug 8, 2016

Maybe we could include some validation that throws an exception if you don't provide it, or at least a trace message and debugger break to slap the developer (that wont happen without a debugger attached)

@ewoutkramer
Copy link
Member

I think the behaviour will become unpredictable if we do that, so I'd rather no do too much magic...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants