Helps the Parseing XML

Version: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production

Hello

I need assistance with an XML file to generate lines to insert into a table staged for further processing.

There is an XML document that is loaded into a table in the database via a Web Service call.

I need to query this table to get the XML code, loop through it to create folders, with the fields in a specific order and insert records into a table of staging.

There are two columns that are not in the XML that are added during the process. I am including these tables as well.

I know it is a bunch of "stuff", but I hope I've provided enough information to get help.

The tables and insert queries:

-This table contains the XML of the Web Service call

CREATE TABLE exam_results
(
CLOB results_clob
);

INSERT INTO exam_results (results_clob)
VALUES
("< result > < candidate > < ProgramCandidateID > 911221 < / ProgramCandidateID > < LastName > V361208 < / LastName > < FirstName > J361208 < / FirstName > < / candidate > < event > < ended > 1 < / filled > < CompleteDate > 2011 - 08 - 05T 10: 23:42.957 < / CompleteDate > < FormName > SSU11-05 < / FormName > < NumStarts > 2 < / NumStarts > < ProgramRegistrationID > SU0006510JV < / ProgramRegistrationID > < result > 564865 identifier < / result identifier >") < Sponsor > MySponsor < / sponsor > < StartTime > 2011 - 08 - 05T 08: 22:47.877 < / StartTime > < TestName > SSU11 < / TestName > < / Event > < start > < Start > < BrowserVersion > 8.0 < / BrowserVersion > < OperatingSystem > Windows NT 4.0 < / OperatingSystem > < / Start > < / begins > < Scores > < issues > < > < name > 105103 < / name > < SeqDelivered > 1 < / SeqDelivered > < response > 1 < / response > < key > 4 < / key > < seconds > 169.126 < / seconds > < Section > 1 < / Section > < / Question > < Question > < name > 261292 < / name > < SeqDelivered > 2 < / SeqDelivered > < answer > 3 < / response > < key > 3 < / key > < seconds > 97.984 < / seconds > < Section > 1 < / Section > < / Question > < Question > < name > 261241 < / name > < SeqDelivered > 3 < / SeqDelivered > < response > 3 < / response > < key > 3 < / key > < seconds > 87.579 < / seconds > < Section > 1 < / Section > < / Question > < Question > < name > 261451 < / name > < SeqDelivered > 4 < / SeqDelivered > < answer > 3 < / response > < key > 3 < / key > < seconds > 59.983 < / seconds (> < Section > 1 < / section > < / Question > < Question > < name > 264373 < / name > < SeqDelivered > 5 < / SeqDelivered > < response > 5 < / response > < key > 1 < / key > < seconds > 86.346 < / seconds > < Section > 1 < / Section > < / Question > < / Questions > < / Scores > < / result > ');

-This table is to get 1 of the additional columns that must be included

CREATE TABLE tracking_id_tbl
(
tracking_id NUMBER,
customer_id NUMBER,
launch_code VARCHAR2 (11)
);

INSERT INTO tracking_id_tbl (tracking_id, customer_id, launch_code)

VALUES (557,2296267, 'SU0006510JV');

-This table is to get the other extra column which must be included

CREATE TABLE school_code_tbl
(
customer_id NUMBER,
nb_id NUMBER,
organization_id VARCHAR2 (8)
);

INSERT INTO school_code_tbl (customer_id, nb_id, organization_id)

VALUES (2296267,911221, '12');

-This table will receive the file created from the XML

CREATE TABLE staging_tbl
(
results_data VARCHAR2 (4000)
);

To facilitate the XML file to read (we hope) here is a formatted version:

< result >

< candidate >

< ProgramCandidateID > 911221 < / ProgramCandidateID >

< name > V361208 < / LastName >

J361208 < FirstName > < / name >

< / candidate >

< event >

< finish > 1 < / completed >

< completeDate > 2011 - 08 - 05T 10: 23:42.957 < / CompleteDate >

SSU11-05 < FormName > < / FormName >

< NumStarts > 2 < / NumStarts >

< ProgramRegistrationID > SU0006510JV < / ProgramRegistrationID >

ID of < result > 564865 < / ID results >

< sponsor > MySponsor < / sponsor >

< StartTime > 2011 - 08 - 05T 08: 22:47.877 < / StartTime >

SSU11 < TestName > < / TestName >

< / event >

< start >

< start >

< > 8.0 BrowserVersion < / BrowserVersion >

< OperatingSystem > Windows NT 4.0 < / OperatingSystem >

< / start >

< / starts >

< scores >

< questions >

< question >

< name > 105103 < / name >

< SeqDelivered > 1 < / SeqDelivered >

< response > 1 < / answer >

< Key > 4 < / key >

< seconds > 169.126 < / seconds >

article <>1 < / Section >

< / question >

< question >

< name > 261292 < / name >

< SeqDelivered > 2 < / SeqDelivered >

< response > 3 < / answer >

< Key > 3 < / key >

< seconds > 97.984 < / seconds >

article <>1 < / Section >

< / question >

< question >

< name > 261241 < / name >

< SeqDelivered > 3 < / SeqDelivered >

< response > 3 < / answer >

< Key > 3 < / key >

< seconds > 87.579 < / seconds >

article <>1 < / Section >

< / question >

< question >

< name > 261451 < / name >

< SeqDelivered > 4 < / SeqDelivered >

< response > 3 < / answer >

< Key > 3 < / key >

< seconds > 59.983 < / seconds >

article <>1 < / Section >

< / question >

< question >

< name > 264373 < / name >

< SeqDelivered > 5 < / SeqDelivered >

< response > 5 < / answer >

< Key > 1 < / key >

< seconds > 86.346 < / seconds >

article <>1 < / Section >

< / question >

< / questions >

< / scores >

< / result >

This XML file is for 1 card. There are several issues that are in the file. I reduced to only 5 is easier to see.

The layout of the document to be inserted in the staging table is:

Event.TestName

Event.FormName

Event.CompleteDate

v_tracking_id

Event.ProgramRegistrationID

Event.StartTime

Event.CompleteDate / * end * /.

Candidate.LastName

Candidate.FirstName

Candidate.MiddleName (the middle name does not exist in the file XML then return null)

Candidate.ProgramCandidateID

v_school_code

Candidate.CustomProperties.Answer (this does not exist in the file XML then return null)

Event.ResultID

Event.NumStarts

Event.Completed

Event.Sponsor

Scores.Questions.Question.Name

Scores.Questions.Question.Section

Scores.Questions.Question.SeqDelivered

Scores.Questions.Question.Key

Scores.Questions.Question.Answer

Scores.Questions.Question.Seconds

Starts.OperatingSystem

Starts.BrowserVersion

The expected output is:

INSERT INTO staging_tbl (results_data)
VALUES ('SSU11,SSU11-05,08/05/2011,557,SU0006510JV,08:22:47,10:23:42,V361208,J361208,,911221,12,,564865,2,1,MySponsor,105103,1,1,4,1,169.126,Windows NT 4.0,8.0");

INSERT INTO staging_tbl (results_data)
VALUES ('SSU11,SSU11-05,08/05/2011,557,SU0006510JV,08:22:47,10:23:42,V361208,J361208,,911221,12,,564865,2,1,MySponsor,261292,1,2,3,3,97.984,Windows NT 4.0,8.0");

INSERT INTO staging_tbl (results_data)
VALUES ('SSU11,SSU11-05,08/05/2011,557,SU0006510JV,08:22:47,10:23:42,V361208,J361208,,911221,12,,564865,2,1,MySponsor,261241,1,3,3,3,87.579,Windows NT 4.0,8.0");

INSERT INTO staging_tbl (results_data)
VALUES ('SSU11,SSU11-05,08/05/2011,557,SU0006510JV,08:22:47,10:23:42,V361208,J361208,,911221,12,,564865,2,1,MySponsor,261451,1,4,3,3,59.983,Windows NT 4.0,8.0");

INSERT INTO staging_tbl (results_data)
VALUES ('SSU11,SSU11-05,08/05/2011,557,SU0006510JV,08:22:47,10:23:42,V361208,J361208,,911221,12,,564865,2,1,MySponsor,264373,1,5,1,5,86.346,Windows NT 4.0,8.0");

The Questions/Question, is what makes a separate line if the values for the other fields would be the same for however many questions is in the XML file.

That's what I've tried so far:

DECLARE                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             CURSOR get_results_cur
IS
SELECT results_clob
Of exam_results;

get_results_rec XMLTYPE.
get_results_clob CLOB.
NUMBER (38) v_count: = 1;


v_result VARCHAR2 (32000);
v_tracking_id tracking_id.tracking_id_tbl%TYPE;
v_school_code organization_id.school_code_tbl%TYPE;

BEGIN
OPEN get_results_cur.
SEEK get_results_cur INTO get_results_clob;
CLOSE Get_results_cur;

get_results_rec: = xmltype.createxml (get_results_clob);

SELECT tracking_id
school_code
IN v_tracking_id
v_school_code
OF ti tracking_id_tbl
JOIN school_code_tbl ON ti.customer_id = sc.customer_id sc
WHERE ti.launch_code = get_results_rec. EXTRACT ('/ Result/Event/ProgramRegistrationID/text()').getstringval () AND)
nb_id = get_results_rec. EXTRACT ('/ Result/Candidate/ProgramCandidateID/text()').getstringval ();)

While get_results_rec. EXISTSNODE ('/ / result [' | v_count |]) ']') = 1
LOOP
v_result: =.
(get_results_rec. EXTRACT ('/ results/event/TestName [' | v_count | / text () ']) .getstringval ())
|| ','
|| (get_results_rec. EXTRACT ('/ results/event/FormName [' | v_count | / text () ']) .getstringval ())
|| ','
|| ((get_results_rec. EXTRAIT ('/ résultats/événement/CompleteDate [' || v_count || / text () SUBSTR']) .getstringval ()), 1, 10)
|| ','
|| v_tracking_id
|| ','
|| (get_results_rec. EXTRACT ('/ results/event/ProgramRegistrationID [' | v_count | / text () ']) .getstringval ())
|| ','
|| ((get_results_rec. EXTRAIT ('/ résultats/événement/StartTime [' || v_count || / text () SUBSTR']) .getstringval ()), 12.8)
|| ','
|| ((get_results_rec. EXTRAIT ('/ résultats/événement/CompleteDate [' || v_count || / text () SUBSTR']) .getstringval ()), 12.8)
|| ','
|| (get_results_rec. EXTRACT ('/ result/candidate/name [' | v_count | / text () ']) .getstringval ())
|| ','
|| (get_results_rec. EXTRACT ('/ result/candidate/name [' | v_count | / text () ']) .getstringval ())
|| ',,'
|| -(get_results_rec. Extract('/result/candidate/MiddleName [' || v_count ||) '] / text () ') .getStringVal ()); ',' ||
(get_results_rec. EXTRACT ('/ result/candidate/ProgramCandidateID [' | v_count | / text () ']) .getstringval ())
|| ','
|| v_school_code
|| ','
|| (get_results_rec. EXTRACT ('/ results/event/result identifier [' | v_count | / text () ']) .getstringval ())
|| ','
|| (get_results_rec. EXTRACT ('/ results/event/NumStarts [' | v_count | / text () ']) .getstringval ())
|| ','
|| (get_results_rec. EXTRACT ('/ results/event/completed [' | v_count | / text () ']) .getstringval ())
|| ','
|| (get_results_rec. EXTRACT ('/ results/event/sponsor [' | v_count | / text () ']) .getstringval ());
|| ','

-Add the results of the first question

|| ','
|| (get_results_rec. EXTRACT ('/ result, departures, Start, OperatingSystem [' | v_count | / text () ']) .getstringval ())
|| ','
|| (get_results_rec. EXTRACT ('/ result, departures, Start, BrowserVersion [' | v_count | / text () ']) .getstringval ());

v_count: = v_count + 1;

INSERT INTO staging_tbl (results_data)
VALUES (v_result);

END LOOP;
END;

What can clear?

Thank you

Joe

You have several questions in the XML, so when flattened document you will have several lines trying to extract in v_result.  Where the error.  You will need to either loop

for rec in (select... from XMLTable...)

loop

insert into staging_tbl...

end loop;

or make an insert select

insert into staging_tbl (results_data)

Select...

from XMLTable...

Tags: Database

Similar Questions

  • Help Ned parsing XML

    I have a XML result that will come back with aliases. I am analyzing these data and put each item in a data base. An example of the XML Structure is attached. I use the function ARRAYLEN to count the child elements, but which generates an error. How can I get a specific element < ALIAS > account in this XML file so I now how long to go through all of the elements?

    Thank you

    It worked.

    Thank you

  • Parsing XML and get the attributes of a tag

    Hello

    When parsing XML for application of Cascades in C++, I am able to get the value of a tag as follows:

    00000

    But I also want to get the attributes of a tag:

    But I don't know how to get the 'CA' and 'California' attributes with my current code.  Can anyone help?  Here is the code I use to parse the XML code:

    void CMController::requestFinished(QNetworkReply* reply) {
    
        if (reply->error() == QNetworkReply::NoError) {
    
            QXmlStreamReader xml;
    
            QByteArray data = reply->readAll();
            xml.addData(data);
    
            QString zip;
            QString id;
            QString location;
    
            while (!xml.atEnd() && !xml.hasError()) {
    
                /* Read next element.*/
                QXmlStreamReader::TokenType token = xml.readNext();
    
                /* If token is just StartDocument, we'll go to next.*/
                if (token == QXmlStreamReader::StartDocument) {
                    continue;
                }
    
                /* If token is StartElement, we'll see if we can read it.*/
                if (token == QXmlStreamReader::StartElement) {
    
                    if (xml.name() == "zip") {
                        zip = xml.readElementText();
                    }
    
                    if (xml.name() == "id") {
                        ???
                    }
    
                    if (xml.name() == "location") {
                        ???
                    }
    
                }
    
            }
    
            emit succeeded(result);
    
        } else {
            emit failed();
        }
    
        reply->deleteLater();
    
    }
    

    Thank you!

    I found a working example:

    if(xml.name() == "state"){
        QXmlStreamAttributes attrib = xml.attributes();
        QStringRef ref = attrib.value("location");
        qDebug() << "location: " << ref;
    }
    
  • Help parsing XML (XMLParseDemo.java)

    Hello world

    I'm trying to parse the XML code in my application. Here's a sample of what I'm trying to analyze:

    
    
      http://api.netflix.com/catalog/titles/autocomplete?{-join|&|term}
      
        
      
      
        
      
      
        
      
      
        
      
    
    

    For the parser, I use the XMLDemoScreen.java that is provided in the JDE samples. What I'm trying to do is to analyze all of theitem. However, when I run the application, my output is as follows:<p class="help"> <pre> autocomplete url_template = <a href="http://api.netflix.com/catalog/titles/autocomplete?{-join" rel="external nofollow noreferrer">http://api.netflix.com/catalog/titles/autocomplete?{-join</a>|&|term}" autocomplete_item title autocomplete_item title autocomplete_item title autocomplete_item title </pre> <p class="help">So, that's the impression not the values of "title". Anyone know why? Is it because the element contains<title short="">?<p class="help"> <p class="help">Thanks for your help. Here is the code that I use (which can be found in the JDE samples):</p> <pre> /* * XMLDemoScreen.java * * Copyright © 1998-2009 Research In Motion Ltd. * * Note: For the sake of simplicity, this sample application may not leverage * resource bundles and resource strings. However, it is STRONGLY recommended * that application developers make use of the localization features available * within the BlackBerry development platform to ensure a seamless application * experience across a variety of languages and geographies. For more information * on localizing your application, please refer to the BlackBerry Java Development * Environment Development Guide associated with this release. */ package com.kflicks.xml; import java.io.InputStream; import net.rim.device.api.ui.component.*; import net.rim.device.api.ui.container.MainScreen; import net.rim.device.api.xml.parsers.*; import org.w3c.dom.*; /** * The main screen for the application. Displays the results of parsing the XML * file. */ /* package */public final class XMLDemoScreen extends MainScreen { // Constants // ----------------------------------------------------------------------------------- private static final int _tab = 4; InputStream input; /** * This constructor parses the XML file into a W3C DOM document, and * displays it on the screen. * * @see Document * @see DocumentBuilder * @see DocumentBuilderFactory */ public XMLDemoScreen(InputStream input) { setTitle(new LabelField("XML Demo")); this.input = input; try { // Build a document based on the XML file. DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(input); // Normalize the root element of the XML document. This ensures that // all Text // nodes under the root node are put into a "normal" form, which // means that // there are neither adjacent Text nodes nor empty Text nodes in the // document. // See Node.normalize(). Element rootElement = document.getDocumentElement(); rootElement.normalize(); // Display the root node and all its descendant nodes, which covers // the entire // document. displayNode(rootElement, 0); } catch (Exception e) { System.out.println(e.toString()); } } /** * Displays a node at a specified depth, as well as all its descendants. * * @param node * The node to display. * @param depth * The depth of this node in the document tree. */ private void displayNode(Node node, int depth) { // Because we can inspect the XML file, we know that it contains only // XML elements // and text, so this algorithm is written specifically to handle these // cases. // A real-world application will be more robust, and will handle all // node types. // See the entire list in org.w3c.dom.Node. // The XML file is laid out such that each Element node will either have // one Text // node child (e.g. <Element>Text</Element>), or >= 1 children // consisting of at // least one Element node, and possibly some Text nodes. Start by // figuring out // what kind of node we're dealing with. if (node.getNodeType() == Node.ELEMENT_NODE) { StringBuffer buffer = new StringBuffer(); indentStringBuffer(buffer, depth); NodeList childNodes = node.getChildNodes(); int numChildren = childNodes.getLength(); Node firstChild = childNodes.item(0); // If the node has only one child and that child is a Text node, // then it's of // the form <Element>Text</Element>, so print 'Element = "Text"'. if (numChildren == 1 && firstChild.getNodeType() == Node.TEXT_NODE) { buffer.append(node.getNodeName()).append(" = \"").append( firstChild.getNodeValue()).append('"'); add(new RichTextField(buffer.toString())); } else { // The node either has > 1 children, or it has at least one // Element node child. // Either way, its children have to be visited. Print the name // of the element // and recurse. buffer.append(node.getNodeName()); add(new RichTextField(buffer.toString())); // Recursively visit all this node's children. for (int i = 0; i < numChildren; ++i) { displayNode(childNodes.item(i), depth + 1); } } } else { // Node is not an Element node, so we know it is a Text node. Make // sure it is // not an "empty" Text node (normalize() doesn't consider a Text // node consisting // of only newlines and spaces to be "empty"). If it is not empty, // print it. String nodeValue = node.getNodeValue(); if (nodeValue.trim().length() != 0) { StringBuffer buffer = new StringBuffer(); indentStringBuffer(buffer, depth); buffer.append('"').append(nodeValue).append('"'); add(new RichTextField(buffer.toString())); } } } /** * Adds leading spaces to the provided string buffer according to the depth * of the node it represents. * * @param buffer * The string buffer to add leading spaces to. * @param depth * The depth of the node the string buffer represents. */ private static void indentStringBuffer(StringBuffer buffer, int depth) { int indent = depth * _tab; for (int i = 0; i < indent; ++i) { buffer.append(' '); } } } </pre> <p class="help">Thank you!</p> <p class="reply">You should get properly "title" attributes of node via</p> <p class="reply">NamedNodeMap attributes = node.getAttributes ();</p> <p class="reply">iterate through the mapping of attributes to retrieve the values you want.</p>

  • SAX parse exception even when the cache xml is correct

    Hello

    I have the bottom of the xml cache and when I start a gemfire Server I get the below error:

    < code >

    ND if read Cache XML file:/C:/vFabric_GemFire_70/insurance_gf_server1/cache.xml. Error while parsing XML, caused by org.xml.sax.SAXParseException: The content of element type "region-attributes" must match "(key-constraint?,value-constraint?,region-time-to-live?,region-idle-time?,entry-time-to-live?,entry-idle-time?,disk-write-attributes?,disk-dirs?,partition-attributes?,membership-attributes?,subscription-attributes?,cache-loader?,cache-writer?,cache-listener*,eviction-attributes?)".

    < code >

    I did check the XML cache and could not find any problems and it is according to the GemFire 7.0 DTD, given below is the xml cache:

    < code >

    <? XML version = "1.0"? >
    <! DOCTYPE PUBLIC cache
    ' - //GemStone systems, declarative Inc.//GemFire 7.0 cached / / IN ".
    < cache lock-location = "120" lock-timeout = '60' research-timeout = '300' is-Server = "true" copy-on-read = "false" >
    < cache-server bind-address port = "${address}" = "${port}" > < / cache server >
    <-critics-bunch-percentage resource manager = "90" expulsion-bunch-percentage = "80" / >
    < record-store name = "insuranceOFDS" allow-force-compression = "true" auto-compact = "true".
    compaction-threshold = "40" oplog-max-size = size of queue "2048" = "1000" interval = "1000" write-buffer-size = "65536" >
    < disk-dirs >
    < disk-dir dir-size "3072" = >$ {GF_SERVER_DS_FOLDER} \insurance_ds < / disc-dir >
    < / disc-dirs >
    < / record store >
    < region attributes id = "defaultRegionAttr" refid = 'PARTITION_REDUNDANT_OVERFLOW' scope = 'distributed-ack ".
    data-policy = "partition" statistical compatible = "true" multicast = 'false' record-store-name = "insuranceOFDS" disc-synchronous = "false" >
    < partition-attributes-redundant copies = '1' total-num-buckets = "113" > < / partition attributes >
    < region-time-to-live >
    < expiry-attributes timeout = "36000" action = "destroy" / >
    < / region-time-to-live >
    < input-time-to-live >
    < expiry-attributes timeout = "900" action = "destroy" / >
    < / entry-time-to-live >
    <>expulsion-attributes
    < lru-memory size maximum = "100" action = "infinity-to-disk" / >
    < / expulsion-attributes >
    < / region-attributes >
    <! - customer area - >
    < name region 'customers' = refid = "defaultRegionAttr" / >
    <! - political region - >
    < name region = "policies" refid = "defaultRegionAttr" / >
    <! - claims region - >
    < name region = "claims" refid = "defaultRegionAttr" / >
    <! - payment area - >
    < name region = 'payments' refid = "defaultRegionAttr" / >
    < / cache >

    < code >

    and the command to start the server:

    < code >

    gfsh start server --name=insurance_gf_server1 --rebalance=true --initial-heap=512M --max-heap=512M --server-bind-address=xxx.xxx.xx.xx --server-port=13490 --J=-DGF_SERVER_DS_FOLDER=C:\vFabric_GemFire_70\insurance_gf_server1,-Daddress=CSCINDAE699524,-Dport=13490,-XX:CMSInitiatingOccupancyFraction=70,-XX:+UseConcMarkSweepGC,-XX:+CMSIncrementalMode,-XX:+CMSIncrementalPacing,-XX:CMSIncrementalDutyCycleMin=0,-XX:CMSIncrementalDutyCycle=10,-XX:+UseParNewGC,-XX:+CMSPermGenSweepingEnabled,-XX:+CMSClassUnloadingEnabled,-XX:MaxGCPauseMillis=250,-XX:MaxGCMinorPauseMillis=100,-XX : + DisableExplicitGC

    < code >

    Can someone help to find the error. Thank you

    The classification is defined by the DTD. This is certainly the case that some DTD defines elements such as the order is not important, but the cache DTD is relatively complex, making this problem very non-negligible.

    See this post SO for general information: http://stackoverflow.com/questions/3022845/dtd-required-elements-ordering

    Then imagine this just apply this to an item in the cache of DTD:

    
    

    The DTD would probably increase by several orders of magnitude.

    However, we could certainly make a point by asserting, in the docs, the order is important.

  • I get a message that says... your version of internet explore is obsolete to run the latest XML parser. I cannot print with my printers. I have a XP SP3, 5 years old. It's time to upgrade to windows 7

    I get a message that says... your version of internet explore is obsolete to run the latest XML parser. I cannot print with my printers. I have a XP SP3, 5 years old. It's time to upgrade to windows 7

    What version of IE are you using?

    The current version is IE8 - http://www.microsoft.com/nz/windows/internet-explorer/default.aspx

    IE9 (is still in beta).

    Harold Horne / TaurArian [MVP] 2005-2011. The information has been provided * being * with no guarantee or warranty.

  • who is the fastest xml parser?

    Currently, I have a question parsering a huge xml, so I want to know what is the fastesr xml parser.

    Thank you.

    PS: Sorry for my English

    We wrote our own, based on something we found on the web, I think it was called tiny XML.  We did things like namespace that we didn't need treatment.  It works on twice the speed of the RIM provided one.  KXML is faster that RIM provided one as well?

    You treat using SAX or DOM we use SAX.  I think that SAX is the faster option.

    You have to use XML?  I've not actually directly compared, but it wouldn't surprise me if JSON is not faster.

  • Widget to the Web service, parsing XML

    I worked on the communication with my web services and back to my widget.

    By using the code below, I was able to perform a GET and repay the XML, but I can't find data where I expect it to be node-wise when parsing XML. I return an object with 3 variables attached to it. I expect to be child nodes 1, 2, and 3. They proved to be 1, 3 and 5 nodes.

    Any ideas on why or how? I feel I'm missing just a simple thing in all of this.

    XML response

    
    - http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
      1000
      Test Station
      105.285
      
    

    The widget code

    //****************** Ajax Logic ******************
    var xmlHttp;
    function getStationUpdate() {
    
        alert("in station update");
        xmlHttp = new XMLHttpRequest();
    
        var Posturl = "http://MachineIPGoesHERE:51107/Service1.asmx/HelloWorld2?";
        alert("after post url");
        xmlHttp.onreadystatechange = updateData;
        alert("after onReadyStateChange");
        xmlHttp.open("GET", Posturl, true);
        alert("after GET");
    
        xmlHttp.send(null);
    }
    
    function updateData() {
        if (xmlHttp.readyState == 4) {
            alert(xmlHttp.responseText);
            parser = new DOMParser();
            var xmlDoc = parser.parseFromString(xmlHttp.responseText, "text/xml");
    
            alert(xmlDoc.documentElement.childNodes[1].tagName + " " + xmlDoc.documentElement.childNodes[1].childNodes[0].nodeValue);
            //alert(xmlDoc.documentElement.childNodes[1].childNodes.length);
            //alert(xmlDoc.documentElement.childNodes[1].hasChildNodes());
            //alert(xmlDoc.documentElement.childNodes[2].hasChildNodes());
            //alert(xmlDoc.documentElement.childNodes[2].tagName + " " + xmlDoc.documentElement.childNodes[2].childNodes[0].nodeValue);
            alert(xmlDoc.documentElement.childNodes[3].tagName + " " + xmlDoc.documentElement.childNodes[3].childNodes[0].nodeValue);
            alert(xmlDoc.documentElement.childNodes[5].tagName + " " + xmlDoc.documentElement.childNodes[5].childNodes[0].nodeValue);
    
            alert(xmlDoc.documentElement.childNodes.length);
        }
    

    Web service

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Services;
    using System.Xml.Serialization;
    
    namespace WebService1
    {
        /// 
        /// Summary description for Service1
        /// 
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [System.ComponentModel.ToolboxItem(false)]
        // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
         [System.Web.Script.Services.ScriptService]
        public class Service1 : System.Web.Services.WebService
        {
    
            [WebMethod]
            public string HelloWorld()
            {
                return "Hello World";
            }
    
            [WebMethod]
            public myTestObj HelloWorld2()
            {
                myTestObj test = new myTestObj();
                return test;
            }
        }
    
        [Serializable]
        public class myTestObj
        {
            private int _StationID;
            private string _StationName;
            private double _Volume;
    
            [XmlElementAttribute(Order = 0)]
            public int StationID
            {
                get
                {
                    return this._StationID;
                }
                set
                {
                    this._StationID = value;
                }
            }
    
            [XmlElementAttribute(Order = 1)]
            public string StationName
            {
                get
                {
                    return this._StationName;
                }
                set
                {
                    this._StationName = value;
                }
            }
    
            [XmlElementAttribute(Order = 2)]
            public double Volume
            {
                get
                {
                    return this._Volume;
                }
                set
                {
                    this._Volume = value;
                }
            }
    
            public myTestObj()
            {
                StationID = 1000;
                StationName = "Test Station";
                Volume = 105.285;
            }
        }
    }
    

    > Any ideas on why or how? I feel I'm missing just a simple thing in all of this.

    White space nodes?

  • Parsing XML and get the required data only using PLSQL

    Hi friends,

    I have a XML data

    < MAJOR_LINE >

    < LINEID > 143424538 < / LINEID >

    nom_element < ITEMNAME > = < / ITEMNAME >

    < > 78245 ITEMPATH < / ITEMPATH >

    < QUANTITY > 10 < / QUANTITY >

    < MINORLINE >

    < LINEID > 143424799 < / LINEID >

    TCC_ITEM_NAME < ITEMNAME > < / ITEMNAME >

    < > 78245 ITEMPATH < / ITEMPATH >

    < QUANTITY > 10 < / QUANTITY >

    < MINORLINE LINEID = "123456_line_id" xmlns = "xxyyzz" >

    < message > < / message >

    < status > < / status >

    < covered_Product_line_id > '123_coveredProductLineID '.

    < / covered_Product_line_id >

    < itemName > < / itemName >

    < quantity > < / quantity >

    "< service lineId ="456_service_line_id">."

    "< covered_Product_line_id >"123_coveredProductLineID"

    < / covered_Product_line_id >

    < productAttributes / >

    < itemType > < / itemType >

    < itemPath > < / itemPath >

    < coveredProducts childProductLineId = "" / > "

    < / coveredProducts >

    < parentCoverage / >

    < / service >

    < / MINORLINE >

    < / MINORLINE >

    < / MAJOR_LINE >

    I want to extract only the Covered_product_line_id and the Service_line_id of the above XML format, these data can come from any where in the xml file and the xml can be any length.

    First we need to find the covered_product_line_id and the service_line_id associated with line_id, (as I pointed out in bold) here only a single pair i showed, but it can be in any number. (Note the line_id is inside the tag).

    #PLSQL

    Help, please.

    Thanks in advance

    Hey Odie,

    Me do string literal too long error:

    Select x.*

    from xmltable)

    XmlNamespaces(default ')

    , ' for $i in //serviceLine

    , $j in $i / coveredProduct

    Returns the element r {}

    $i / lineId

    , $j/childProductLineId

    }'

    from xmltype (')

    45146937

    N20

    1

    63090598

    CON-S

    1

    SNT

    UCS - IOM

    342544294

    N20-FW012

    342544295

    342544294

    UCS-IOM2

    1

    N20-C6508-UPG:

    45146937

    CON-S

    1

    SNT

    342544295

    N20-FW012

    1

    N20-C6508-UPG:

    45146937

    CON-SN

    1

    SNT

    342544296

    FET - 10G

    16

    N20-C6508 - UPG:U SC EXPERIENCE

    342544297

    UCSB-5108-PKG-FW

    1

    N20-C6508-UPXPANSION O

    342544298

    N20-CBLKP

    2

    N20-C6508 - UPG:0 - CBLKP

    342544299

    N01-UAC1

    1

    N20-C6508 - UPG:N01 - UAC1

    342544300

    N20-CBLKI

    1

    N20-C6508 - UPG:U HC EXPANSION OPT: N20-CBLKI

    342544301

    N20-FAN5

    8

    N20-C6508 - UPG:U HC EXPANSION OPT: N20-FAN5

    342544302

    N20-CBLKB1

    6

    N20-C6508-UPG-CBLKB1

    342544303

    N20 - CAK

    1

    N20-C6508-OPT: N20 - CAK

    342544304

    UCSB-B420-M3-D

    1

    N20-C6508-UP-B420-M3-D

    63090594

    CON-SNT-B420M3D

    1

    SNT

    UCS-UC-E5-4617

    342544305

    UCS-ML-1X324RY-A

    342544306

    342544305

    UCS-UC-E5-4617

    2

    N20-C6508 - UPG:PU - E5-4617

    342544304

    CON-SNT-B420M3D

    1

    SNT

    342544306

    UCSRY-A

    2

    N20-C624RY-A

    342544304

    CON-SNT-B420M3D

    1

    SNT

    342544307

    UCS0MS

    1

    N FIO-1600MS

    63090595

    CON-SNT-FIOB16MS

    1

    SNT

    342544308

    N2KD

    4

    N20-C6LKD

    342544309

    UCSB-HS-01-EP

    2

    N20-C65B-HS-01-EP

    342544310

    N1K-VSG-UCS-BUN

    1

    N20-C6508 - UPG:U-BLA1K-VSG-UCS-BUN

    342544311

    VSG-VLEM-UCS-1

    1

    N20-C6508 - UPG:U BLN1K BUN: VSG-VLEM-UCS-1

    63090596

    CON-SAU-VSGUCS

    1

    SAU

    342544312

    N1K-VLEM-UCS-1

    1

    N20-C6508CS-BUN: VMW N-UCS-1

    63090597

    CON-SAU-VLEMUCS

    1

    SAU

    342544313

    UCSB-ACDV

    2

    N20ACDV

    342544314

    R2XX-DMYMPWRCORD

    2

    PWRCORD N20 - C6

    ')

    columns for the ordinalite seq_id

    , path number child_product_line_id "childProductLineId".

    , service_line_id number path "lineId.

    ) x ;

  • Answer need help parsing XML

    Hi, I am new to JAVA and don't work with her each time than in quite awhile.

    I have a question that is probably very simple for someone with experience in JAVA.

    I have a piece of writing JAVA code that will have to apply for a credit card transaction to a gateway, gateways response come in the form of XML.

    Here's the response XML file in its entirety.
    <?xml version="1.0" encoding="utf-8"?>
    <string xmlns="https://www.domain.com/ws/">1,0,Transaction accepted,0</string>
    I worked with other XML responses and was able to get what I need. However, this XML response is a little different, and I can't understand how to correctly analyze the text string I need at the end which is:
    1,0,Transaction accepted,0
    Any help would be appreciated.

    Thank you!

    jl1997 wrote:
    I used the following to try to get the information I need

    new PrintStream(ftemp).println("Root element :" + doc.getDocumentElement().getNodeName());
    new PrintStream(ftemp).println("Root value :" + doc.getDocumentElement().getAttribute("string"));
    

    Output of the above code is:

    Root element :string
    Root value :
    

    So I can identify the name of the node, which is 'chain', I just was not able to read the content of the node.

    Published by: jl1997 on April 9, 2013 08:05

    The element has no attribute named 'string. ' There only the content that you get using getTextContent() or the equivalent of what you use.

  • Help parsing XML with multiple namespaces

    I have a function that returns the following XML:
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
       <soap:Body>
          <fetchReportDataResponse xmlns="http://RptArchive/">
             <fetchReportDataResult>
                <feed xmlns="urn:WA.Ecy.ADS.RptAuditImage.Services">
                   <Table xmlns="">
                      <Report>Person Item</Report>
                      <Program>WQ</Program>
                      <Application>PARIS</Application>
                   </Table>
                   <Table xmlns="">
                      <Report>Select DB by Fragment</Report>
                      <Program>WQ</Program>
                      <Application>PARIS</Application>
                   </Table>
                   <Table xmlns="">
                      <Report>EmployeeDetailReport</Report>
                      <Program>ADS</Program>
                      <Application>Son1</Application>
                   </Table>
                   <Table xmlns="">
                      <Report>DeliveryTestReport</Report>
                      <Program>ADS</Program>
                      <Application>Test</Application>
                   </Table>
                   <Table xmlns="">
                      <Report>Report_NoDMRs_ProcessByDeliveryMethod</Report>
                      <Program>WQ</Program>
                      <Application>PARIS</Application>
                   </Table>
                </feed>
             </fetchReportDataResult>
          </fetchReportDataResponse>
       </soap:Body>
    </soap:Envelope>
    I wrote to try to get the data of the following SQL statement:
    select application,program_name,report
    from 
    (select extract(enforce_pkg.get_ads_report_data,'/soap:Envelope/soap:Body/fetchReportDataResponse/fetchReportDataResult/child::node()',
    'xmlns="http://RptArchive/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/') xml
    from dual )t,
    xmltable('/feed/Table'
    passing t.xml
    columns
    report varchar2(100) path 'Report',
    program_name varchar2(100) path 'Program',
    application varchar2(100) path 'Application');
    {code}
    This returns zero records.  If I break this up, I see that my extract statement is working:
    
    {code}
    select extract(enforce_pkg.get_ads_report_data,'/soap:Envelope/soap:Body/fetchReportDataResponse/fetchReportDataResult/child::node()',
    'xmlns="http://RptArchive/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/') xml
    from dual ;
    Returns
    <feed xmlns="urn:WA.Ecy.ADS.RptAuditImage.Services">
    <Table xmlns="">
    <Report>Person Item</Report>
    <Program>WQ</Program>
    <Application>PARIS</Application>
    </Table>
    <Table xmlns="">
    <Report>Select DB by Fragment</Report>
    <Program>WQ</Program>
    <Application>PARIS</Application>
    </Table>
    <Table xmlns="">
    <Report>EmployeeDetailReport</Report>
    <Program>ADS</Program>
    <Application>Son1</Application>
    </Table>
    <Table xmlns="">
    <Report>DeliveryTestReport</Report>
    <Program>ADS</Program>
    <Application>Test</Application>
    </Table>
    <Table xmlns="">
    <Report>Report_NoDMRs_ProcessByDeliveryMethod</Report>
    <Program>WQ</Program>
    <Application>PARIS</Application>
    </Table>
    </feed>
    So I guess that there is something wrong with my implementation of the function xmltable - perhaps because there are two namespaces involved,
    one of them is null (I know that it is bad form--I am a consumer here and do not have control of the source).

    Any help would be appreciated.

    Best regards, Tony

    You can use xmltable with a simple xpath as follows:

    create or replace type ty_Rep  as object (rep_name varchar2(40), prg_name varchar2(40),app_name varchar2(40));
    /
    create or replace type tb_Rep as table of ty_Rep;
    /
    
    set serveroutput on
    declare
      l_xml xmltype := xmltype('
                                 
                                   
                                       
                                          
                                             Person ItemWQPARIS
    Select DB by FragmentWQPARIS
    EmployeeDetailReportADSSon1
    DeliveryTestReportADSTest
    Report_NoDMRs_ProcessByDeliveryMethodWQPARIS
    '); l_Rep tb_Rep := tb_Rep(); begin select ty_Rep(x.Report, x.Program, x.Application) bulk collect into l_Rep from (select l_XML as m from dual) d ,xmltable ('//Table' passing d.m columns Report varchar2(40) path 'Report' ,Program varchar2(40) path 'Program' ,Application varchar2(40) path 'Application') as x; dbms_output.put_line(l_Rep.count); for r in 1..l_Rep.count loop dbms_output.put_line('Report: ' || l_Rep(r).rep_name ); dbms_output.put_line('Program: ' || l_Rep(r).prg_name ); dbms_output.put_line('Application: ' || l_Rep(r).app_name ); end loop; end; / 5 Report: Person Item Program: WQ Application: PARIS Report: Select DB by Fragment Program: WQ Application: PARIS Report: EmployeeDetailReport Program: ADS Application: Son1 Report: DeliveryTestReport Program: ADS Application: Test Report: Report_NoDMRs_ProcessByDeliveryMethod Program: WQ Application: PARIS PL/SQL procedure successfully completed.
  • The large XML parsing retrieved inside out

    Let me start by saying: I hope this is the right place to post this question. If anyone feels that there is a forum better, please let me know and I can repost here.

    That being said, I am trying to create a function that retrieves the rates and services of FedEx using their Web services from directly within the DB. I was able to create the application, connect and publish to the FedEx server and retrieve the response. My DB is 10.2.0.1.0

    It seems to me have identified 4 problems which I hope someone can help to solve:

    (1) utl_http.read_line return varchar2 with restriction length 32767

    -The XML response is extremely broad. Can be greater than 50000 characters.

    (2) a restriction on length approx. xmltype.createxml varchar2 (2000)

    -I read that 'somewhere' - is this true? workaround solutions?

    (3) I don't want to store the result XML of FedEx anywhere (DB or file system)

    -Each application will be different and their storage is worthless.

    (4) how can I analyze without storing.

    -It is really a culmination of points 2 and 3

    Any guidance, direction or advice would be greatly appreciated.

    (1) utl_http.read_line return varchar2 with restriction length 32767

    I think you can loop and add this content varchar2 (32767) in a clob.

    (2) a restriction on length approx. xmltype.createxml varchar2 (2000)

    You can pass the clob in xmltype()
    v_xml: = XmlType (this_is_a_large_clob);

    (3) I don't want to store the result XML of FedEx anywhere (DB or file system)

    You don't have to. For example to make a cursor within a procedure and pass this XML in a slider and process using xmltable().
    Then, open this slider and the loop through the lines.

    (4) how can I analyze without storing.

    Look at the previous answer.

    Ants

  • Remove the attribute xml Tags help please

    Hello

    Can anyone suggest me how I can attribute del keyterm Tags.

    Remove only the attribute olinkend kt-real-zero

    Screen shot 2012-01-11 at 5.54.18 PM.png

    Thank you

    Best regards, snegig

    1. I saw the warning "Content contains characters that cannot be encoded." when importing xml, but have never tracked down what is happening. Or if I have never seen different content in InDesign than what I expected after seeing this warning. Perhaps, it occurs when the imported xml file does not have the attribute of coding on the initial processing instruction, but InDesign figures on the encoding? I do not know.

    2. If you want to remove any olinked attribute on keyterm items, simply modify the XPath in .evaluateXPathExpression to //keyterm[@olinkend] . If you want to match multiple specific values, just do//keyterm[@olinkend = 'KT01401' or @olinkend = 'KT01402' or @olinkend = 'KT01403'].

    Jeff

  • !!! Need to print the javax.xml.soap.SOAPElement - please help

    Hello
    I have a webservice correctly executed in Weblogic 9.2. I wrote a stand-alone client that receives the javax.xml.soap.SOAPElement as return type of webservice. As
    SOAPElement soapElement = port.getClientPartyIdFromBrAcct("CV4009946");
    I can properly see the request and response using the TCP/IP monitor.

    But I need to print the entire SOAPElement as a string. Because I set the SOAPElement as XML in an HTML page to display in the browser... in a way properly shaped.
    Please let me know how I can do it.

    Hello
    I did something similar. You can add the following method:

    public String convertDocumentToString (input element) {}
    DOMSource domSource = new DOMSource (input);
    StringWriter writer = new StringWriter();
    StreamResult result = new StreamResult (writer);
    TransformerFactory tf = TransformerFactory.newInstance ();
    Transformer transformer;
    try {}
    transformer = tf.newTransformer ();
    transform. Transform (domSource, result);
    } catch (Exception e) {}
    System.out.println (e);
    }
    Return writer.toString ();
    }

    It will return your xml into a string and then call with your SOAPElement object as input.

    André

  • parsing xml in blackberry jde 5.0

    Hi, I was wondering if someone could help me to analyze an XML file from a server in the channels that I can use. I'm trying to access the data are under the "ResponseChoices" tag in the following fragment:

    It is a question, nothing to do with the BlackBerry in particular generic analysis of XML. Your code does not work because it is not navigate the DOM correctly. For the XML file that you posted, x.item (0) is an element corresponding to the tag. This element has two child elements corresponding to the tags. (It can have children for the white spaces as well, depending on the configuration of the parser, it is better to browse children or reuse getElementsByTagName.) The child element for each tag has, in turn, a child of text that contains the value you want.

    So maybe a way to do this:

    NodeList x = messageElements[i].getElementsByTagName("String");
    int n = x.length();
    String[] choices = new String[n];
    for (int i = 0; i < n; ++i) {
        choices[i] = x.item(i).getFirstChild().getNodeValue();
    }
    

    If you have tags in other places, so you can first get each ResponseChoices node, cast to an element and call the getElementsByTagName method to obtain that these tags that fall under it.

Maybe you are looking for