Solved

offline xml unencoder

Posted on 2009-05-05
8
977 Views
Last Modified: 2012-05-06
I'm after a link to an offline XML unencoder. Basically a static HTML page that will let me paste in the contents of an XML tag, and will unencode all the &amp, &quot, &gt etc.

I am currently using XML Marker and I like it because its lightweight and simple (I primarily paste in existing XML to inspect it), but it does not seem to have this kind of functionality.


FYI the bigger picture is that I copy a URL string out of the browser, unencode it with a static HTML URL decoder (http://meyerweb.com/eric/tools/dencoder/), then paste that into an XML editor for inspection. I need the XML tag contents to also be unencoded though. Maybe there is a tool that does it all in one go.


Oh, and of course preferably free!
0
Comment
Question by:nmcdermaid
  • 5
  • 3
8 Comments
 
LVL 39

Expert Comment

by:abel
ID: 24461014
I think I can create what you want within a reasonable time, if I don't find one online, but it seems that this is probably already you want: http://www.opinionatedgeek.com/dotnet/tools/HtmlEncode/Decode.aspx

Just to make sure I understand you correctly, do you mean that:

<!-- this code -->

<myxml>&lt;b&gt;bold text incorrectly inside encoded tags&lt;/b&gt;</myxml>
 

<data>

&lt;html&gt;

  &lt;body&gt;

    &lt;p&gt;

      &quot;some text&quot;

    &lt;/p&gt;

   &lt;/body&gt;

&lt;/html&gt;

</data>
 
 

<!-- should be translated into this code? -->

<myxml><b>bold text incorrectly inside encoded tags</b></myxml>
 

<data>

<html>

  <body>

    <p>

      "some text"

    </p>

   </body>

</html>

</data>

Open in new window

0
 
LVL 30

Author Comment

by:nmcdermaid
ID: 24463579
Yes the example you have given is what I'm after - basically rather than having to search/replace all those codes, I'd like to paste it in and do the lot.
The link you posted doesn't seem to do that though (plus its online - I don't want to have to install an aspx page)
Basically a static HTML page with some javascript to do the search/replace on the pasted string would be fantastic.
Something that would do both (Button 1 - de-encode URL string. Button 2 - de econde XML string) would be absolutely fantastic!
Its really just a search/replace if I understand it correctly.
Even if you did a small static web page with some javascript with a limited subset of tokens, I could extend to the rest.
I just can't seem to find something like it on the web.
PS thank you for responding.
0
 
LVL 39

Expert Comment

by:abel
ID: 24463606
> The link you posted doesn't seem to do that though

I used that link to create the example above. Why doesn't it work for you, am I missing some detail about what you want en/decoded?

I'll try to build a little page for you.
0
 
LVL 39

Expert Comment

by:abel
ID: 24463741
Ok, I created a very simple HTMLEncoder/Decoder which I put online for future reference. The trick that is exposed is simple but efficient: just set the data as innerHTML of an element (hidden of course) and read it back in as nodeValue. Works flawlessly on IE7 and FF3 (not tested further, but technique is well known).

In the code below tempDiv is any temporary div with at least one character content and hidden (display:none). The "encoded" and "decoded" should be textareas. For more information, see the working version online.

-- Abel --

// the basic idea:
 

function HTMLdecode(){

    var tempDiv = document.getElementById("tempDiv");

    tempDiv.innerHTML = document.getElementById("encoded").value;            

    document.getElementById("decoded").value = tempDiv.childNodes[0].nodeValue;

}

function HTMLencode(){

    var tempDiv = document.getElementById("tempDiv");

    tempDiv.childNodes[0].nodeValue = document.getElementById("decoded").value;

    document.getElementById("encoded").value = tempDiv.innerHTML;

}

Open in new window

0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 30

Author Comment

by:nmcdermaid
ID: 24514499
Thanks abel. My apologies for taking so long to get back to you. That certainly works for the example data that I indicated, but when I paste in my particualr XML escaped string, does not unescape as expected. It is entirely likely that I misled you above on the type of data to unencode.
I have pasted my XML encoded string below. If that is pasted into the HTML page it returns run
Possibly it does not match the type of data that I indicated earlier - sorry!
As an overview I am:
1. Capturing the parameter part of a URL string which is passed to a web app
2. Passing that through a URL decode HTML app which basically uses unescape(encoded.replace(/\+/g,  " ")); to decode the URL
3. That gives me the posted string below which is valid XML and pastes into XML Marker OK, but has lots of nasty escaped XML such as &apos; in it.
If I can get the string below to decode then can stick it all together and make one page that makes decoding easier for me.
My apologies for dragging this on, I really do appreciate your efforts.
 

<authoredDrillRequest><param name="action">run</param><param name="target">/content/folder[@name=&apos;Packages&apos;]/package[@name=&apos;Maintenance&apos;]/folder[@name=&apos;Labour Utilisation&apos;]/folder[@name=&apos;Management Reporting&apos;]/report[@name=&apos;KPI 9 - Man Hours Allocated&apos;]</param><param name="format">HTMLFragment</param><param name="locale">en-au</param><param name="prompt">false</param><param name="sourceContext">&lt;bus:parameters xsi:type=&quot;SOAP-ENC:Array&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; SOAP-ENC:arrayType=&quot;bus:baseParameter[2]&quot; xmlns:SOAP-ENC=&quot;http://schemas.xmlsoap.org/soap/encoding/&quot; xmlns:bus=&quot;http://developer.cognos.com/schemas/bibus/3/&quot;&gt;

    &lt;item xsi:type=&quot;bus:parameter&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&gt;

      &lt;bus:name xsi:type=&quot;xs:string&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:bus=&quot;http://developer.cognos.com/schemas/bibus/3/&quot;&gt;pWorkArea&lt;/bus:name&gt;

      &lt;bus:type xsi:type=&quot;bus:parameterDataTypeEnum&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:bus=&quot;http://developer.cognos.com/schemas/bibus/3/&quot;&gt;memberUniqueName&lt;/bus:type&gt;

    &lt;/item&gt;

    &lt;item xsi:type=&quot;bus:parameter&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&gt;

      &lt;bus:name xsi:type=&quot;xs:string&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:bus=&quot;http://developer.cognos.com/schemas/bibus/3/&quot;&gt;pDates&lt;/bus:name&gt;

      &lt;bus:type xsi:type=&quot;bus:parameterDataTypeEnum&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:bus=&quot;http://developer.cognos.com/schemas/bibus/3/&quot;&gt;memberUniqueName&lt;/bus:type&gt;

    &lt;/item&gt;

  &lt;/bus:parameters&gt;</param><param name="objectPaths">&lt;bus:objectPaths xsi:type=&quot;SOAP-ENC:Array&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; SOAP-ENC:arrayType=&quot;bus:searchPathSingleObject[4]&quot; xmlns:SOAP-ENC=&quot;http://schemas.xmlsoap.org/soap/encoding/&quot; xmlns:bus=&quot;http://developer.cognos.com/schemas/bibus/3/&quot;&gt;

    &lt;item xsi:type=&quot;bus:searchPathSingleObject&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&gt;i62E0D313C7E34D0BA55A952247589B14&lt;/item&gt;

    &lt;item xsi:type=&quot;bus:searchPathSingleObject&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&gt;iF8A53A4BA46C462F9987E8848AA7459B/model[last()]&lt;/item&gt;

    &lt;item xsi:type=&quot;bus:searchPathSingleObject&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&gt;/content/folder[@name=&amp;apos;Packages&amp;apos;]/package[@name=&amp;apos;Maintenance&amp;apos;]/model[@name=&amp;apos;model&amp;apos;]&lt;/item&gt;

    &lt;item xsi:type=&quot;bus:searchPathSingleObject&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&gt;/content/folder[@name=&amp;apos;Packages&amp;apos;]/package[@name=&amp;apos;Maintenance&amp;apos;]/model[last()]&lt;/item&gt;

  &lt;/bus:objectPaths&gt;</param><drillParameters><param name="p_pWorkArea">&lt;selectChoices&gt;&lt;selectOption useValue=&quot;[(cube) MN_KPI_LabourUtilisation].[All Work Areas].[All Work Areas].[Site]-&amp;gt;:[PC].[@MEMBER].[Callide]&quot; displayValue=&quot;Callide&quot;/&gt;&lt;/selectChoices&gt;</param><param name="p_pDates">&lt;selectChoices&gt;&lt;selectOption useValue=&quot;[(cube) MN_KPI_LabourUtilisation].[All Dates].[Relative Time]-&amp;gt;:[PC].[@MEMBER].[Last 2 Months]&quot; displayValue=&quot;Last 2 Months&quot;/&gt;&lt;/selectChoices&gt;</param></drillParameters><param name="executionParameters">H4sIAAAAAAAAAO1UTU-CQBA9669oejBqQpePW8VGRA5EigTwI2mI2ZYJbNzuNjtbPv692wKlIHrSm73sZua9N29mJ22GKboJVTQGDQqtVcwFuiZ4a8*1TlxCprAALhNQTiRnQqI5YoLRHGKKJGQGShrE3hJXyAricrl0lg1HqhmpV6s18ub3RjmtwgRqKiIwLGSuXidwa4*eWoNKp992W0rR9U5vFy1Et4Udk0ZJk1w9uxAQkZwyMTNWCimaSY1z*YM2XyhPIahPbO-8LP*aTENcMvMVXUDPmllSmFQJv0IXtTLVbS95oBqaZAc6pC0yqR*a-sF5nNvoGp9BbW-8tHVkccJhUCaVGBsrTEQ8RbY4aiOUkgMVtqdVum2jQB5LTBkmnK5Pz6FHUVt1y5dCz3EjtMUfy6T4zSiDyygN4cry***Pg*57j4YyVc*acYZUMykmTtDi3MoGjuY*BG7CpqExi2FSuZjpGzcYtE3mzu-4952huR24mmxsmfqlcZJsnvtXI8WzFbtygPjNzWkpoP*b442ML7Su-3RnXqX6sLJ546lA5uAXlmOT3-9cvU8qo6NLbQUAAA__</param></authoredDrillRequest>

Open in new window

0
 
LVL 39

Expert Comment

by:abel
ID: 24515547
The problem is mixed correct XML and escaped XML. To have any encoding / decoding working, you'll have to loop through the correct XML (i.e., the params) and use the decoder on each part. For instance, if I remove the first two params, and I add it to the decoder on the link, I get:

<!-- output text -->
 

<!-- first param -->

/content/folder[@name='Packages']/package[@name='Maintenance']/folder[@name='Labour Utilisation']/folder[@name='Management Reporting']/report[@name='KPI 9 - Man Hours Allocated']
 

<!-- second param -->

<bus:parameters xsi:type="SOAP-ENC:Array" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENC:arrayType="bus:baseParameter[2]" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:bus="http://developer.cognos.com/schemas/bibus/3/">

    <item xsi:type="bus:parameter" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

      <bus:name xsi:type="xs:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bus="http://developer.cognos.com/schemas/bibus/3/">pWorkArea</bus:name>

      <bus:type xsi:type="bus:parameterDataTypeEnum" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bus="http://developer.cognos.com/schemas/bibus/3/">memberUniqueName</bus:type>

    </item>

    <item xsi:type="bus:parameter" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

      <bus:name xsi:type="xs:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bus="http://developer.cognos.com/schemas/bibus/3/">pDates</bus:name>

      <bus:type xsi:type="bus:parameterDataTypeEnum" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bus="http://developer.cognos.com/schemas/bibus/3/">memberUniqueName</bus:type>

    </item>

  </bus:parameters>

Open in new window

0
 
LVL 39

Accepted Solution

by:
abel earned 500 total points
ID: 24515550
So, in other words, where you are using your unescape(encoded.replace(/\+/g,  " "));  (in step 2) to decode the string, you should place my function and you should be fine.
0
 
LVL 30

Author Comment

by:nmcdermaid
ID: 24542962
OK, thanks I'll give it a shot.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

A list of useful business intelligence software.
In this article, you will read about the trends across the human resources departments for the upcoming year. Some of them include improving employee experience, adopting new technologies, using HR software to its full extent, and integrating artifiā€¦
The viewer will learn how to set up a document for the web and print and the recommended PPI for printing.
An overview on how to enroll an hourly employee into the employee database and how to give them access into the clock in terminal.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now