473,385 Members | 1,470 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,385 software developers and data experts.

embedding xml in xml as string

I have an xml format for creating a database; lets say a fragment looks
like this:

<insertValue type="int">7</insert>
<insertValue type="string">Hello everyone</insert>
now I have a document I am transforming into this format using XSLT:

<nDwarves>7</nDwarves>
<snowWhiteSays>Hello everyone</snowWhiteSays>
<groupReply><possibleReplies replyTo="greeting">hello</possibleReplies>
<possibleReplies replyTo="workSignal">hi ho, hi ho</possibleReplies>
</groupReply>
My problem is that I want to put the entire contents of the <groupReply>
node into a string, escaping the "<" and ">", so that I have an
insertValue node containing the string which is essentially a bit of
escaped xml.

Unfortunately, <xsl:copy-of... > doesnt have an option to escape the xml
characters, so far as I can see. Is there another way?
background:
why do this?
I am using the Xerces2.3 parser to get the text content of the
<insertValue> nodes, then I upload it. If I have straight xml inside
this node, then getTextContent simply returns the collapsed text content
of all the child elements * with no element names etc, when what I want
is the actual xml fragment to insert in my database as a string. I hope
to get around this by escaping the xml, so it really looks like just
another string.
Nov 2 '05 #1
1 1732
In article
<sh*****************************@news-reader.wanadooportails.com>,
shaun roe <sh*******@wanadoo.fr> wrote:

it probably bad form to answer your own question, but I think this will
do it:

<!-- serializing the embedded xml into a string -->
<xsl:template name="serialize">
<xsl:param name="nodeset"/>
<!-- openstarttag, openendtag, closetag markers, and close empty tag
marker -->
<xsl:variable name="ot" select="'&lt;'"/>
<xsl:variable name="oet" select="'&lt;/'"/>
<xsl:variable name="ct" select="'&gt;'"/>
<xsl:variable name="cet" select="'/&gt;'"/>
<xsl:for-each select="$nodeset">
<xsl:variable name="n" select="name()"/>
<xsl:variable name="value" select=".[not(./*)]"/>
<xsl:variable name="attributes">
<xsl:for-each select="./@*">
<xsl:call-template name="serializeAttribute"/>
</xsl:for-each>
</xsl:variable>
<xsl:choose>
<xsl:when test="empty(.)">
<xsl:value-of select="concat($ot,$n,$attributes,$cet,$LF)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat($ot,$n,$attributes,$ct,$value)"/>
<xsl:call-template name="serialize">
<xsl:with-param name="nodeset" select="./*"/>
</xsl:call-template>
<xsl:value-of select="concat($oet,$n,$ct,$LF)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
<!--serialize one attribute -->
<xsl:template name="serializeAttribute">
<xsl:variable name="q" select="'&quot;'"/>
<xsl:variable name="an" select="name()"/>
<xsl:variable name="av" select="."/>
<xsl:value-of select="concat(' ',$an,'=',$q,$av,$q)"/>
</xsl:template>
Nov 2 '05 #2

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

Similar topics

4
by: Alicia Haumann | last post by:
I accidentally sent this to webmaster@python.org, so this could be a duplicate if "webmaster" forwards it to this list. :{ Hi, there. Thanks for any help that can be offered. I've been...
5
by: Victor Fees | last post by:
I have an XML string in a database that I would like to display using XSLT. All of that works like a champ, but I can't figure out how to embed the XML inside an ASPX page. For example, I have...
2
by: Matt | last post by:
I'm working on a plug-in for an application called DesktopSideBar for Windows. It emulates to some degree the Longhorn sidebar. The SDK for DesktopSideBar supports .NET plug-in development through...
0
by: hq4000 | last post by:
Given AStyleSheet.xsl : <AStyleSheet> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.mytest.mytest2.mytest3.com" version="1.0"> <xsl:output method="xml"...
0
by: Fozzie | last post by:
Hi, I have a problem which is quite circular, and hopefully either someone has encountered something similar or has a reason why this will not work. We have a COM library providing...
18
by: Andrew Backer | last post by:
Is it possible to embed a newline constant in a string in the same way as c#? I really don't want to do something like this: ++ String.Format("Line 1 : {0} " & vbcrlf & " Line 2 : {1}", o, t)...
3
by: Jim Hill | last post by:
Well, I've found about a hundred thousand web pages where people have had the same problem I have but nary a page with a solution that works for me. I want to do a simple embed, so I've followed...
3
by: anonymisiert85 | last post by:
At the moment i can run python-string-code from C (MinGW, WinXP) But how can i register a C-function in python-RUNTIME and call this C function from python - without wrapper dll's or libs??? ...
2
by: John Grandy | last post by:
I am not having success embedding carriage return and line feed characters into a string and displaying them with an ASP.NET label. Is anyone getting either of the following to work ? ...
1
by: Benke | last post by:
Hello, I'm quite new to Python and embedding python in c++. I'm trying to write a function that i can use to call a python function. It should take 3 arguments, the name of the python file, the...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.