Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7831983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:58:31+00:00 2026-06-02T11:58:31+00:00

We’re using IronPython on C#, and I get different results on the console and

  • 0

We’re using IronPython on C#, and I get different results on the console and on our application.

This code runs fine on IronPython Console:

str=[]
a = 1
b = 0
c = 1
if a==1:
   str.append('One')

if b==1:
   str.append('Two')

if c==1:
   str.append('Three')

out=','.join(str)
print out

But the same code returns an error on our application:

unexpected token 'if'

I suspect that the problem is in my newlines, because the string containing the Python code is passed through XML (XML>C#>Python):

<Set key="PythonCode" value="ipy:str=[]
a = 1
b = 0
c = 1
if a==1:
   str.append('One')

if b==1:
   str.append('Two')

if c==1:
   str.append('Three')

out=','.join(str)"/>

Other commands return expected results, my problem is with indented commands (conditions, loops).

As I don’t have access to the C# code, I look for a way to write one-liners, or any other way not to be dependent on indentation or newlines.
I tried this:

<Set key="PythonCode" value="ipy:str=[];
a = 1;
b = 0;
c = 1;
if a==1: str.append('One');
if b==1: str.append('Two');
if c==1: str.append('Three');
out=','.join(str);"/>

But I get again the same error, because there should be a blank line after each condition.

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T11:58:33+00:00Added an answer on June 2, 2026 at 11:58 am

    Nonsignificant whitespace in xml is not preserved

    http://www.w3.org/TR/1998/REC-xml-19980210#AVNormalize

    Before the value of an attribute is passed to the application or checked for validity, the XML processor must normalize it as follows:
    (…)
    a whitespace character (#x20, #xD, #xA, #x9) is processed by appending #x20 to the normalized value, except that only a single #x20 is appended for a “#xD#xA” sequence that is part of an external parsed entity or the literal entity value of an internal parsed entity
    (…)
    If the declared value is not CDATA, then the XML processor must further process the normalized attribute value by discarding any leading and trailing space (#x20) characters, and by replacing sequences of space (#x20) characters by a single space (#x20) character.

    if you want to transmit text with significant whitespace within xml tags, you need to enclose it inside a cdata section:

    <<Set key="PythonCode"><![CDATA[ 
    
    YOUR CODE HERE
    
    ]]></Set>
    

    As far as I know, you cannot use a cdata section inside an attribute string, so you will have to change that part of your xml format to enclose the code in tags instead.


    Another workaround would be to tell your xml exporter as well as your xml importer to preserve nonsignificant whitespace.

    for c# how to do this depends on which method you use to parse xml (XDocument, XmlDocument, …), see for example

    http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.preservewhitespace(v=vs.71).aspx

    http://msdn.microsoft.com/en-us/library/bb387014.aspx

    http://msdn.microsoft.com/en-us/library/bb387103.aspx

    But using cdata is definitely the better solution


    what you definitely should not do is use Whython – Python For People Who Hate Whitespace

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.