How validate HTML using PL/SQL

Hi,
I try validate HTML using PL/SQL that user inputs.
I did create below function for that purpose
CREATE OR REPLACE
FUNCTION validate_html(
  p_html IN VARCHAR2
) RETURN BOOLEAN
AS
  l_comment  XMLTYPE;
  xml_parse_err EXCEPTION;
  PRAGMA EXCEPTION_INIT (xml_parse_err , -31011);
BEGIN
  l_comment := xmlType.createXML('<root><row>' || p_html || '</row></root>');
  RETURN TRUE;
EXCEPTION WHEN xml_parse_err THEN
  RETURN FALSE;
END;
Function works ok and return true if I run e.g.
BEGIN
  IF validate_html('<p>Hello</p>') THEN
    dbms_output.put_line('OK');
  ELSE
    dbms_output.put_line('Not valid HTML');
  END IF;
END;
And return false if I enter not valid HTML like
BEGIN
  IF validate_html('<p>Hello') THEN
    dbms_output.put_line('OK');
  ELSE
    dbms_output.put_line('Not valid HTML');
  END IF;
END;
But it return false also if I run below
BEGIN
  IF validate_html('<p>Hello &nbsp</p>') THEN
    dbms_output.put_line('OK');
  ELSE
    dbms_output.put_line('Not valid HTML');
  END IF;
END;
Problem seems to be that &nbsp (there is ; in end but do not know how post it without forum convert that to space) witch is valid HTML for me.
I know that HTML is not XML, but can I use Oracle database XML functions for validating HTML?
How I should validate user inputted HTML?
I'm currently developing this using Oracle XE 11G database.
Regards,
Jari

Not an elegant way:
But try this.........
CREATE OR REPLACE FUNCTION validate_html (p_html IN VARCHAR2)
   RETURN BOOLEAN AS
   l_comment       XMLTYPE;
   xml_parse_err   EXCEPTION;
   PRAGMA EXCEPTION_INIT (xml_parse_err, -31011);
BEGIN
   l_comment :=
      xmlType.createXML (
         '<root><row>'
         || CASE
               WHEN INSTR (p_html, '&') > 0 THEN
                  UTL_I18N.escape_reference (p_html)
               ELSE
                  p_html
            END
         || '</row></root>');
   RETURN TRUE;
EXCEPTION
   WHEN xml_parse_err THEN
      RETURN FALSE;
END;
SET DEFINE OFF
SET SERVEROUTPUT ON
BEGIN
   IF validate_html ('<p>Hello') THEN
      DBMS_OUTPUT.put_line ('OK');
   ELSE
      DBMS_OUTPUT.put_line ('Not valid HTML');
   END IF;
END;
SET DEFINE OFF
SET SERVEROUTPUT ON
BEGIN
   IF validate_html ('<p>Hello &nbsp</p>') THEN
      DBMS_OUTPUT.put_line ('OK');
   ELSE
      DBMS_OUTPUT.put_line ('Not valid HTML');
   END IF;
END;
Cheers,
Manik.

Similar Messages

  • How can i use one SQL statement to solve problem?

    How can i use one SQL statement to solve the question below?
    For a Table named A, there is a column named F(char type).
    Now select all the records where F like '%00' and update their F value to '%01'
    Just one SQL statement.Do not use PL/SQL block.
    How to do that?
    Thanks.

    What is the data volume for this table?
    Do you expect lots of rows to have '%00' as their value?
    Following two statements come to mind. Other experts would be able to provide better alternatives:
    If you have index on SUBSTR(f, 2):
    UPDATE A
    SET    f = SUBSTR(f,
                      1,
                      length(f) - 2) || '01'
    WHERE  substr(f,
                  -2) = '00';If most of the rows have pattern '%00':
    UPDATE A
    SET    f = SUBSTR(f,
                      1,
                      length(f) - 2) ||
               DECODE(SUBSTR(f,
                             -2),
                      '00',
                      '01',
                      SUBSTR(f,
                             -2));

  • How do i use PL/SQL function in filter operator

    Hi,
    i want to use one pl/sql function in filter operator. how do i use it in filter condition.
    error i am getting is
    " error occured during expression validatation.
    my filter condition is
    INOUTGRP1.LAST_UPDATE_DATE > "GET_LAST_UPDATE_DATE"()
    can any one suggest me what is the problem for this error.
    Regards,
    Jyothy

    I tried and getting the same error. don't know why!!
    However, There is another way of accomplishing it.
    You can add a "Mapping Input Parameter" to your mapping and in the default value field call the function "Get_Last_Update_date". Then add the output field from this operator to the filter operator. Then edit the filter condition to replace the function call with output value from the Input parameter operator.
    This should work...

  • How can I use PL/SQL in Merosoft VC++ 6.0??

    I'm a fresher.Would you tell me how to use PL/SQL in MS VC++6.0? How set erviroment of VC++?
    Thans in advanced!!

    I guess that you are refering how to call program units
    from VC++6.0 . That is very easy. It depends on what
    data access object you are using.
    If you are using ADO 2.7 you can call Stored Procedures
    with a COMMAND OBJECT :
    dim obj_com as ADODB.COMMAND
    This information can be useful for you:
    Contents
    Introducing Oracle Objects for OLE
    Overview of Oracle Objects for OLE
    About the OO4O Automation Server
    About Oracle Data Control
    About Oracle Objects for OLE C++ Class Library
    New Features of Oracle Objects for OLE
    Tips and Techniques for Performance Tuning
    Requirements
    Required Setups
    OO4O Redistributable Files
    Demonstration Schema and Code Examples
    Getting Started with the OO4O Automation Server
    Basics of Client Applications
    Accessing the OO4O Automation Server
    Connecting to the Oracle Database
    Detection of Lost Connections
    Automation Objects
    PL/SQL Support
    Executing Commands
    Asynchronous Processing
    XML Data Interchange
    Initializing Oracle LOBs, Objects, and Collections
    Large Objects (LOBs)
    Oracle Object Datatypes
    Oracle Collections
    Advanced Queueing Interfaces
    Database Schema Objects
    Application Failover Notifications
    Database Events
    Using OO4O with Automation Clients
    Overview
    With Visual Basic
    With Excel
    With Active Server Pages (ASP)
    Oracle Data Control with Visual Basic
    Oracle Data Control with MS VC++
    OO4O Code Wizard for Stored Procedures
    About the Code Wizard
    Supported Datatypes
    Using the OO4O Code Wizard
    Code Wizard Examples
    OO4O Automation Server Reference
    Objects
    Methods
    Properties
    Oracle Data Control Reference
    Events
    Methods
    Properties
    Troubleshooting
    Error Handling
    Troubleshooting
    http://download-west.oracle.com/docs/cd/B10501_01/win.920/a95895/toc.htm
    Joel P�rez

  • How do you use PL/SQL to update a view?

    Hi there, I know how to use SQL to create and update a view. I am using it to pull data for a specific date.
    But now I want to find a way to parametized it (ie. the date) so that it can be run like a program each day (based on system date) to pull the latest data. I am thinking of using PL/SQL but not sure how it can be done.
    DECLARE
    run_date DATE := '10/12/2009';
    BEGIN
    END
    Can someone shed some light on how I can update a view? Thanks alot.

    Try this
    DECLARE
    run_date DATE := '10/12/2009';
    BEGIN
    execute imeediate 'create view view_name as select * from dual';
    END

  • How can I use the SQL to create a primary key for a existing table?

    create table a(bm number,mc varchar2(20));
    when the table was created,i want to make the column bm as
    the primary key and my SQL is "alter table a enable primary key bm",the system show
    me error,how can I write the right one?

    create table a(bm number,mc varchar2(20));
    when the table was created,i want to make the column bm as
    the primary key and my SQL is "alter table a enable primary key bm",the system show
    me error,how can I write the right one? You do not have any primary key defined on your table yet, so, it does not make sense to enable it (if at all possible) !
    You need to add PRIMARY KEY using something like this:
    SQL> alter table a add constraint pk_a_bm primary key (bm) ;

  • How many people use the SQL Resource Governor?

    (Timely Walking Dead joke ahead.)For those of you new DBAs, the SQL Server Resource Governor was released along with SQL Server 2008 as a feature to manage your workload and system resource consumption. With Resource Governor, you can throttle allocating resources to the CPU, Memory, and IOPs appropriately, and free up resources based on importance of the application or the user. Resource Governor also allows DBAs to limit any runaway queries and throttle I/O resources that negatively impact workloads.But of course, there are always going to be limitations to any great tool.For example, resource management is limited to the SQL Server Database Engine, andcan't be used for Analysis Services, Integration Services, and Reporting Services. And there isn't any workload monitoring or workload management between SQL Server instances.This...
    This topic first appeared in the Spiceworks Community

    (Timely Walking Dead joke ahead.)For those of you new DBAs, the SQL Server Resource Governor was released along with SQL Server 2008 as a feature to manage your workload and system resource consumption. With Resource Governor, you can throttle allocating resources to the CPU, Memory, and IOPs appropriately, and free up resources based on importance of the application or the user. Resource Governor also allows DBAs to limit any runaway queries and throttle I/O resources that negatively impact workloads.But of course, there are always going to be limitations to any great tool.For example, resource management is limited to the SQL Server Database Engine, andcan't be used for Analysis Services, Integration Services, and Reporting Services. And there isn't any workload monitoring or workload management between SQL Server instances.This...

  • Using pl/sql to access non-apex HTML items on page

    how would i use pl/sql to access html items on a page. the items are not apex items.
    i want to loop through a set of html items on the page and do a database update on these values. the method i am using to distinguish these items from others on the page is using a custom attribute of type. i am then going to use the id as the primary key for the database.
    using javascript i can traverse through all items however i require to do it in pl/sql. i realise that i could use javascript to put all values in one apex hidden field but this would be sloppy and i want to avoid doing this.

    Hello,
    When a form submits the server never sees any custom attributes one way or the other, (this in any web environment) all anything on the server side will ever see is the value of the form item submitted. The only way to do what you want is to use javascript to collect the extra information and place it in a form item visible to APEX (a regular APEX Item).
    The javascript route isn't a work around its the only way this will work the way you want. In the product itself we use custom attributes in an htmldb: namespace so the attribute does looks like htmldb:something="value", (you should make your own namespace don't use htmldb:)
    I recommend using the namespace on your attributes instead of just shoving it in there as it will be closer to valid html or xhtml, it will still fail validation but at least you have the argument that "Hey xhtml is xml and xml allows for custom namespaces and custom attributes for that namespace so it's still good xml" not that I've ever used the argument or anything.
    Carl
    Message was edited by:
    Carl Backstrom

  • How to use PL/SQL table

    Hi all,
    can you guys suggest me how can I use pl/sql tables for the below query to incresing the performance.
    DECLARE
        TYPE cur_typ IS REF CURSOR;
        c           cur_typ;
        total_val varchar2(1000);
        sql_stmt varchar2(1000);
        freeform_name NUMBER;
        freeform_id NUMBER;
        imgname_rec EMC_FTW_PREVA.EMC_Image_C_Mungo%rowtype;
        imgval_rec  EMC_FTW_PREVA.EMC_Content_C_Mungo%rowtype;
        CURSOR imgname_cur IS
            select * from EMC_FTW_PREVA.EMC_Image_C_Mungo
            where cs_ownerid in (
                        select id from EMC_FTW_PREVA.EMC_Image_C
                        where updateddate > '01-JUN-13'
                        and path is not null
                        and createddate != updateddate)
            and cs_attrid = (select id from EMC_FTW_PREVA.EMC_ATTRIBUTE where name = 'Image_Upload');
    BEGIN
        OPEN imgname_cur;
        LOOP
          FETCH imgname_cur INTO imgname_rec;
          EXIT WHEN imgname_cur%NOTFOUND;
          total_val := 'EMC_Image_C_' || imgname_rec.cs_ownerid;
          sql_stmt := 'SELECT instr(textvalue,''' || total_val || '''), cs_ownerid FROM EMC_FTW_PREVA.EMC_Content_C_Mungo a Where cs_attrid = (select id from EMC_FTW_PREVA.EMC_ATTRIBUTE where name = ' || '''' || 'Body_freeform' || '''' || ')';
            OPEN c FOR sql_stmt;
            LOOP
              FETCH c INTO freeform_id,freeform_name;
              EXIT WHEN c%NOTFOUND;
                                      IF freeform_id > 0 THEN
                dbms_output.put_line (imgname_rec.cs_ownerid || ',' || total_val || ',' || freeform_id || ',' || freeform_name);
                                      END IF;
            END LOOP;
            CLOSE c;     
       END LOOP;
       CLOSE imgname_cur;
    END;
    Thanks in Advance.

    can you guys suggest me how can I use pl/sql tables for the below query to incresing the performance.
    There would be absolutely no point at all in improving the performance of code that has NO benefit.
    The only result of executing that code is to possibly produce some lines of output AFTER the entire procedure if finished:
    dbms_output.put_line (imgname_rec.cs_ownerid || ',' || total_val || ',' || freeform_id || ',' || freeform_name);
    So first you need to explain:
    1. what PROBLEM you are trying to solve?
    2. why you are trying to use PL/SQL code to solve it.
    3. why are you using 'slow by slow' (row by row) processing and then, for each row, opening a new cursor to query more data?
    You should be using a single query rather than two nested cursors. But that begs the question of what the code is even supposed to be doing since the only output is going to a memory buffer.

  • How to use Native SQL String

    Hi all,
    How do i use Native SQL String in the Reciver JDBC Adapter.
    Do i need to change the message format could u suggest me some blogs on the same.
    Also please can anyone let me knw if i can use this for stored procedure.

    hi aditya,
    there shud be no format as such. for sql xml format there are specific structure. but for native sql there shudnt be any specific structure.
    as pointed in sap documentaion:
    Instead of an XML document format, a text is expected that represents any valid SQL statement.
    When inserting a line into a table the corresponding document looks as follows:
    INSERT INTO tableName  (column-name1, column-name2, column-name3) VALUES(‘column-value1’, ‘column-value2’, ‘column-value3’)
    so jus make sure that u give a valid sql statement becoz if will be passed as it is to the database and try ur scenario.
    regards,
    latika.

  • How to find using SQL query application deployed on win 7 machines with SCCM 2012 server or user installed manually.

    Hi,
    how to find using SCCM SQL query,  application deployed on win 7 machines with SCCM 2012 server or user/technician installed manually. Please let me know.

    Thanks, is it not possible via any script also?
    Like Torsten said, how can you tell the difference between CM12 installed applications and locally installed? Once you can answer that, then you can write report.
    Garth Jones | My blogs: Enhansoft and
    Old Blog site | Twitter:
    @GarthMJ

  • Optimizing an SQL Query using Oracle SQL Developer

    Hi ,
    Currently i am using Oracle SQL Developer as my Database IDE .
    Is it possible to use Orqcles SQLDeveloper for the purpose of Optimizing an SQL Query ??
    For example assume i am having a query as :
    Select from Tranac_Master where CUST_STATAUS='Y' and JCC_REPORT='N'*
    Could anybody please tell me how can i use Oracle SQL Developer to optimize this query or any other SQL queries ??
    Please share your ideas , thanks in advance .

    1. Your query looks very simplistic as it is, so I fail to see how you can better optimise it (unless 'Tranac_Master' is a view, in which case I'd need to see the view details).
    2. No tool can automagically optimise your SQL to any degree of practical use. Very minor adjustments may be possible automatically, but really it is a question of you knowing your data & database design accurately, and then you applying your expert knowledge to tune it.

  • Using pl/sql functions for transformation

    How can I use pl/sql functions in the transformation mapping field for my interface?
    I have a name field where firstname and lastname are concatenated via a space-character and I would like to extract this 'name' field to 2 separate database attributes.
    This means that I need to use a function that uses SUBSTRING and INSTR to be able to get the firstname and lastname separatly out of the name-field.
    The INSTR-function isn't known inside the expression editor in ODI so I'm wondering how I can use my own function?

    Hi Romanna,
    Are you sure? Where did you do your transformation?
    -Source, Staging area or Target
    I try this on Oracle target...
    FIRST_NAME = substr(MYTABLE.FIRST_LASTNAME, 1, instr(MYTABLE.FIRST_LASTNAME, ' ')-1)
    LAST_NAME = substr(MYTABLE.FIRST_LASTNAME,instr(MYTABLE.FIRST_LASTNAME, ' ')+1)

  • Insertion / Update of field of type "TIME" using Native SQL

    Hi ABAP gurus,
    We are trying to perform inserts and updates within an ORACLE table where a TIME field exists without suscess. We are trying to code it using Native SQL.
    EXEC SQL.
    INSERT INTO table (field1[name], field2[age], field3[birthday], field4[hour])
    VALUES (:name, :age, TO_DATE(:date_birth), ¿:hour?)
    ENDEXEC.
    EXEC SQL.
    UPDATE table SET field3[birthday] = TO_DATE(:date_birth), field4[hour] = ¿:hour?
    WHERE field1[name] = :name AND field2[age] = :age
    ENDEXEC.
    Which is the right coding sentence in order to achieve our goal?
    Many thanks in advance. Best regards,
       Imanol

    >
    Imanol Beguiristain wrote:
    > Hi all,
    >
    > I am sorry for being unclear.
    >
    > I do want to code both INSERT and UPDATE. That is clear.
    >
    > The problem we are having is that we don't know how to code (using Native SQL) such instructions using in the SQL sentence a field of TIME type.
    >
    > Any helps?
    >
    > Thanks in advance.
    >
    >   Imanol
    I've not heard of an Oracle TIME datatype; we used to use the timestamp which is stored as part of the date or we set up a separate column to hold the time defined as CHAR.  Still, it is possible that they have created such a thing since I last did SQL.  In which case, there would have to be a function like TO_DATE which you would use to convert your time to its time format.
    If you mean TIMESTAMP you can use something like the following to do the data conversion.
    TO_TIMESTAMP(LOCALTIMESTAMP, 'DD-MON-RR HH.MI.SSXFF')

  • How to create dynamic HTML page using PL/SQL code in APEX.

    hello,
    I am woking on one APEX application in which i want to create one dynamic HTML page on button press using PL/SQL code.
    Thanks

    It is possible to create HTML page with dynamic content. One way would be creating hidden field (e.g. P1_HTML on page 1) with dynamic HTML and on button click you redirect to page 2 and pass P1_HTML item value to item P2_HTML on page 2. On page you must have PL/SQL region. You can then render your dynamic HTML with code:
    htp.p(:P2_HTML);
    Don use APEX URL for passing HTML value. Problem and solution is described here: http://blog.trent-schafer.com/2011/04/03/dont-pass-string-parameters-in-the-url-in-apex-its-a-bad-idea/
    Edited by: MiroMas on 3.2.2012 3:20

Maybe you are looking for