XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Steve GriseSubject: Handling embedded "<" in a source xml file
Author: Steve Grise
Date: 18 May 2007 05:01 PM
I have a source xml document that works within an existing product, but it creates problems for me when I try to use xslt. The xml contains "<" and ">" characters that I'm having a hard time replacing:

<CodedValue xsi:type="es:CodedValue">
<Name>FS - Balsam fir and spruce occur and are each < 10 % of the stand (Balsam Fir dominants); maximum of 20%</Name>
<Code xsi:type="xs:string">FS</Code>
</CodedValue>

Is there a way I can create a template and fix these values in Stylus Studio, or are there any other Javascript etc. solutions for this? I might be able to cheat by replacing " < " with " &lt; " in the xml file but that's obviously a hack.

Steve

Postnext
Tony LavinioSubject: Handling embedded
Author: Tony Lavinio
Date: 21 May 2007 08:52 AM
Originally Posted: 21 May 2007 08:51 AM
It's not a hack. The < character must be escaped, as in &lt;, if it's
in the middle of text. Otherwise the parser has no clear indication
that it isn't starting an end-tag construct.

That's not just our rule, but is the XML standard. The other parser
is in error, since it is allowing something nonstandard, and the text
of the standard clearly states that conforming XML processors should
act the same in this case.

Postnext
Steve GriseSubject: Handling embedded
Author: Steve Grise
Date: 22 May 2007 09:03 AM
Thanks, I agree this is non-standard xml. What I meant by "hack" was that I need to rely on a space on either side of the character (ie " < " not " <" or "<" since that would replace a lot of brackets I need.

I notice that Stylus Studio gives me an error message about where the offending character is in the file - is there some way I can get to that error and do the replace functions more systematically?

Steve

Postnext
Tony LavinioSubject: Handling embedded
Author: Tony Lavinio
Date: 23 May 2007 10:10 AM
Originally Posted: 23 May 2007 10:09 AM
How are you using this file?
I'm assuming that a simple search-and-replace in the editor isn't
sufficient.

If it's in Java, I'd write a wrapper for the InputStream that would
return &lt; whenever it saw a '<' that was preceded and followed by
a space, and use that instead:
InputStream input = new FixupInputStream(input);

For JavaScript, can you grab the whole thing into a string variable
and do a search-and-replace there?

Postnext
Steve GriseSubject: Handling embedded
Author: Steve Grise
Date: 23 May 2007 10:57 AM
Yes, I'm already doing some Javascript triage on the xml file. I can do a global replace on " < ". I was hoping for something a bit cleaner, but I guess I'll just have to warn people that " < 10" is ok and " <10" is not ok... Seems like replacing "< " and " >" would be catch most of the issues.

I suppose I could also play with some other approaches for catch-and-fix in Javascript rather than global replaces.

Anyway, I think you've answered my basic question - that it's not something I can do easily within Stylus Studio as part of the xslt code I am writing.

Thanks
Steve

Posttop
Tony LavinioSubject: Handling embedded
Author: Tony Lavinio
Date: 23 May 2007 04:56 PM
Of course the real solution, (the one you would get if you posted this
on xml-dev), is that it's not XML, since it's only XML if it follows
all of the rules - and therefore the generating application should be
fixed.

But you already knew that. Sorry you have to suffer for someone else's
bug.

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.