473,321 Members | 1,916 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

Parsing out embedded XML

I have a back end system that passed data to me in tabular XML format so
that it can be easily loaded into a Data Dynamics SharpGrid. The native
format for data in SharpGrid is like the following:

<Data count=1>
<row col1="My Data" col2="More Data" col3="Even more data" />
</Data>

The problem with this format is that the only way xml can be sent in one of
these attributes is to replace all < with &lt; and > with &gt;. This is
what is done for one of the columns and now I need to get the data back into
XML (see below for example of the data). My plan was to use an xml template
to do a search and replace to put back in the < and >. With the data stored
in a variable, I can then turn the variable into a node-set and do any
x-path off of it that I want. Unfortunately, I can't get my replace to
work. I know I can do this using a script tag, but I'd rather not do that
if I don't have to. Here's my approach. When I run through the xsl parser
it complains on the select="string(&lt;)" (same for &gt; version) saying
that string(&lt;) isn't a valid X-Path. Let me know if there is a better
way to do this. Preferably, one that works, since this doesn't. =)

<xsl:variable name="LongFieldData">
<xsl:call-template name="globalReplace">
<xsl:with-param name="outputString" select="LongFieldData"/>
<!-- **************************************
The one below is fine since there are the single
quotes. It's treated as a string
**************************************-->>
<xsl:with-param name="lookfor" select="'&lt;'"/>
<!-- **************************************
This one fails saying it is an invalid X-Path
**************************************-->>
<xsl:with-param name="replacewith" select="string(&lt;)" />
<xsl:call-template name="globalReplace">
<!-- with no selection on outputString, it will use the
output from last iteration as input -->
<xsl:with-param name="outputString" />
<xsl:with-param name="lookfor" select="'&gt;'"/>
<xsl:with-param name="replacewith" select="string(&gt;)" />
</xsl:call-template>
</xsl:call-template>
</xsl:variable>

<table>
<xsl:for-each select="msxsl:node-set($LongFieldData)/item" />
<tr><td>
<xsl:value-of select="xmldata" />
</tr></td>
<xsl:for-each>
</table>

<xsl:template name="globalReplace">
<xsl:param name="outputString"/>
<xsl:param name="lookfor"/>
<xsl:param name="replacewith"/>
<xsl:choose>
<xsl:when test="contains($outputString,$lookfor)">
<xsl:value-of select="concat(substring-before($outputString,$lookfor),
$replacewith)"/>
<xsl:call-template name="globalReplace">
<xsl:with-param name="outputString"
select="substring-after($outputString,$lookfor)"/>
<xsl:with-param name="lookfor" select="$lookfor"/>
<xsl:with-param name="replacewith" select="$replacewith"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$outputString"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

Here's the embedded xml:
------------------------------
&lt;item&gt; &lt;xmltag&gt; Some data that I need to get &lt;/xmltag&gt;
&lt;/item&gt; &lt;item&gt; &lt;xmltag&gt; Some more that I need to get
&lt;/xmltag&gt; &lt;/item&gt;

Here's what I want it to look like so I can turn it into a nodeset.
---------------------------------------------------------------
<item>
<xmltag>Some data that I need to get</xmltag>
</item>
<item>
<xmltag>Some more data that I need to get</xmltag>
</item>


Jul 20 '05 #1
2 2144
CB

select="'&lt;'"
And this group is not about XSLT transformations but CSS stylesheets

Cybarber

"Rob Archibald" <ro***********@intel.com> schreef in bericht
news:bk**********@news01.intel.com...
I have a back end system that passed data to me in tabular XML format so
that it can be easily loaded into a Data Dynamics SharpGrid. The native
format for data in SharpGrid is like the following:

<Data count=1>
<row col1="My Data" col2="More Data" col3="Even more data" />
</Data>

The problem with this format is that the only way xml can be sent in one of
these attributes is to replace all < with &lt; and > with &gt;. This is
what is done for one of the columns and now I need to get the data back into
XML (see below for example of the data). My plan was to use an xml template
to do a search and replace to put back in the < and >. With the data stored
in a variable, I can then turn the variable into a node-set and do any
x-path off of it that I want. Unfortunately, I can't get my replace to
work. I know I can do this using a script tag, but I'd rather not do that
if I don't have to. Here's my approach. When I run through the xsl parser
it complains on the select="string(&lt;)" (same for &gt; version) saying
that string(&lt;) isn't a valid X-Path. Let me know if there is a better
way to do this. Preferably, one that works, since this doesn't. =)

<xsl:variable name="LongFieldData">
<xsl:call-template name="globalReplace">
<xsl:with-param name="outputString" select="LongFieldData"/>
<!-- **************************************
The one below is fine since there are the single
quotes. It's treated as a string
**************************************-->>
<xsl:with-param name="lookfor" select="'&lt;'"/>
<!-- **************************************
This one fails saying it is an invalid X-Path
**************************************-->>
<xsl:with-param name="replacewith" select="string(&lt;)" />
<xsl:call-template name="globalReplace">
<!-- with no selection on outputString, it will use the
output from last iteration as input -->
<xsl:with-param name="outputString" />
<xsl:with-param name="lookfor" select="'&gt;'"/>
<xsl:with-param name="replacewith" select="string(&gt;)" />
</xsl:call-template>
</xsl:call-template>
</xsl:variable>

<table>
<xsl:for-each select="msxsl:node-set($LongFieldData)/item" />
<tr><td>
<xsl:value-of select="xmldata" />
</tr></td>
<xsl:for-each>
</table>

<xsl:template name="globalReplace">
<xsl:param name="outputString"/>
<xsl:param name="lookfor"/>
<xsl:param name="replacewith"/>
<xsl:choose>
<xsl:when test="contains($outputString,$lookfor)">
<xsl:value-of select="concat(substring-before($outputString,$lookfor),
$replacewith)"/>
<xsl:call-template name="globalReplace">
<xsl:with-param name="outputString"
select="substring-after($outputString,$lookfor)"/>
<xsl:with-param name="lookfor" select="$lookfor"/>
<xsl:with-param name="replacewith" select="$replacewith"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$outputString"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

Here's the embedded xml:
------------------------------
&lt;item&gt; &lt;xmltag&gt; Some data that I need to get &lt;/xmltag&gt;
&lt;/item&gt; &lt;item&gt; &lt;xmltag&gt; Some more that I need to get
&lt;/xmltag&gt; &lt;/item&gt;

Here's what I want it to look like so I can turn it into a nodeset.
---------------------------------------------------------------
<item>
<xmltag>Some data that I need to get</xmltag>
</item>
<item>
<xmltag>Some more data that I need to get</xmltag>
</item>
Jul 20 '05 #2
CB wrote:
select="'&lt;'"
And this group is not about XSLT transformations but CSS stylesheets


The ciwas charter (<http://css.nu/pointers/ciwast-charter.html>) does
not explicitly mention CSS:

This unmoderated newsgroup is intended for the discussion of Web
stylesheets. Style sheets can make an author's life much easier. With
style sheets, one only needs to specify presentational preferences
once, and the style can be applied to an entire site. Not only that,
but style sheets also reduce download time when one file contains all
the style information.

Topics for this newsgroup include:
* How to achieve a particular effect with style sheets,
* The relative advantages of different stylesheet languages,
* Specifications versus implementations, and
* Bugs and limitations in implementations.
--
Johannes Koch
In te domine speravi; non confundar in aeternum.
(Te Deum, 4th cent.)

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: MrBill | last post by:
I would like to be able to open, read, and extract data from a report that is produced in MS Word. The doc seems to contain embedded spreadsheets. I would like to extract some of the data from...
2
by: Peter Sprenger | last post by:
Hello, I hope somebody can help me with my problem. I am writing Zope python scripts that will do parsing on text for dynamic webpages: I am getting a text from an oracle database that contains...
3
by: Pir8 | last post by:
I have a complex xml file, which contains stories within a magazine. The structure of the xml file is as follows: <?xml version="1.0" encoding="ISO-8859-1" ?> <magazine> <story>...
4
by: Earl | last post by:
I'm curious if there are others who have a better method of accepting/parsing phone numbers. I've used a couple of different techniques that are functional but I can't really say that I'm totally...
4
by: Rick Walsh | last post by:
I have an HTML table in the following format: <table> <tr><td>Header 1</td><td>Header 2</td></tr> <tr><td>1</td><td>2</td></tr> <tr><td>3</td><td>4</td></tr> <tr><td>5</td><td>6</td></tr>...
9
by: ankitdesai | last post by:
I would like to parse a couple of tables within an individual player's SHTML page. For example, I would like to get the "Actual Pitching Statistics" and the "Translated Pitching Statistics"...
3
by: toton | last post by:
Hi, I have some ascii files, which are having some formatted text. I want to read some section only from the total file. For that what I am doing is indexing the sections (denoted by .START in...
13
by: Chris Carlen | last post by:
Hi: Having completed enough serial driver code for a TMS320F2812 microcontroller to talk to a terminal, I am now trying different approaches to command interpretation. I have a very simple...
6
by: James Arnold | last post by:
Hello, I am new to C and I am trying to write a few small applications to get some hands-on practise! I am trying to write a random string generator, based on a masked input. For example, given...
1
by: Philip Semanchuk | last post by:
On Oct 12, 2008, at 5:25 AM, S.Selvam Siva wrote: Selvam, You can try to find them yourself using string parsing, but that's difficult. The closer you want to get to "perfect" at finding URLs...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.