XSL character replace

Dominic (4)

Usenet Archive
Joined
Apr 28, 2010
Messages
5
Reaction score
0
Hi there,

I'm dipping my toes into XSL and have used it a little in order to remove the XML header of some XML which an API kept choking on (not sure why TBH, seems an odd state of affairs that!). Now a different API is choking on " (double quote - (HTML: ")) but is fine with ' (single quote (HTML: ')) for enclosing attributes. I've been using a simple string replace to convert "s to 's (If you see what I mean?) but have to convert the XML to a string rather than keep it as XML. Is there an XSL way that'll do the same thing so that I can keep the XML as XML?

Thanks in advance

Dom
 

Martin Honnen

Usenet Archive
Joined
Apr 8, 2000
Messages
6,174
Reaction score
0
Dominic said:
I'm dipping my toes into XSL and have used it a little in order to remove the XML header of some XML which an API kept choking on (not sure why TBH, seems an odd state of affairs that!). Now a different API is choking on " (double quote - (HTML: ")) but is fine with ' (single quote (HTML: ')) for enclosing attributes. I've been using a simple string replace to convert "s to 's (If you see what I mean?) but have to convert the XML to a string rather than keep it as XML. Is there an XSL way that'll do the same thing so that I can keep the XML as XML?

Do you want to replace double quotes in character data (e.g. element or attribute content)? Or do you want to replace double quotes in markup (e.g. attribute value delimiters)?

But all that sounds rather odd, are those APIs that are choking really APIs that are supposed to process XML?
 

Dominic (4)

Usenet Archive
Joined
Apr 28, 2010
Messages
5
Reaction score
0
Do you want to replace double quotes in character data (e.g. element or attribute content)? Or do you want to replace double quotes in markup (e.g. attribute value delimiters)?
I'm pretty sure that what I want is a way to convert the attribute value delimiters rather than character data. If I'm understanding the terminology correctly (always a possibility ;-))
But all that sounds rather odd, are those APIs that are choking really APIs that are supposed to process XML?
Believe it or not they are indeed! I had problems getting my head around the concept as well but there you go...
To elaborate further:

What I'm after is something that'll convert this:

<something scheme="http://example.com" term="http:// anotherexample.org" />

into:

<something scheme='http://example.com' term='http:// anotherexample.org' />

Cheers for your reply,

Dom
 

Martin Honnen

Usenet Archive
Joined
Apr 8, 2000
Messages
6,174
Reaction score
0
Dominic said:
To elaborate further:

What I'm after is something that'll convert this:

<something scheme="http://example.com" term="http:// anotherexample.org" />

into:

<something scheme='http://example.com' term='http:// anotherexample.org' />

But that is not something XSLT can do for you really, XSLT operates on a tree model with nodes of type element, attribute (and others). That tree model does not store the type of attribute value delimiters at all, and the serialization of such a tree back to markup does not allow you to define the attribute value delimiters either.

In the .NET world (where I am mostly at home when it comes to dealing with XML programmatically) I would solve that with reading the XML in with an XmlReader and feeding it back to an XmlTextWriter which has a QuoteChar http://msdn.microsoft.com/en-us/library/system.xml.xmltextwriter.quotechar(v=VS.100).aspx property that can be set.
 

Dominic (4)

Usenet Archive
Joined
Apr 28, 2010
Messages
5
Reaction score
0
But that is not something XSLT can do for you really, XSLT operates on a tree model with nodes of type element, attribute (and others). That tree model does not store the type of attribute value delimiters at all, and the serialization of such a tree back to markup does not allow you to define the attribute value delimiters either.

In the .NET world (where I am mostly at home when it comes to dealing with XML programmatically) I would solve that with reading the XML in with an XmlReader and feeding it back to an XmlTextWriter which has a
QuoteCharhttp://msdn.microsoft.com/en-us/library/system.xml.xmltextwriter..quot...
property that can be set.

Cheers Martin,

I'm using PHP and can't seem to see anything similar in that language which is why I was looking to XSL, if it's not possible though I'll use my existing inelegant solution ;-) - at least it works even if it's a bit of a cludge ;-)

Cool blog by the way, how do you get your XML coloured and formatted so nicely? I usually do it by hand but it takes a fair old while.

Thanks again,

Dom
 

Peter Flynn

Usenet Archive
Joined
Jan 2, 2000
Messages
1,813
Reaction score
0
Dominic wrote:

If the software can't handle this, it is not XML-conformant and must be replaced. You cannot rely on broken software to handle business processes.

///Peter
 

Mayeul

Usenet Archive
Joined
Oct 16, 2008
Messages
159
Reaction score
0
Peter said:
If the software can't handle this, it is not XML-conformant and must be replaced. You cannot rely on broken software to handle business processes.

When you think of it, part of the point of XML is that this sort of brokenness can be easily dealt with.

I'm more the type to heavily suggest upgrading to an XML-compliant toolchain and offering assistance in doing so ; /then/ if not accepted heavierly suggest against calling that XML within technical communication, calling it something else myself anyway, and offering to support this custom format for an additional fee. This additional fee will enable me to make or update my own serializer, which is easy to do and test.

Sure it looks like taking in the money without caring for added value to the world. But it is also enabling your client to just do things regardless of their utter incompetence with a technology known as XML.
 

Joe Kesselman

Usenet Archive
Joined
Feb 3, 2006
Messages
1,229
Reaction score
0
Hm. The right answer for what you've requested is an XML parser feeding an XML serializer which uses ' to delimit attribute values. It might be worth simply trying one of the parse-and-regenerate sample programs that come with most XML parsers to see whether they have the desired effect. I haven't seen one that exposes the selection of apostrophe versus quote delimiters as an option; if you can't find one that is biased in the direction you need, you may want to grab an open-source serializer and tweak it.

(Trying to do this as string processing could mostly work, but will be fragile in the presence of <[CDATA]> sections, so I tend to prefer the parse-and-reserialize approach.)

XSLT manipulates document content, not syntax, and again don't generally expose this as an option.

A properly written XML application should never see, or care about, this distinction, so I'd make sure to hammer on whoever wrote the tool consuming these documents and get them to fix their code as a service to the community (and as a way of not losing customers), even if you have a workaround for your own needs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,049
Messages
3,104,245
Members
248,133
Latest member
DujonT

Latest Threads

Top