XQuery err:XPST0003

Hello,
I need help. I have the following query
define variable $packets {collection("nettraffic.bdbxml")/packet};
for $i in $packets
return
<packet>
     <mac>{$i/proto[@name="ethernet"]/field[@name="src"]/@showvalue}</mac>
     <ip>{$i/proto[@name="ip" or @name="ipv6"]/field[@name="src"]/@showvalue}</ip>
</packet>and the following code in C++:
dbPath = config_manager->LoadDatabaseLocation();
          container = manager->openContainer(dbPath.c_str(), DBXML_TRANSACTIONAL | DBXML_ALLOW_VALIDATION |
                                                      DBXML_INDEX_NODES | DB_THREAD, XmlContainer::NodeContainer);
          XmlQueryContext context = manager->createQueryContext();
          std::string myQuery = query_str.c_str();
          XmlResults results = manager->query(myQuery, context);
          XmlValue value;
          std::string docContent = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?> \n<packets>";
          while (results.next(value))
               docContent += "\n" + value.asString();
          docContent += "\n</packets>";and I get the the error [XPST0003]. What am I doing wrong? How can I save the query results in an xml file for further processing ?
Please help me ! Thanks in advance,
Adina
Message was edited by:
Adina

Hi Adina,
You are using incorrect XQuery syntax. You didn't give the line and column for the error you got, but from looking at your query it seems to be the global variable declaration, which should look like this:
define variable $packets := collection("nettraffic.bdbxml")/packet;John

Similar Messages

  • Problem with user defined function in XQUERY

    Hi,
    I have a file in which I store XQUERY. My java program reads this file and executes the xquery
    and output the result. I have a working XQUERY in a file, which is something like :
    <feed>
    let $entries := for $x in collection('/path/to/atomStore.bdbxml')/entry[matches(id,'
    .entry')]
    order by $x/updated descending
    return <entry xmlns="http://www.w3.org/2005/Atom">{$x/id,$x/title,$x/published,$x/updated,$x/link}
    </entry>
    let $latest := fn:subsequence($entries, 1, 10)
    for $f in $latest return $f
    </feed>
    After adding the following simple function(I'm not calling it anywhere for the time being),
    I'm getting an error
    com.sleepycat.dbxml.XmlException: Error: Error in XQuery expression:
    Unrecognized character 'a' (0x61) [err:XPST0003], line 33, column 2, errcode = XPATH_PARSER_ERROR
    declare function xml:convertdate($date as xs:integer) as xs:string
    let $months := ("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec")
    let $month := $months[$date]
    return $month
    I couldn't find any error with the function syntax. Anyone has any idea?
    Regards,
    Anoop

    Hi Anoop,
    The query and function work fine for me. What does the line and column information in the error point to?
    John

  • Precompiled xquery functions

    I'm trying to find the way to prepare and reuse queries thought the life of application.
    I have a bunch of functions that call each other; all of them accept one string parameter and will be called frequently.
    What I'm doing is:
    1. Prepare following query for each function call (declarations of all and call of one of them):
    declare function pg:fun1 ( $t as xs:string )
    return "some_node"
    declare function pg:fun2 ( $t as xs:string )
    return ns:fun1 ( $local_var )
    declare variable $p as xs:string external;
    return ns:fun1 ( $p )
    2. Call function this way:
    self.__qe [ function ].setVariableValue ( "p", XmlValue ( XmlValue.STRING, str ( arg ) ) )
    return self.__qe [ function ].execute ( self.__dc.qc )
    If it would work that would serve my needs, but preparing (step 1) falls with error:
    _dbxml.XmlQueryParserError: (6, "Error: Unrecognized character 'p' (0x70) [err:XPST0003], <query>:26:9")
    that error on actual function call "return ns:fun1 ( $p )", so it's not sufficient to just declare external variable before query preparation
    Maybe I'm taking completely wrong approach, but I couldn't find any tips on how to do that proper way. If somebody can tell me how to prepare bunch of functions and than just call them passing different parameter values, I would be much appreciated.

    Hi Philippe,
    You would be doing things in a correct manner if you were using XQuery syntax in your query. After unmangling what I think you mean from what you posted, you might want to try something like this:
    declare function local:fun1 ( $t as xs:string )
    "some_node"
    declare function local:fun2 ( $t as xs:string )
    local:fun1 ( $t )
    declare variable $p as xs:string external;
    local:fun1 ( $p )John

  • OSb-XQuery-TypeConversion(decimal to int)

    Hi all,
    I need some help in Xquery Transformation
    Source element type is decimal
    target element type is int
    I need to convert to decimal to int in Xquery.
    Actually I tried like this way
    <targetElement>{xs:int($sourceElement)}</targetElement>
    <error>Error occurred while executing XQuery: {err}XP0021: "100.00": can not cast to {http://www.w3.org/2001/XMLSchema}integer: error: integer: Invalid integer value: 100.00. Either the XQuery is invalid or it contains custom XQuery functions. Try using the web test console to test this XQuery (Right click on the XQuery file and select Run As ->Run On Server) </error>
    Can u help on this ,Which function do I need to use for type casting in Xquery.
    Regards
    Krishna.

    It's tricky because when you convert from xs:string to xs:integer decimal point is not allowed... So you have to go around and convert to xs:decimal first...
    <targetElement>{xs:int(xs:decimal($sourceElement))}</targetElement>
    Hope this answers your question...
    Cheers,
    Vlad

  • Please help me to find the problem in this Query

    hi
    This is my xml structure,
    <?xml version="1.0">
    <rss version ="2.0">
    <channel>
    <Lgs>
    <Lg>
         <Fid>16447</Fid>
    <Fname>Sam</Fname>
    </Lg>
    </Lgs>
    <Lgs>
    <Lg>
         <Fid>206</Fid>
    <Fname>David</Fname>
    </Lg>
    </Lgs>
    <Lgs>
    </channel>
    </rss>
    I need to limit the results ie, at a time retrieve only "10" results , also that should be ordered by node "Fid".
    I am using PHP-API
    and following query is i have used...
    $query = "let $hits := (for $hit in collection('gview.dbxml')/rss/channel/Lgs/Lg order by $hit/Fid return $hit) return subsequence($hits, 1, 10)";
    $results = $mgr->query($query);
    getting the error,
    Fatal error: Uncaught exception 'xmlexception' with message 'Error: syntax error, unexpected :=, expecting <end of file> [err:XPST0003], <query>:1:8' in /usr/local/apache/htdocs/add_loc_file.php:99 Stack trace: #0 /usr/local/apache/htdocs/add_loc_file.php(99): xmlmanager->query('let := (for i...') #1 {main} thrown
    Message was edited by:
    user647571

    The "$hits" in your string is being interpreted by PHP as a variable reference and substituted out before DB XML gets the query.
    John

  • OSB - XQuery - line 24, col 1 {err}FORG0005: expected 1 item, got 2 or mor

    In the below XQ, I am trying to learn making calls to local functions. I have tweaked my earlier XQ, which had a local variable defined [in xf:getCost() function] as XPath to Quantity. Now, I have modified the XQ to make a call to xf:getQty() from xf:getCost(), to get the desired Quantity.
    On executing the below code I get Error occurred while executing XQuery: line 24, column 1: {err}FORG0005: expected exactly one time, got 2+ items. Either the XQuery is invalid or .... Request Help
    xquery version "1.0" encoding "Cp1252";
    (:: pragma parameter="$anyType1" type="xs:anyType" ::)
    (:: pragma type="xs:anyType" ::)
    declare namespace xf = "http://tempuri.org/purchaseOrder/";
    declare function xf:getCost()
    as xs:double {
    let $po := <purchase-order>
    <red-tape/>
    <order-item product="p010" price="10.50" quantity="3"/>
    <order-item product="p020" price="18.10" quantity="8"/>
    <order-item product="p020" price="11.10" quantity="8"/>
    </purchase-order>
    let $s1 := $po/order-item/@price
    let $s2 := $po/order-item/@quantity
    let $s3 := sum(for $el at $i in $s1 return $s1[$i] * xf:getQty($i))
    return $s3
    declare function xf:getQty($index as xs:decimal)
    as xs:decimal {
    let $po := <purchase-order>
    <red-tape/>
    <order-item product="p010" price="10.50" quantity="3"/>
    <order-item product="p020" price="18.10" quantity="8"/>
    <order-item product="p020" price="11.10" quantity="8"/>
    </purchase-order>
    return ($po/order-item/@quantity[$index])
    xf:getCost()

    return ($po/order-item[$index]/@quantity)
    not
    return ($po/order-item/@quantity[$index])

  • OSB - XQuery - line 7, col 2: {err}FORG0005: expected exactly 1 item, got 0

    Hi,
    I am trying to execute the below sample XQuery. Eclipse designer does not show any error. However on executing the XQuery, I get the following error "+Error executing the XQuery transformation: line 7, column 2: {err}FORG0005: expected exactly one item, got 0 items+". Appreciate your help.
    xquery version "1.0" encoding "UTF-8";
    declare namespace xf = "http://tempuri.org/OSB%20Project%201/Ids/";
    declare function xf:Ids()
    as element() {*
    *     let $abc := <catalog><product dept="MEN"><number>784</number><name language="en">Cotton Dress Shirt</name><colorChoices>white gray</colorChoices><desc>Our favorite shirt!</desc></product></catalog>*
    *     for $product in $abc/catalog/product*
    *     let $name := $product/name*
    *     where $product/@dept = "ACC"*
    *     order by $name*
    *     return $name*
    xf:Ids()

    Thanks, for the answer.
    I just tweeked my XQuery:Var = $abc a little and ended up with same issue. Request your help again.
    xquery version "1.0" encoding "UTF-8";
    declare namespace xf = "http://tempuri.org/OSB%20Project%201/Ids/";
    declare function xf:Ids() as element(*)? {
    let $abc := +<catalog><product dept="MEN" xmlns="http://datypic.com/prod"><number>784</number><name language="en">Cotton Dress Shirt</name><colorChoices>white gray</colorChoices><desc>Ou<i>favorite</i> shirt! </desc></product><product dept="ACC"><number>563</number><name language="en">Floppy Sun Hat</name></product><product dept="ACC"><number>443</number><name language="en">Deluxe Travel Bag</name></product><product dept="MEN"><number>784</number><name language="en">Cotton Dress Shirt</name><colorChoices>white gray</colorChoices><desc>Ou<i>favorite</i> shirt! </desc></product><product dept="WMN"><number>557</number><name language="en">Fleece Pullover</name><colorChoices>navy black</colorChoices></product></catalog>+
    --(:<catalog><product dept="ACC"><number>784</number><name language="en">Cotton Dress Shirt</name><colorChoices>white gray</colorChoices><desc>Our favorite shirt!</desc></product></catalog>:)--
    for $product in $abc/product
    let $name := $product/name
    where $product/@dept = "ACC"
    order by $name
    return $name
    xf:Ids()

  • Please Help With : XVM-01003: [XPST0003]/LPX-00801: XQuery  Syntax error at

    Hi gurus,
    I need your help on using the XMLQuery function. We are FINALLY in the processing of migrating from 10g to 11gR2! Oracle says that we should replace extracValue with XMLQuery, so I am trying to do that but I am getting the errors below,
    XVM-01003: [XPST0003] Syntax error at (if I use a PL/SQL variable).
    LPX-00801: XQuery syntax error at (if I use the literals).
    I have read through many of the posts related to XMLQuery and its default element namespace, but I have no luck on that. I have an example that has this kind prefix (a part of the xml is posted here):
    <soap:Body>
    <soap:Fault xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
    <soap:Code>
    <soap:Value>soap:Sender</soap:Value>
    <soap:Subcode>
    <soap:Value>soap:InvalidMessage</soap:Value>
    </soap:Subcode>
    </soap:Code>
    <soap:Reason>
    <soap:Text xml:lang="en">UpdateCaseDetentionStatus does not apply to this case&apos;s type.</soap:Text>
    </soap:Reason>
    <soap:Node>CourtFileNumber</soap:Node>
    I need to get the Text inside the Reason node. No matter what I do with the default namespace (and if I don't declare one I also get an error), I get the following error:
    XMLQuery ('declare default element namespace s="http://www.w3.org/2003/05/soap-envelope" ; /s:Envelope/s:Body/s:Fault/s:Reason/s:Text'):
    LPX-00801: XQuery syntax error at 's'
    1 declare default element namespace s="http://www.w3.org/2003/05/soap-envelop
    - ^
    ORA-06512: at line 103
    XMLQuery('declare default element namespace xmlns:soap="http://www.w3.org/2003/05/soap-envelope" ; /soap:Envelope/soap:Body/soap:Fault/soap:Reason/soap:Text'):
    LPX-00801: XQuery syntax error at 'xmlns:soap'
    1 declare default element namespace xmlns:soap="http://www.w3.org/2003/05/soa
    - ^
    ORA-06512: at line 103
    Using the XMLTable function does not have any problems.
    What do I do wrong here? I could just use the XMLTable to replace all the extractValue(s) that I have, but I really want to learn how to make the XMLQuery correct. Please help!
    I just tried this and I got the same error:
    XMLQuery('declare default namespace s="http://www.w3.org/2003/05/soap-envelope" ; (::) $p/s:Envelope/s:Body/s:Fault/s:Reason/s:Text' passing p_XMLDoc as "p"
    Thank you.
    Ben
    Edited by: myora9i on Apr 22, 2011 1:42 PM

    Hi Ben,
    Can someone please explain to me when should I use the default key word and when I should not use it?If you declare a default namespace then all unqualified (= unprefixed) elements will be considered belonging to that namespace.
    If you declare a namespace with a prefix, you'll have to qualify each element in the XQuery.
    See below example based on your XML sample :
    DECLARE
      soap_doc xmltype := xmltype(
      '<soap:Body xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
    <soap:Fault>
    <soap:Code>
    <soap:Value>soap:Sender</soap:Value>
    <soap:Subcode>
    <soap:Value>soap:InvalidMessage</soap:Value>
    </soap:Subcode>
    </soap:Code>
    <soap:Reason>
    <soap:Text xml:lang="en">UpdateCaseDetentionStatus does not apply to this case''s type.</soap:Text>
    </soap:Reason>
    <soap:Node>CourtFileNumber</soap:Node>
    </soap:Fault>
    </soap:Body>'
      v_text  varchar2(100);
    BEGIN
      -- with a default namespace,
      -- no need to prefix each element :
      SELECT XMLCast(
        XMLQuery(
          'declare default element namespace "http://www.w3.org/2003/05/soap-envelope"; (::)
           /Body/Fault/Reason/Text'
          passing soap_doc
          returning content
        as varchar2(100)
      INTO v_text
      FROM dual;
      dbms_output.put_line(v_text);
      -- with a declared namespace prefix,
      -- each element must be qualified with the prefix :
      SELECT XMLCast(
        XMLQuery(
          'declare namespace s = "http://www.w3.org/2003/05/soap-envelope"; (::)
           /s:Body/s:Fault/s:Reason/s:Text'
          passing soap_doc
          returning content
        as varchar2(100)
      INTO v_text
      FROM dual;
      dbms_output.put_line(v_text);
    END;
    /

  • Xquery: Invalid URI format [err:FODC0002]

    I tried to run a query
    query ‘"collection("C:\Documents and Settings\mxu\stripesdbxml.dbxml\")/profile/preference [@key=\'party\']"’
    but it indicts that uri is in an invalid format from the very beginning of the query string.
    and I am also confused that when i create a container in tomcat environment with a relative address, the container is create in Tomcat/bin directory, but not in my webapp/myapp folder.
    How can I change this

    Hi,
    You can't use a windows path as an argument to the collection() function - as the error message says, it's not a valid URI. I would suggest not using a full path at all, in fact. You should open the container first using a command like this:
    openContainer C:\Documents and Settings\mxu\stripesdbxml.dbxmlThe add an alias for the container, which is another name that you can access it by:
    addAlias myAliasThen access the container from a query like this:
    query "collection('myAlias')/profile/preference [@key='party']"In answer to your other question, containers can be accessed and created using a path relative to the location of the database environment.
    John

  • Error parsing XML: {err}FORG0005: expected exactly one item, got 0 items

    Hi ,
    Good Morning to all
    in osb replace action am using xquery transformation resource.
    source code of xquery is :
    ====================================================================================
    (:: pragma bea:global-element-parameter parameter="$addition1" element="ns0:Addition" location="../wsdl/NewWSDLFile.wsdl" ::)
    (:: pragma bea:global-element-return element="ns1:process" location="../bpelprocess1_client_ep.wsdl" ::)
    declare namespace ns1 = "http://xmlns.oracle.com/POProcessing/AdditionOSB/BPELProcess1";
    declare namespace ns0 = "http://www.example.org/NewWSDLFile/";
    declare namespace xf = "http://tempuri.org/ServiceCallout/trans/route/";
    declare function xf:route($addition1 as element(ns0:Addition))
    as element(ns1:process) {
    <ns1:process>
    <ns1:value1>{ data($addition1/value1) }</ns1:value1>
    <ns1:value2>{ data($addition1/value2) }</ns1:value2>
    </ns1:process>
    declare variable $addition1 as element(ns0:Addition) external;
    xf:route($addition1)
    =====================================================
    at the time of running "error is Error parsing XML: {err}FORG0005: expected exactly one item, got 0 items " in replace action.
    how to resolve this problem...
    Thanks & Regards
    venky

    The reason for the error is the xquery is not able to find the values in the input... Check the input and namespaces...
    Try...
    <ns1:value1>{ data($addition1/ns0:value1) }</ns1:value1>
    <ns1:value2>{ data($addition1/ns0:value2) }</ns1:value2>Cheers,
    Vlad

  • Problem with Xquery transformation in OSB

    hi,
    My scenario is that I have to break the data in a single tag of xml A, to populate multiple tags of xml B.I am using Xquery transformation and substring function to achieve this. The problem comes when i import the xquery resource in OSB and try to do the transformation in a proxy service it gives the following error
    <con:fault xmlns:con="http://www.bea.com/wli/sb/context">
    <con:errorCode>BEA-382510</con:errorCode>
    <con:reason>
    *OSB Assign action failed updating variable "message": com.bea.wli.common.xquery.XQueryException: Error parsing XML: {err}XP0006: "element {http://schemas.xmlsoap.org/soap/envelope/}Body { {http://www.w3.org/2004/07/xpath-datatypes}untypedAny }": bad value for type element {http://www.example.org/data}data { {http://www.w3.org/2001/XMLSchema}anyType }*
    </con:reason>
    <con:location>
    <con:node>PipelinePairNode1</con:node>
    <con:pipeline>PipelinePairNode1_request</con:pipeline>
    <con:stage>stage1</con:stage>
    <con:path>request-pipeline</con:path>
    </con:location>
    </con:fault>
    the configuration i have done in the proxy service is this::_
    Assign: [XQuery resource..] to [message]
    Delete: [.] in [body]
    Insert [$message] [as first child of][.] in [body]
    The Xquery resource is the .xq file that i have generated for Xquery transformation.
    and i m routing this proxy service to a business service that wud take the XML and dump it to my D drive using file protocol.
    Edited by: rahulc on Oct 12, 2010 12:40 AM
    Edited by: rahulc on Oct 12, 2010 12:41 AM

    My Xquery is this::
    (:: pragma bea:global-element-parameter parameter="$data1" element="ns0:data" location="data.xsd" ::)
    (:: pragma bea:global-element-return element="note" location="note.xsd" ::)
    declare namespace ns0 = "http://www.example.org/data";
    declare namespace xf = "http://tempuri.org/OSB_Try/tag_break/";
    declare function xf:tag_break($data1 as element(ns0:data))
    as element(note) {
    <note>
    <to>
    fn:substring(data($data1),
    1 ,
    6)
    </to>
    <from>
    fn:substring(data($data1),
    7 ,
    6)
    </from>
    <heading>
    fn:substring(data($data1),
    13 ,
    6)
    </heading>
    <body>
    fn:substring(data($data1),
    19 ,
    11)
    </body>
    </note>
    declare variable $data1 as element(ns0:data) external;
    xf:tag_break($data1)
    and my data is this::
    <?xml version="1.0"?>
    <ns0:data xmlns:ns0="http://www.example.org/data">DON'T FORGET ME THIS WEEKEND!</ns0:data>
    and i have tested this zquery for the above data and this is the transformation its doing::
    <note>
    <to>DON'T </to>
    <from>FORGET</from>
    <heading> ME TH</heading>
    <body>IS WEEKEND!</body>
    </note>
    Edited by: rahulc on Oct 12, 2010 1:57 AM

  • Urgent - XQuery ERROR in Aqualogic Console

    Hello everybody!
    I am getting the following error in my Xquey in ALSB console.
    Could you plase help me?
    An error occurred creating the resource:
    An error occurred compiling the XQuery resource: line 6, column 26: {err}XQ0046: "http://www.tibco.com/schemas/BW/eAI/Shared Resouces/Schema Definition/PRT/Schema.xsd": illegal URI.
    Many Thanks!

    This error could be due to the spaces in the schema file
    Shared Resources
    Schema Definition
    Do not include preceding or embedded spaces in schema file and folder names, give it a try
    Thanks
    Ashok
    Edited by mashokku at 03/28/2008 4:37 PM

  • OSB download 250 MG file results in error Error parsing XML: {err}FORG0005

    Hi,
    Using OSB 11.1.1.5. I have service to download files from Oracle ECM. Running into an issue where the file size is over 250 MB service is failing. Giving me an error
    OSB Replace action failed updating variable "body": Error parsing XML: {err}FORG0005: expected exactly one item, got 0 items
    I have service callout to get the binary content of the file and it's taking over 5 minutes and then this error. I also set Read Timeout and Connection Timeout to 20 seconds at the business service level
    but looks like it's not taking that timeout values and still waiting over 5 minutes before it dies. My JTA Timeout is set to 12 minutes. After service callout I have a log to write the output but it's not even getting there and throwing that error above
    How can I trap that kind of errors. How can I set timeout at service level i.e. if after 1 minute if the file is still downloading close the connection etc.
    I don't want to have some many open threads in the back ground as this service is being called in a loop to download files. Smaller files like 30 MG downloads fine but the larger ones are not.
    I have a error hndler at the root level but the error is not trapped there either. Looks like system errors are not getting trapped.
    So Just wondering if OSB is suitable to download that huge files.
    Thanks

    The reason for the error is the xquery is not able to find the values in the input... Check the input and namespaces...
    Try...
    <ns1:value1>{ data($addition1/ns0:value1) }</ns1:value1>
    <ns1:value2>{ data($addition1/ns0:value2) }</ns1:value2>Cheers,
    Vlad

  • Problem Using XQuery Operators

    I have been able to use every XPath function in the "fn" namespace so far with no problem. Unfortunately, when I tried to use an XQuery operator from the "op" namespace, I get an error. I am trying to use "op:date-equals(xs:date, xs:date)" and I get the following error message:
    com.sleepycat.dbxml.XmlException: Error: Function 'date-equal' in namespace 'http://www.w3.org/2005/04/xpath-functions' with 2 argument is undefined [err:XPST0017], errcode = XPATH_PARSER_ERROR
    The actual XQuery is: "/ld:library/book[date-equal(2006-11-28, year)]". year is a direct child of book. I've tried putting "./" before year, but I get the same error.

    Hi Brian,
    When reading the XQuery Functions and Operators specification, functions in the "op" namespace are merely used to describe functionality - they are not available to a user of XQuery.
    Note also that XQuery does not allow you to write an xs:date as a literal - you will have to cast a string to an xs:date.
    In order to compare items as a date, you should first cast the items to an xs:date, and then use the "=" or "eq" operators:
    /ld:library/book[xs:date(year) = xs:date("2006-11-28")]John

  • QueryError "It is error for context item undefined when using[err:XPDY0002]

    Hi,
    I a beginner for DB XML with python, below is my script and i have error
    "def next(*args): return _dbxml.XmlResults_next(*args)
    RuntimeError: Error: It is an error for the context item to be undefined when using it [err:XPDY0002], <query>:1:12" when i executed my scripts. Pls advice. Thank you.
    import sys
    from dbxml import *
    from bsddb3.db import *
    class DbXml:
    def createEnvironment(self, home):
    """ Create DBEnv and initialize XmlManager"""
    try:
    environment = DBEnv()
    environment.open(home, DB_RECOVER|DB_CREATE|DB_INIT_LOCK|
    DB_INIT_LOG|DB_INIT_MPOOL|DB_INIT_TXN, 0)
    except DBError, exc:
    print exc
    sys.exit()
    try:
    mgr = XmlManager(environment, 0)
    except XmlException, se:
    print se
    sys.exit()
    return mgr
    def closeEnvironment(self):
    """ Close DBEnv environment"""
    environment = DBEnv()
    environment.close()
    def createContainer(self, mgr, containerName):
    """ Create/open a node container"""
    if mgr.existsContainer(containerName) != 0:
    mgr.removeContainer(containerName)
    try:
    return mgr.createContainer(containerName,
    DBXML_TRANSACTIONAL|DBXML_ALLOW_VALIDATION,
    XmlContainer.NodeContainer)
    except XmlException, ex:
    print ex
    sys.exit()
    def putDocument(self, mgr, cont, file, DocName):
    """ put xml document in database"""
    self.docName = DocName
    f = open(file)
    q = f.read()
    f.close()
    try:
    # all Container modification operations need XmlUpdateContext
    uc = mgr.createUpdateContext()
    txn = mgr.createTransaction()
    try:
    docName = cont.putDocument(txn, self.docName,
    q, uc) #, DBXML_GEN_NAME)
    txn.commit()
    except XmlException, ex:
    print ex
    txn.abort()
    txn = mgr.createTransaction()
    doc = cont.getDocument(txn, self.docName)
    name = doc.getName()
    docContent = doc.getContentAsString()
    txn.commit()
    print "Document name: ",name,"\nContent: ",docContent
    except XmlException, inst:
    print inst
    if txn:
    txn.abort()
    def query(self, mgr, cont, queries):
    """ Query"""
    myQuery = r"collection(" + cont + ")" + "/" + queries
    myContainer = mgr.openContainer(cont)
    qContext = mgr.createQueryContext()
    qContext.setEvaluationType(XmlQueryContext.Lazy)
    results = mgr.query(myQuery, qContext)
    for value in results:
    document = value.asDocument()
    name = document.getName()
    content = value.asString()
    print name, ":", content
    if __name__ == "__main__":
    dbxml = DbXml()
    mgr = dbxml.createEnvironment(".")
    cont = dbxml.createContainer(mgr, "test.dbxml")
    dbxml.putDocument(mgr, cont, "C:\Documents and Settings\uidc0998\Desktop\\books.xml", "books.xml")
    dbxml.query(mgr, "test.dbxml", "bookstore/book/title")
    dbxml.closeEnvironment()
    Edited by: user10951778 on Mar 31, 2009 5:47 PM

    Hi rucong.zhao,
    Below is my xml, may i know what type of namespace or what i should put for namespace? Thank you.
    <bookstore>
    <book category="COOKING">
    <title lang="en">Everyday Italian</title>
    <author>Giada De Laurentiis</author>
    <year>2005</year>
    <price>30.00</price>
    </book>
    <book category="CHILDREN">
    <title lang="en">Harry Potter</title>
    <author>J K. Rowling</author>
    <year>2005</year>
    <price>29.99</price>
    </book>
    <book category="WEB">
    <title lang="en">XQuery Kick Start</title>
    <author>James McGovern</author>
    <author>Per Bothner</author>
    <author>Kurt Cagle</author>
    <author>James Linn</author>
    <author>Vaidyanathan Nagarajan</author>
    <year>2003</year>
    <price>49.99</price>
    </book>
    <book category="WEB">
    <title lang="en">Learning XML</title>
    <author>Erik T. Ray</author>
    <year>2003</year>
    <price>39.95</price>
    </book>
    </bookstore>

Maybe you are looking for

  • No Design Mode in Flash Builder 4.7

    It took me many hours to figure this out so I thought I would share what I discovered to make it easier on others. 1.  Flash Builder 4.7 no longer has Design Mode (being able to design forms graphically).  4.6 was the last version to support it. 2. 

  • Creating a default User account for new users

    Today I tried creating a default setting for and account that could be used for all new users.  I did web searches after web serches and not luck.  In the old systems it was simple, but Mavericks made it difficult.  But after much hair pulling and pu

  • I inadvertantly deleted my tool bar and cannot replace it

    I deleted the toolbar on my homepage and am unable to replace it. I have uninstalled and reinstalled firefox to no avail. Help!

  • Applied Amount does not match Applied Transaction

    I have a credit memo for an amount of $124.14. The header page says the applied amount is $248.24 and open balance is -124.14 (In essence a debit to the customer balance) The applied transaction has three entries to this CN: IN applied amount  124.14

  • Why does map data space on N900 is limited to 5.5 ...

    Can anyone tell me the reason why there is a limit to the map data space on N900? Currently, I can only down load the map data (using Map Loader) up to 5.5 GBs even though I still have over 20 GBs left on my /home/user/Mydocs. Thanks