× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Jim,

just so you understand that I'm not a complete fool around doing regex
here is a little javascript that extracts a table from the HTML dom to
an XML file ...

I'm sure Dennis will read this on the fly, because he of couse know all
the browser differences in the innerHTML representation in varius
browsers and verius versions of the browsers and because he knows what
you put into the DOm isn't exactly what you get out

Just teasing ;-)



// ------------------------------------------------------------------
// Generate Raw XML File From Input Table DOM
function htmlToXML(tbody,filetag,recordtag) {
crlf = '\u000D\u000A';
xml = '<'+filetag+'>'+crlf;
rows = document.getElementById(tbody).getElementsByTagName('tr');
for (var i = 0; i < rows.length; i++) {
row = rows[i];
xml = xml+'<'+recordtag+'>'+crlf;
xml = xml+'<'+recordtag+'>'+crlf;
xml = htmlToXMLrow(row,xml);
xml = xml+'</'+recordtag+'>'+crlf;
}
xml = xml+'</'+filetag+'>'+crlf;
// alert(xml);
return(xml);
}

// Generate Raw XML Record From Input Table DOM
function htmlToXMLrow(row,xml) {
crlf = '\u000D\u000A';
tds = row.getElementsByTagName('td');
for (var i = 0; i < tds.length; i++) {
td = tds[i];
tdtag = td.getAttribute('db2field');
if (td.firstChild.value) {
if (td.firstChild.type == 'checkbox') { // input tag checkbox
if (td.firstChild.checked == true) {
if (td.firstChild.checked == true) {
tdvalue = td.firstChild.value;
} else {
tdvalue = ''
}
} else {
tdvalue = td.firstChild.value; // other input tag's
}
} else {
tdvalue = document.layers ? td.textContent : document.all ?
td.innerText : td.textContent; // td tag
}
tdvalue = tdvalue.replace(/\</g,"&lt;"); // Regex that handles
char'<' in strings
tdvalue = tdvalue.replace(/\>/g,"&gt;"); // Regex that handles
char'>' in strings
tdvalue = tdvalue.replace(/\&/g,"&amp;"); // Regex that handles
char'&' in strings
xml = xml+'<'+tdtag+'>'+tdvalue+'</'+tdtag+'>'+crlf;
}
return(xml);
}

// -------------------------------------------------------------
// handles innerHTML differencies to W3C/activeX DOM XMLobject
function html_string(html) {
html = html_tagcase(html);
html = html_crlf(html);
html = html_entities(html);
html = html.replace(/([a-z])\s*(=)\s*("|')/gi, '$1$2$3');
if (tags = html.match(/(<\/?[a-z][a-z0-9]*[^<>]*>)/gi)) {
for (var i = 0; i < tags.length; i++) {
var tag = tags[i];
tag1 = html_attributes1(tag);
tag2 = html_attributes2(tag1);
html = html.replace(new RegExp(tag, 'g'), tag2);
}
}
return html;
}

function html_tagcase(html) {
if (parts = html.match(/(<\/?[a-z][a-z0-9]*| [a-z]+=)/gi)) {
for (var i = 0; i < parts.length; i++) {
var part = parts[i];
html = html.replace(new RegExp(part, 'g'), part.toLowerCase());
}
}
return html;
}

// handles CR LF and tabs removal
function html_crlf(html) {
html = html.replace(/^\s*/, '').replace(/\n\s*/g, '\n').replace(/\n/g,
'').replace(/\r/g, '');
return(html);
}

// handles browser entities to UTF-8 encoding
function html_entities(html) {
function html_entities(html) {
html = html.replace(/&nbsp;/g, '&#160;').replace(/&quot;/g,
'&#34;').replace(/&amp;/g, '&#38;').replace(/&lt;/g, '&#60;').replace(
return(html);
}

// handles IE innerHTML tags without "" around attributes and NOT ending
with >
function html_attributes1(tag) {
if (attributes = tag.match(/(=[^"= >\r\n]* )/gi)) {
for (var i = 0; i < attributes.length; i++) {
attribute = attributes[i];
newattribute = attribute.replace(/=/, '="');
newattribute = newattribute.replace(/ /, '" ');
tag = tag.replace(new RegExp(attribute, 'g'), newattribute);

}
}
return tag;
}

// handles IE innerHTML tags without "" around attributes and ending with
function html_attributes2(tag) {
if (attributes = tag.match(/(=[^"= >\r\n]*>)/gi)) {
for (var i = 0; i < attributes.length; i++) {
attribute = attributes[i];
newattribute = attribute.replace(/=/, '="');
newattribute = newattribute.replace(/>/, '">');
tag = tag.replace(new RegExp(attribute, 'g'), newattribute);
}
}
return tag;
}
Henrik Rützou
HR Software Development
Ved Stampedammen 39
DK 2970 Hørsholm
Denmark
E-mail: hr@xxxxxxxxxxxx
Phone: +45 2714 8449

Homepage




"Lowary, Jim" <jlowary@xxxxxxxx>
Sent by: rpg400-l-bounces@xxxxxxxxxxxx
16-02-2010 20:14
Please respond to
RPG programming on the IBM i / System i <rpg400-l@xxxxxxxxxxxx>


To
<rpg400-l@xxxxxxxxxxxx>
cc

Subject
Re: Replace 1 Char with 3Char's






Terry,

Not a problem I actually had the day off myself, so I'm just catching
up. I'm sorry this has turned into such a long discussion and hope it
has not wasted to much of anyone's time.

I finally just read the input IFS file (one char at a time) and replace
the "<" with the "crlf + <". Yes it is not the best, but it is no worse
than the Delphi program has been in place for about 4 years. If I was
given the time and go ahead I would replace this whole job stream with
something more XML friendly in design, but such is life.

...

On the "sed" command running from 'QSH CMD()', would anyone know how
would I set the CCSID to be something other than default I get from
executing this command in RPG via QCMDEXC or is there a way?

I played around with it some interactively and figured out I could run
the command "QSH" and then at its command line do a QIBM_CCSID = 819
and change the CCSID for that execution. But if I tried to do 'QSH
CMD(QIBM_CCSID = 819)' It didn't like that at all.

I would think there would be a way to change the "QSH" default CCSID for
just this job. Since I'm not Unix savvy and this is where the two
worlds tend to bluer together, I couldn't find it. If I could have set
the right CCSID I might have been able to get "sed" to work well enough
for what I needed anyway.

Thanks for all the suggestions, and to everyone else for putting up
saga.

-- Jim
------------------------------

message: 8
date: Tue, 16 Feb 2010 10:15:09 -0500
from: Terrence Enger <tenger@xxxxxxxxxxxxxxxx>
subject: Re: Replace 1 Char with 3Char's

The sheer length of this thread reinforces my preexisting prejudice in
favour of "contracting out" any XML parsing to a tool designed for the
job. I wonder, Jim, if producing your desired output from a parsed
representation of the input would be any more work than the effort you
have already spent on adhocery? And then, which strategy would give you
more confidence in the result?

(Yesterday was a holiday in Canada. Feel free to attribute this message
to the moral equivalent of Monday-morning grumpiness :)

Cheers,
Terry.

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.