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 8299327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:06:34+00:00 2026-06-08T16:06:34+00:00

I have some XML that needs to be manipulated into a string to render

  • 0

I have some XML that needs to be manipulated into a string to render some instructions. The text looks like this

<?xml version="1.0" encoding="UTF-8"?>
<instructions id="detection" version="1.0">
<instruction task="detection">
    <phrase type="header">HAS THE CARD TURNED OVER?<nl/><nl/><nl/></phrase>
    <phrase type="practice">you are now going to do a practice.<nl/><nl/></phrase>
    <phrase type="real">You are now going to do a test.<nl/><nl/></phrase>
    <phrase>As soon as the card turns face up:<nl/><nl/></phrase>
    <phrase><ts/><ts/>Press YES.<nl/><nl/></phrase>
    <phrase>Go as fast as you can and try not to make any mistakes.<nl/><nl/></phrase>
    <phrase>If you press YES before a card turns face up, you will hear an error sound.</phrase>
</instruction>
</instructions>

Now, all I need to do is the following

  1. Replace all <nl/> with \n
  2. Replace all <ts/> with \t
  3. Conditionally select practice or real, probably by removing the other
  4. Remove all XML bits remaining to result in a string.

so lets say I want the practice version of this, I should end up with

HAS THE CARD TURNED OVER?\n\n\n
you are now going to do a practice.\n\n
As soon as the card turns face up:\n\n
\t\tPress YES.\n\n
Go as fast as you can and try not to make any mistakes.\n\n
If you press YES before a card turns face up, you will hear an error sound.

Now, I have the opportunity to change the structure of the XML if the current form isn’t ideal for this, but what I’m not sure is if I can do all of the above with e4X or I need to also use regex’s? Some examples would be great.

  • 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-08T16:06:36+00:00Added an answer on June 8, 2026 at 4:06 pm

    It can be done with E4X, probably not as elegantly as regex.
    Here’s an example of replacing <nl> with “\n” using E4x:

    package
    {
        import flash.display.Sprite;
    
        public class e4xStuff extends Sprite
        {
            private var srcxml:XML;
    
            public function e4xStuff()
            {
                srcxml = new XML(   '<instructions id="detection" version="1.0">' +
                    '<instruction task="detection">' +
                    '<phrase type="header">HAS THE CARD TURNED OVER?<nl/><nl/><nl/></phrase>' +
                    '<phrase type="practice">you are now going to do a practice.<nl/><nl/></phrase>' +
                    '<phrase type="real">You are now going to do a test.<nl/><nl/></phrase>' +
                    '<phrase>As soon as the card turns face up:<nl/><nl/></phrase>' +
                    '<phrase><ts/><ts/>Press YES.<nl/><nl/></phrase>' +
                    '<phrase>Go as fast as you can and try not to make any mistakes.<nl/><nl/></phrase>' +
                    '<phrase>If you press YES before a card turns face up, you will hear an error sound.</phrase>' +
                    '</instruction>' +
                    '</instructions>');
    
    
                processNode(srcxml);
                trace(srcxml);
            }
    
            private function processNode(xml:XML):XML
            {
                //replace <nl/> with \n
                if(xml.name() == "nl")
                {
                    return new XML("\n");
                }
    
                var children:XMLList = xml.children();
                if(children.length() == 0)
                {
                    return xml;
                }
    
                //remove the children
                xml.setChildren(new XMLList());   
    
                //put the children back, one-by-one, after checking for <nl/>
                for(var i:int=0; i<children.length(); i++)
                {
                    xml.appendChild(processNode(children[i])); 
                }
                return xml;
            }
        }
    }
    

    A list of E4X methods is posted at http://wso2.org/project/mashup/0.2/docs/e4xquickstart.html
    You can check for practice or real using xml.@type

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

Sidebar

Related Questions

I have some data in an XML element that looks like this: <?xml version=1.0
I have some XML that is structured like this: <whatson> <productions> <production> <category>Film</category> </production>
I have some XML that I am trying serialize like so: string Value =
I have some xml files that contain text, which are displayed on my website.
I have a table from a vendor application that stores some xml data into
I have an html string I'd like to dump directly into an element. This
I have an asp.net vb project that needs to parse some raw XML that
I have some data in a database that I need represented in an XML
I have some XML that I want to parse using the lxml method in
I have some XML files that contain different function information. I am trying to

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.