You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Leif Goodwin <lg...@qgsl.com> on 2009/11/17 17:10:20 UTC
How to have an attribute which contains XML
We have blocks of XML which represents dialog templates. Here is an example
with 2 buttons and one number edit control:
<dialogex caption="Activity" charset="1" cx="522" cy="348" decplaces="5"
field="activity" fontname="MS Shell Dlg" italic="0" major_version="1"
minor_version="0" ptsize="8" resid="130"
style="DS_SETFONT|DS_MODALFRAME|DS_FIXEDSYS|WS_POPUP|WS_CAPTION|WS_SYSMENU"
type="DIALOGEX" weight="400" x="0" y="0">
<pushbutton caption="OK" cx="63" cy="15" resid="IDOK" style="WS_TABSTOP"
x="453" y="7"/>
<pushbutton caption="Cancel" cx="63" cy="15" resid="IDCANCEL"
style="WS_TABSTOP" x="453" y="28"/>
<editnumber cx="100" cy="12" decplaces="3" field="no_CSP"
formula=".//activity/@LCSP - .//activity/@FCSP + 1" numeric="int"
resid="218" style="ES_AUTOHSCROLL|ES_READONLY|WS_BORDER|WS_TABSTOP" x="84"
y="297"/>
</dialogex>
You can see that the <editnumber> element has an attribute called "formula"
which contains an XQuery expression. This works fine until the XQuery
expression contains something like the following:
"<data>.//activity/@status</data>"
The problem is that Xerces does not like an attribute value that contains
the '<' and '>' characters. When I try to parse the <dialogex> element with
a formula attribute containing the above XQuery expression, it goes wobbly,
and fails.
Does anyone know a way around this? (Of course I could pre-parse the formula
string, and replace all '<' characters with "@@lt" for example, and
similarly for '<', and hope that our formula never needs to contain "@@lt"
and "@@gt". But I'd rather find a more elegant method.)
--
View this message in context: http://old.nabble.com/How-to-have-an-attribute-which-contains-XML-tp26392607p26392607.html
Sent from the Xerces - C - Dev mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org
RE: How to have an attribute which contains XML
Posted by Jesse Pelton <js...@PKC.com>.
If I understand you correctly, what I described is not in fact exactly
what you do. It sounds like rather than the invalid serialization that
I asked about, your document is being serialized correctly.
Invalid:
<editnumber formula="<data>.//activity/@status</data>"/>
Valid:
<editnumber formula="<data>.//activity/@status</data>"/>
If this is true, the problem is in the parsing as you suggest. I think
a test case is needed. I'd recommend attaching an example of a
problematic document that cannot be processed by one of the sample
applications (like DOMParse).
-----Original Message-----
From: Leif Goodwin [mailto:lgoodwin@qgsl.com]
Sent: Wednesday, November 18, 2009 5:31 AM
To: c-dev@xerces.apache.org
Subject: RE: How to have an attribute which contains XML
Yes, that is exactly what we do. I use the setAttribute method on
DOMElement
instance passing name as "formula" and value as
"<data>.//activity/@status</data>". Then I serialise the DOMDocument to
a
string. When I examine the string, I see that Xerces has replaced each
'<'
with "<" which is correct. But it leaves each '>' as is. Then when I
try
to serialise the string into a DOM document, the result is nonsense, as
I
think the '>' characters are interpreted as close element markers. I
tried
replacing each '>' with ">" in the string before passing it to
setAttribute, but that did not work, as it replces the '&' with "&".
---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org
RE: How to have an attribute which contains XML
Posted by Leif Goodwin <lg...@qgsl.com>.
Yes, that is exactly what we do. I use the setAttribute method on DOMElement
instance passing name as "formula" and value as
"<data>.//activity/@status</data>". Then I serialise the DOMDocument to a
string. When I examine the string, I see that Xerces has replaced each '<'
with "<" which is correct. But it leaves each '>' as is. Then when I try
to serialise the string into a DOM document, the result is nonsense, as I
think the '>' characters are interpreted as close element markers. I tried
replacing each '>' with ">" in the string before passing it to
setAttribute, but that did not work, as it replces the '&' with "&".
Are you saying that the document may be serialized with an element like the
following?
<editnumber formula="<data>.//activity/@status</data>">
If so, the serialization is invalid. See
http://www.w3.org/TR/2006/REC-xml-20060816/#syntax. '<' must be represented
as a numeric character reference or '<' when it's not used as a markup
delimiter. If humans have to look at the markup, you might want to
represent '>' as '>' for symmetry. Note that ampersands must also be
escaped. A spec-compliant XML processor will take care of this for you.
--
View this message in context: http://old.nabble.com/How-to-have-an-attribute-which-contains-XML-tp26392607p26405545.html
Sent from the Xerces - C - Dev mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org
RE: How to have an attribute which contains XML
Posted by Jesse Pelton <js...@PKC.com>.
Are you saying that the document may be serialized with an element like the following?
<editnumber formula="<data>.//activity/@status</data>">
If so, the serialization is invalid. See http://www.w3.org/TR/2006/REC-xml-20060816/#syntax. '<' must be represented as a numeric character reference or '<' when it's not used as a markup delimiter. If humans have to look at the markup, you might want to represent '>' as '>' for symmetry. Note that ampersands must also be escaped. A spec-compliant XML processor will take care of this for you.
-----Original Message-----
From: Leif Goodwin [mailto:lgoodwin@qgsl.com]
Sent: Tue 11/17/2009 11:10 AM
To: c-dev@xerces.apache.org
Subject: How to have an attribute which contains XML
We have blocks of XML which represents dialog templates. Here is an example
with 2 buttons and one number edit control:
<dialogex caption="Activity" charset="1" cx="522" cy="348" decplaces="5"
field="activity" fontname="MS Shell Dlg" italic="0" major_version="1"
minor_version="0" ptsize="8" resid="130"
style="DS_SETFONT|DS_MODALFRAME|DS_FIXEDSYS|WS_POPUP|WS_CAPTION|WS_SYSMENU"
type="DIALOGEX" weight="400" x="0" y="0">
<pushbutton caption="OK" cx="63" cy="15" resid="IDOK" style="WS_TABSTOP"
x="453" y="7"/>
<pushbutton caption="Cancel" cx="63" cy="15" resid="IDCANCEL"
style="WS_TABSTOP" x="453" y="28"/>
<editnumber cx="100" cy="12" decplaces="3" field="no_CSP"
formula=".//activity/@LCSP - .//activity/@FCSP + 1" numeric="int"
resid="218" style="ES_AUTOHSCROLL|ES_READONLY|WS_BORDER|WS_TABSTOP" x="84"
y="297"/>
</dialogex>
You can see that the <editnumber> element has an attribute called "formula"
which contains an XQuery expression. This works fine until the XQuery
expression contains something like the following:
"<data>.//activity/@status</data>"
The problem is that Xerces does not like an attribute value that contains
the '<' and '>' characters. When I try to parse the <dialogex> element with
a formula attribute containing the above XQuery expression, it goes wobbly,
and fails.
Does anyone know a way around this? (Of course I could pre-parse the formula
string, and replace all '<' characters with "@@lt" for example, and
similarly for '<', and hope that our formula never needs to contain "@@lt"
and "@@gt". But I'd rather find a more elegant method.)
--
View this message in context: http://old.nabble.com/How-to-have-an-attribute-which-contains-XML-tp26392607p26392607.html
Sent from the Xerces - C - Dev mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org