iway xml archive user's guide€¦ · chapter 1 installing the iway xml archive this section...
TRANSCRIPT
iWay XML Archive User's GuideVersion 7.0.x and Higher
August 16, 2018
Active Technologies, EDA, EDA/SQL, FIDEL, FOCUS, Information Builders, the Information Builders logo, iWay, iWaySoftware, Parlay, PC/FOCUS, RStat, Table Talk, Web390, WebFOCUS, WebFOCUS Active Technologies, and WebFOCUSMagnify are registered trademarks, and DataMigrator and Hyperstage are trademarks of Information Builders, Inc.
Adobe, the Adobe logo, Acrobat, Adobe Reader, Flash, Adobe Flash Builder, Flex, and PostScript are either registeredtrademarks or trademarks of Adobe Systems Incorporated in the United States and/or other countries.
Due to the nature of this material, this document refers to numerous hardware and software products by theirtrademarks. In most, if not all cases, these designations are claimed as trademarks or registered trademarks by theirrespective companies. It is not this publisher's intent to use any of these names generically. The reader is thereforecautioned to investigate all claimed trademark rights before using any of these names other than to refer to the productdescribed.
Copyright © 2018, by Information Builders, Inc. and iWay Software. All rights reserved. Patent Pending. This manual, orparts thereof, may not be reproduced in any form without the written permission of Information Builders, Inc.
Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Documentation Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5
Related Publications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Customer Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Help Us to Serve You Better . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7
User Feedback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Information Builders Consulting and Training . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1. Installing the iWay XML Archive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
iWay XML Archive Installation Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11
Installing iWay Service Manager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Installing mongoDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Configuring the iWay XML Archive Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Verifying the iWay XML Archive Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2. Using the iWay XML Archive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
iWay XML Archive Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17
XML and JSON . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Loading Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .18
Making Requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .18
The Query String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .19
Query Grammar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Searching Elements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Searching Attributes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .20
Searching on Multiple Keys (and). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .20
Advanced Queries. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .21
Using Regular Expressions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Searching by _id. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Understanding the JSON Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Returning XML Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .23
Returning a Slice of XML With XQuery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3. Using the iWay XML Archive Test Client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Test Client Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
iWay XML Archive User's Guide 3
Query Grammar in the Test Client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Searching Elements in the Test Client. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Searching Attributes in the Test Client. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Searching on Multiple Keys (and) in the Test Client. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Advanced Queries in the Test Client. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Using Regular Expressions in the Test Client. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .30
Understanding the Results. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Applying an XQuery. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .32
Special Queries. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .33
Querying an ID. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Contents
4 Information Builders
Preface
This document describes the iWay XML Archive, which is a system that you can use toefficiently store, query, and retrieve a large number of XML documents.
Note: This Release 7.0.x content is currently being updated to support iWay Release 8.0.xsoftware. In the meantime, it can serve as a reference for your use of iWay Release 8. If youhave any questions, please contact [email protected].
How This Manual Is Organized
This manual includes the following chapters:
Chapter/Appendix Contents
1 Installing the iWay XMLArchive
Describes how to install the required software forthe iWay XML Archive and how to configure the iWayXML Archive Application.
2 Using the iWay XML Archive Describes how to use the iWay XML Archive for thestorage and retrieval of XML documents.
3 Using the iWay XML ArchiveTest Client
Describes how to use the iWay XML Archive TestClient to search the iWay XML Archive and retrieveXML documents.
Documentation Conventions
The following table describes the documentation conventions that are used in this manual.
Convention Description
THIS TYPEFACE
or
this typeface
Denotes syntax that you must type exactly as shown.
this typeface Represents a placeholder (or variable), a cross-reference, or animportant term. It may also indicate a button, menu item, or dialogbox option that you can click or select.
underscore Indicates a default setting.
Key + Key Indicates keys that you must press simultaneously.
iWay XML Archive User's Guide 5
Convention Description
{ } Indicates two or three choices. Type one of them, not the braces.
| Separates mutually exclusive choices in syntax. Type one of them,not the symbol.
... Indicates that you can enter a parameter multiple times. Type onlythe parameter, not the ellipsis (...).
.
.
.
Indicates that there are (or could be) intervening or additionalcommands.
Related Publications
Visit our Technical Content Library at http://documentation.informationbuilders.com. You canalso contact the Publications Order Department at (800) 969-4636.
Customer Support
Do you have questions about this product?
Join the Focal Point community. Focal Point is our online developer center and more than amessage board. It is an interactive network of more than 3,000 developers from almost everyprofession and industry, collaborating on solutions and sharing tips and techniques. AccessFocal Point at http://forums.informationbuilders.com/eve/forums.
You can also access support services electronically, 24 hours a day, with InfoResponseOnline. InfoResponse Online is accessible through our website, http://www.informationbuilders.com. It connects you to the tracking system and known-problemdatabase at the Information Builders support center. Registered users can open, update, andview the status of cases in the tracking system and read descriptions of reported softwareissues. New users can register immediately for this service. The technical support section of http://www.informationbuilders.com also provides usage techniques, diagnostic tips, andanswers to frequently asked questions.
Call Information Builders Customer Support Services (CSS) at (800) 736-6130 or (212)736-6130. Customer Support Consultants are available Monday through Friday between 8:00a.m. and 8:00 p.m. EST to address all your questions. Information Builders consultants canalso give you general guidance regarding product capabilities. Please be ready to provide yoursix-digit site code number (xxxx.xx) when you call.
Related Publications
6 Information Builders
To learn about the full range of available support services, ask your Information Buildersrepresentative about InfoResponse Online, or call (800) 969-INFO.
Help Us to Serve You Better
To help our consultants answer your questions effectively, be prepared to providespecifications and sample files and to answer questions about errors and problems.
The following table lists the environment information that our consultants require.
Platform
Operating System
OS Version
JVM Vendor
JVM Version
The following table lists the deployment information that our consultants require.
Adapter Deployment For example, JCA, Business Services Provider, iWayService Manager
Container For example, WebSphere
Version
Enterprise Information System(EIS) - if any
EIS Release Level
EIS Service Pack
EIS Platform
The following table lists iWay-related information needed by our consultants.
iWay Adapter
Preface
iWay XML Archive User's Guide 7
iWay Release Level
iWay Patch
The following table lists the types of iWay Explorer. Specify the version (and platform, ifdifferent than listed previously) in the columns provided.
iWay Explorer Type Version Platform
Swing
Servlet
Eclipseࡊ
Embedded in iWay Designer
The following table lists additional questions to help us serve you better.
Request/Question Error/Problem Details or Information
Did the problem arise througha service or event?
Provide usage scenarios orsummarize the application thatproduces the problem.
When did the problem start?
Can you reproduce thisproblem consistently?
Describe the problem.
Describe the steps toreproduce the problem.
Specify the error message(s).
Help Us to Serve You Better
8 Information Builders
Request/Question Error/Problem Details or Information
Any change in the applicationenvironment: softwareconfiguration, EIS/databaseconfiguration, application, andso forth?
Under what circumstance doesthe problem not occur?
Following is a list of error/problem files that might be applicable.
Input documents (XML instance, XML schema, non-XML documents)
Transformation files
Error screen shots
Error output files
Trace files
Service Manager package to reproduce problem
Custom functions and services in use
Diagnostic Zip
Transaction log
For information on tracing, see the iWay Service Manager User's Guide.
User Feedback
In an effort to produce effective documentation, the Technical Content Management staffwelcomes your opinions regarding this document. You can contact us through our website, http://documentation.informationbuilders.com/connections.asp.
Thank you, in advance, for your comments.
Information Builders Consulting and Training
Interested in training? Information Builders Education Department offers a wide variety oftraining courses for this and other Information Builders products.
Preface
iWay XML Archive User's Guide 9
For information on course descriptions, locations, and dates, or to register for classes, visitour website (http://education.informationbuilders.com) or call (800) 969-INFO to speak to anEducation Representative.
Information Builders Consulting and Training
10 Information Builders
Chapter1Installing the iWay XML Archive
This section discusses the installation and configuration of the iWay XML Archive. Itassumes a Windows-based installation, but the iWay XML Archive is also supported onthe Linux and UNIX® operating systems. You can use the sample values provided tocreate a sample configuration.
In this chapter:
iWay XML Archive Installation Requirements
Installing iWay Service Manager
Installing mongoDB
Configuring the iWay XML Archive Application
Verifying the iWay XML Archive Installation
iWay XML Archive Installation Requirements
The following software is required:
iWay Service Manager (iSM) Version 7.0 and higher.
The iSM installation also requires the iWayXMLArchive.iia binary file to support the iWayXML Archive application. To obtain the required application binary file, contact InformationBuilders Technical Support at http://techsupport.iwaysoftware.com.
MongoDB® 1.8.0 or higher for a 32-bit or 64-bit environment. You can download mongoDBfrom:
http://www.mongodb.com/downloads
Mongo® Java driver version 2.5, which you can download from:
https://mvnrepository.com/artifact/org.mongodb/mongo-java-driver/2.5.3.
Note: There are known issues when using Mongo Java driver version 2.7.3. It isrecommended to use Mongo Java driver version 2.5, which has been used for iWay XMLArchive certification.
In addition, the end user must agree to the Apache License Version 2.0, found at:
iWay XML Archive User's Guide 11
http://apache.org/licenses/LICENSE-2.0
Installing iWay Service Manager
To install iWay Service Manager (iSM):
1. Run the iSM 7.0 installation.
2. During the installation, select the iWay XML Archive Extensions category.
3. Copy the mongo-2.5.jar file (or higher) to the iwayhome\lib directory.
4. Start the iSM service.
Note: For a complete set of installation instructions, see the iWay Installation and ConfigurationGuide.
Installing mongoDB
To install mongoDB:
1. Create a new directory to store the mongo binary files. For example, c:\mongo.
Note: It is recommended that you put the mongoDB directories outside of the iSMinstallation directories. If you need to reinstall iSM, the directories will not be erased.
2. Extract the downloaded mongoDB ZIP file to the c:\mongo directory.
3. Create a new directory to store the mongoDB data. For example, c:\mongo\data\db.
4. As an administrator, open a command prompt, and navigate to the c:\mongo\mongodb-architecture_version\bin directory.
5. At the administrator command prompt, type the following command:
mongod –-install --dbpath c:\mongo\data\db –logpath c:\mongo\log.txt
6. Start the mongo service, and verify that it is set to autostart.
Note: You can start the mongo service from the command line, which is useful fordebugging purposes. Type the following at the command prompt:
mongod --dbpath c:\mongo\data\db
Configuring the iWay XML Archive Application
The following procedures describe how to configure the iWay XML Archive Application.
Installing iWay Service Manager
12 Information Builders
Procedure: How to Configure the iWay XML Archive Application
1. From the iSM Console, click the Management link, as shown in the following image.
2. Click Applications, as shown in the following image.
3. From the Applications list, select Deploy for the application named iWayXMLArchive.
1. Installing the iWay XML Archive
iWay XML Archive User's Guide 13
4. Leave iWayXMLArchive selected, and click Deploy, as shown in the following image.
Once the application has been deployed, you are automatically switched to theDeployments link on the left.
5. Click the eye icon next to the iWayXMLArchive deployment, shown in the image below.
Configuring the iWay XML Archive Application
14 Information Builders
6. Click the Bindings tab. You will see that each register has a red asterisk next to it.
7. Select each register in order, and type the correct values, as follows:
ArchivReg.LISTENER_INPUT. The directory on disk from which a file listener reads XMLdocuments to put into the archive. For example,c:\mongo\input. You need to createthis directory.
ArchiveReg.LISTENER_DESTINATION. The directory to which the XML files are movedafter being processed. For example, c:\mongo\destination. You need to create thisdirectory.
ArchiveReg.DB_HOST. The name of the machine that hosts mongo. For example,localhost.
ArchiveReg.DB_PORT. The port number of the host machine that the mongo instanceis listening on. For example, the default value is27017.
ArchiveReg.DB_NAME. The name of the database that stores the XML data. Thedatabase is created for you. For example, FedReg.
ArchiveReg.COLLECTION_NAME. The name of the collection that stores the XML data.This is analogous to a table in an RDBMS system. For example, xml.
1. Installing the iWay XML Archive
iWay XML Archive User's Guide 15
ArchiveReg.TEST_CLIENT_LOCATION. The location of the sample user interface. Forexample, set it to _sreg(iwayworkdir)/resource/client.
Neither id or query should exist. You do not need to set them.
8. Start the iWayXMLArchive configuration by navigating to youriwayhome directory and typingthe following at a command prompt:
iway7.cmd iWayXMLArchive
Verifying the iWay XML Archive Installation
To verify the installation:
1. Download the following ZIP file, which contains large XML documents from the FederalRegister:
http://www.gpo.gov/fdsys/bulkdata/FR/2010/12/FR-2010-12.zip
2. Extract the contents to the c:\mongo\input directory. The listener starts to pick up each fileand process it.
3. Start a web browser, and point to http://localhost:2222.
4. Click Search, and verify that there are 21 results returned.
Verifying the iWay XML Archive Installation
16 Information Builders
Chapter2Using the iWay XML Archive
The iWay XML Archive is an XML document storage system that you can use to efficientlystore, query, and retrieve a large number of XML documents.
In this chapter:
iWay XML Archive Architecture
XML and JSON
Loading Documents
Making Requests
The Query String
Query Grammar
Understanding the JSON Results
Returning XML Documents
Returning a Slice of XML With XQuery
iWay XML Archive Architecture
For efficient storage and retrieval, the XML documents are first converted to BSON (BinaryJSON) and stored in a mongoDB collection. A reference to the original XML document itself isthen attached to the mongoDB document, and then stored using the mongoDB GridFS system.
You can then query and retrieve documents using web services hosted in iSM. The queries areJava Script Object Notation (JSON) like and hierarchical. They return either the JSONrepresentation or the full XML document. In addition to retrieving a full XML document, you canapply an XQuery to a document and retrieve a part of it.
XML and JSON
The conversion to JSON from XML changes the structure of the document. Take this intoaccount when making hierarchical queries. The primary structural change is that attributesbecome elements in JSON, and the content of a mixed element is set in a content key.
For example, consider the following XML document:
iWay XML Archive User's Guide 17
<?xml version="1.0" encoding="UTF-8"?> <a name="bob"> <b>testA</b> <c>12345</c> </a>
After the conversion, the following corresponding JSON document is created:
{ "a":{ "b":"testA", "c":"12345", "name":"bob" }}
Another example in which the <a> element has content is as follows:
<?xml version="1.0" encoding="UTF-8"?> <a name="bob"> <b>testA</b> <c>12345</c> Test </a>
After the conversion, the following corresponding JSON document is created:
{ "a":{ "content":"\nTest", "b":"testA", "c":"12345", "name":"bob" }}
Loading Documents
In the default configuration, documents are loaded using a file listener listening to a folder inthe local file system. An XML document of any schema can be dropped into this folder andloaded into the archive.
For details on how to configure this location, see Configuring the iWay XML Archive Applicationon page 12.
Making Requests
The iWay XML Archive handles requests through an HTTP listener on port 2222 in the defaultconfiguration. The requests are made using a properly encoded URL of the following format:
Loading Documents
18 Information Builders
http://host:port/?querystring
where:
hostIs the name of the machine on which the iWay XML Archive is installed and configured. Thedefault value is localhost.
portIs the number of the port that the iWay XML Archive is listening on. The default value is2222.
querystringIs the query.
The sample queries are encoded and can be executed from any web browser by cutting andpasting them into the address bar. The results are then displayed in the browser. If you areusing Internet Explorer® or Mozilla Firefox, you will be asked to either save or open theresulting document. You can then use a text editor to view the results.
The Query String
The query string contains variables that are used to specify query arguments or indicate thetype of query. The primary query variable is the word query. All queries use a JSON-typestructure.
A basic example that returns the _id key value pairs for every record in the database is:
http://localhost:2222/?query={},{%22_id%22:1}
If you cut and paste this URL into the Google Chrome browser, you will see a result similar tothe following. The number of results varies, depending on the number of records in your datastore.
{ "retval" : [ { "_id" : { "$oid" : "4d068547e818f7cba1b63688"}} , { "_id" : { "$oid" : "4d06852ee818f7cb95b63688"}} , { "_id" : { "$oid" : "4d068532e818f7cb97b63688"}} , { "_id" : { "$oid" : "4d068535e818f7cb98b63688"}} , { "_id" : { "$oid" : "4d068545e818f7cba0b63688"}} , { "_id" : { "$oid" : "4d068550e818f7cba6b63688"}}] , "ok" : 1.0}
Adding the {"_id":1} limit to the query is a good practice if you want to retrieve the XML in asubsequent query. If this limit is omitted from the query, the full JSON representation will bereturned for each result. If the records are large, this could significantly decrease performance.
2. Using the iWay XML Archive
iWay XML Archive User's Guide 19
Query Grammar
The contents of a query are a set of key-value pairs. You can join multiple pairs together toform and or ortype queries. Furthermore, you can also use regular expressions for the valuepart of a pair.
Searching Elements
Consider the following XML document:
<?xml version="1.0" encoding="UTF-8"?> <a> <b>test</b> <c>12345</c> </a>
To find all document ids for which the value of <b> is equal to test, use the search string{"a.b":"test"} ,{"_id":1}. The HTTP request is as follows:
http://localhost:2222/?query={%22a.b%22:%22test%22},{%22_id%22:1}
Searching Attributes
In the iWay XML Archive, XML documents are first converted to JSON before they are loadedinto the archive. This notation is used for storage and retrieval efficiency. Changes that convertattributes to child elements are made to the XML structure to support this notation.
Example: Attribute Search
Consider the following XML document:
<?xml version="1.0" encoding="UTF-8"?> <a name="bob"> <b>test</b> <c>12345</c> </a>
To find all document ids for which the value of the name attribute is equal to bob, use thesearch string {"a.name":"bob"} ,{"_id":1}. The HTTP request is as follows:
http://localhost:2222/?query={%22a.name%22:%22bob%22},{%22_id%22:1}
Searching on Multiple Keys (and)
To search for a document based on multiple keys, type comma-delimited, key-value pairs in thesearch box. This is similar to an and in a SQL where clause.
Query Grammar
20 Information Builders
Example: Multiple Key Search
Consider the following XML document:
<?xml version="1.0" encoding="UTF-8"?> <a name="bob"> <b>test</b> <c>12345</c> </a>
To find all documents in which the name attribute of <a> is equal to bob and the value of <b>is equal totest, type {"a.name":"bob","a.b":"test"},{"_id":1}. The HTTP request is as follows:
http://localhost:2222/?query={%22a.name%22:%22bob%22,%22a.b%22:%22test%22},{%22_id%22:1}
Advanced Queries
The iWay XML Archive query language is based on the mongoDB query language. Many of theadvanced queries are supported. Some of the advanced queries require extra operators tocomplete, such as the or query. For more information on the mongoDB advanced queries, see http://www.mongodb.org/display/DOCS/Advanced+Queries
Example: Advanced Query
Consider the following XML documents:
<?xml version="1.0" encoding="UTF-8"?> <a name="bob"> <b>test</b> <c>12345</c> </a>
<?xml version="1.0" encoding="UTF-8"?> <a name="bob"> <b>testA</b> <c>12345</c> </a>
To find all document ids for which the value of <b> is equal to test or testA, use the followingsyntax:
{$or:[{"a.b":"test"},{"a.b":"testA"}]} ,{"_id":1}
The HTTP request is as follows:
http://localhost:2222/?query={$or:[{%22a.b%22:%22test%22},{%22a.b%22:%22testA%22}]},{%22_id%22:1}
2. Using the iWay XML Archive
iWay XML Archive User's Guide 21
Using Regular Expressions
You can use Pearl Compatible Regular Expressions (PCRE) for the value of a searchexpression. The expressions are not enclosed in quotation marks, and are bound between /(slash) characters. For more information on PCRE, see http://www.cs.tut.fi/~jkorpela/perl/regexp.html
Example: Regular Expression
Consider the following XML documents:
<?xml version="1.0" encoding="UTF-8"?> <a name="bob"> <b>test</b> <c>12345</c> </a>
<?xml version="1.0" encoding="UTF-8"?> <a name="bob"> <b>testA</b> <c>12345</c> </a>
To find all document ids for which the value of <b> contains the string test, type the followingsyntax
{"a.b":/test./},{"_id":1}
The HTTP request is as follows:
http://localhost:2222/?query={%22a.b%22:/test./},{%22_id%22:1}
Searching by _id
The previous examples limited the results of a search to return on the _id key-value pair. If thelimitation is removed, the entire JSON document is retrieved for each result. If you search for asingle id, you the entire JSON document for that id is retrieved. To execute a search by id, youmust use the mongoDB ObjectId class in your query.
For example, to return a document with the id "4d068547e818f7cba1b63688", type thefollowing search term:
{"_id":new ObjectId("4d068547e818f7cba1b63688")}
The HTTP request is as follows:
http://localhost:2222/?query={%22_id%22:new%20ObjectId(%224d49af7ce5397929bad5421e%22)}
Query Grammar
22 Information Builders
Understanding the JSON Results
The following document is returned from a search for a particular id.
{ "retval":[ { "_id":{ "$oid":"4d49af7ce5397929bad5421e" } , "a":{ "b":"test", "c":"12345", "name":"bob" } , "xml":{ "_id":{ "$oid":"4d49af7ce5397929b8d5421e" } , "chunkSize":262144, "length":80, "md5":"2fd2fece0f2c73ef073436d3e2638922", "filename":null, "contentType":"application/xml", "uploadDate":{ "$date":"2011-02-02T19:24:44Z" } , "aliases":null } } ] , "ok":1.0}
The results of a search against the mongoDB are all returned in JSON format and are stored inthe retval array. This array will contain multiple result objects if the search was not for a singleid.
The JSON result also contains two additional keys. The first is the _id key, which is the uniqueid assigned by mongoDB to the record. The second is the xml key. The xml key storesreference information in the XML file in the GridFS system.
Returning XML Documents
Once the set of documents of interest has been identified, you can use the _id value toretrieve the XML document associated with the record. The query uses the query variablesquery and xml. For example,
2. Using the iWay XML Archive
iWay XML Archive User's Guide 23
http://localhost:2222/?query={"_id":new ObjectId("4d484fcfe7bd792987408a76")}&xml=true
The xml=true switch causes the archive to first look up the location of the XML document usingthe value of _id. It then retrieves the document from the file system.
Returning a Slice of XML With XQuery
Instead of retrieving the full XML document, you can apply an XQuery and retrieve the resultingpartial document. To execute an XQuery, you must set the xquery and xml query variables.
Consider this XML document:
<?xml version="1.0" encoding="UTF-8"?> <a name="bob"> <b>test</b> <c>12345</c> </a>
The following query,
?query={"_id":new ObjectId("4d484fcfe7bd792987408a76"}&xquery=for$x in /a return $x/b&xml=true
returns the following:
<?xml version="1.0" encoding="UTF-8" ?><XQueryResult> <item> <b>test</b> </item></XQueryResult>
The HTTP request is as follows:
http://localhost:2222/?query={%22_id%22:new%20ObjectId(%224d49af7ce5397929bad5421e%22)}&xquery=for%20$x%20in%20/a%20return%20$x/b&xml=true
For more information on XQuery, see the XQuery agent documentation.
Returning a Slice of XML With XQuery
24 Information Builders
Chapter3Using the iWay XML Archive Test Client
Queries can be made against the iWay XML Archive using an HTTP interface that wrapsthe mongoDB query language.
Application of an XQuery against a document retrieved in a search is also supported,using some additional options in the HTTP request.
In this chapter:
Test Client Overview
Query Grammar in the Test Client
Test Client Overview
The iWay XML Archive Test Client is a web-based AJAX application used to search the iWayXML Archive and retrieve XML documents. The client interface wraps a mongoDBdb.collection.find() method. The Key:Value field becomes the contents of the find method.Consider the following example, shown in the image below.
This example results in a mongoDB query of db.xml.find({"FEDREG.VOL":"75"}). The additionalquery options for field selection, sorting, skip, limit, and cursors, are not supported in the HTTPrequest sent from the Test Client. However, these types of queries can be made from a moreintelligent client.
The client also supports applying an XQuery to the set of documents retrieved through thesearch. This is done by checking the Apply XQuery: check box and typing a query string in theXQuery to apply: input box as shown in the following image:
The client is an example of one of the many ways in which you can use the archive. In thedefault installation of the iWay XML Archive, the Test Client can be found at http://localhost:2222.
iWay XML Archive User's Guide 25
This section describes the use of the iWay XML Archive Test Client and some basics of thequery grammar.
You can find more information about the mongoDB query language at:
http://www.mongodb.org/display/DOCS/Querying
Query Grammar in the Test Client
The following topics provide the basics of query grammar used in the Test Client.
Searching Elements in the Test Client
The following image shows the iWay Archive Search query page.
Specify the query in the Key:Value search box to search the archive. The Key portion of thequery consists of the hierarchical element structure that you wish to query. The Key must besurrounded by double quotation marks. The Value portion consists of the value that theelement must match. If the value is a string, it must be surrounded by double quotation marks.If the value is numeric, do not use quotation marks.
Example: Element Search
Consider the following XML document:
<?xml version="1.0" encoding="UTF-8"?> <a> <b>test</b> <c>12345</c> </a>
Query Grammar in the Test Client
26 Information Builders
Typing "a.b":"test" retrieves all documents whose <b> element is equal to the string "test".The following image shows the results in the Test Client.
Searching Attributes in the Test Client
In the iWay XML Archive, XML documents are first converted to JSON (Java Script ObjectNotation) before they are loaded into the archive. This notation is used for storage andretrieval efficiency. Changes that convert attributes to child elements are made to the XMLstructure to support this notation.
Example: Attribute Search
Consider the following XML document:
<?xml version="1.0" encoding="UTF-8"?> <a name="bob"> <b>test</b> <c>12345</c> </a>
3. Using the iWay XML Archive Test Client
iWay XML Archive User's Guide 27
Typing "a.name":"bob" retrieves all documents containing the name attribute of the <a>element that equals the string bob. The following image shows the results in the Test Client.
Searching on Multiple Keys (and) in the Test Client
To search for a document based on multiple keys, type comma-delimited, key-value pairs in theKey:Value search box. This is similar to an and in a SQL where clause.
Example: Multiple Key Search
Consider the following XML document:
<?xml version="1.0" encoding="UTF-8"?> <a name="bob"> <b>test</b> <c>12345</c> </a>
Query Grammar in the Test Client
28 Information Builders
Typing the search term "a.name":"bob","a.b":"test" returns all documents containing thename attribute of the <a> element that equals the string bob, and whose <a><b> elementvalue is equal to the string test. The following image shows the results in the Test Client.
Advanced Queries in the Test Client
Some queries require extra operators, such as an or query. Some of these advanced queriesare documented at:
http://www.mongodb.org/display/DOCS/Advanced+Queries
Example: Advanced Query
Consider the following XML documents:
<?xml version="1.0" encoding="UTF-8"?> <a name="bob"> <b>test</b> <c>12345</c> </a>
<?xml version="1.0" encoding="UTF-8"?> <a name="bob"> <b>testA</b> <c>12345</c> </a>
3. Using the iWay XML Archive Test Client
iWay XML Archive User's Guide 29
Typing the search term $or:[{"a.b":"test"},{"a.b":"testA"}] results in the return of bothdocuments, as shown in the following image. You can see that the $or key operator has thevalue of a JSON array with two JSON-formatted, Key:Value pair objects.
Using Regular Expressions in the Test Client
You can use Pearl Compatible Regular Expressions (PCRE) for the value of a searchexpression. The expressions are not enclosed in quotation marks, and are bound between /(slash) characters. For more information on PCRE, see http://www.cs.tut.fi/~jkorpela/perl/regexp.html.
Example: Regular Expression
Consider the following XML documents:
<?xml version="1.0" encoding="UTF-8"?> <a name="bob"> <b>test</b> <c>12345</c> </a>
Query Grammar in the Test Client
30 Information Builders
<?xml version="1.0" encoding="UTF-8"?> <a name="bob"> <b>testA</b> <c>12345</c> </a>
Typing "a.b.":/test.*/ returns all documents whose <a><b> element values contain the stringtest, even if there is text following test. The period (.) and asterisk (*) operators matchanything after the string test, 0 or more times.
Understanding the Results
The following image shows the results of an empty query, which returns all documents in thearchive.
3. Using the iWay XML Archive Test Client
iWay XML Archive User's Guide 31
The ID column of the result set contains the key for the record returned. This key can be usedin a query to retrieve one particular document. For more information, see Special Queries onpage 33. The XML column contains a link that returns the full XML document for the recordfrom the archive.
Applying an XQuery
You can apply an XQuery to a set of documents matching the mongoDB Key:Value query byselecting the Apply XQuery check box and typing a query in the XQuery to apply: field.
You can also apply an XQuery to an individual document in a result set by selecting the ApplyXQuery check box, and then clicking the xml link in the result set.
Information on XQuery is available at:
http://www.w3schools.com/xquery/default.asp
Example: XQuery
Consider the following XML documents:
<?xml version="1.0" encoding="UTF-8"?> <a name="bob"> <b>test</b> <c>12345</c> </a>
<?xml version="1.0" encoding="UTF-8"?> <a name="bob"> <b>testA</b> <c>12345</c> </a>
With a Key:Value query of "a.name":"bob" and an XQuery of for $x in /a return $x/b, two XMLdocuments are returned. The returned documents have the following format:
<?xml version="1.0" encoding="UTF-8"?><XQueryResult> <item>Return xml</item></XQueryResult>
The results are wrapped in an <XQueryResult><item> element, in case the query has multipleitems, and the root has been removed.
Query Grammar in the Test Client
32 Information Builders
An example of the query performed in the Test Client is shown in the following image.
Special Queries
The archive query language uses a special notation for querying ID or date fields. Date fieldsare a special case and must be defined to the archive prior to loading.
3. Using the iWay XML Archive Test Client
iWay XML Archive User's Guide 33
Querying an ID
The following image shows a search result of two records.
Query Grammar in the Test Client
34 Information Builders
Given the preceding search results, to retrieve just the third record in the list, type "_id":newObjectId("4d01274ce4e6cb0bf5d2e0cc") in the Key:Value field. The following image showsthe results.
3. Using the iWay XML Archive Test Client
iWay XML Archive User's Guide 35
Query Grammar in the Test Client
36 Information Builders
FeedbackCustomer success is our top priority. Connect with us today!
Information Builders Technical Content Management team is comprised of many talentedindividuals who work together to design and deliver quality technical documentation products.Your feedback supports our ongoing efforts!
You can also preview new innovations to get an early look at new content products andservices. Your participation helps us create great experiences for every customer.
To send us feedback or make a connection, contact Sarah Buccellato, Technical Editor,Technical Content Management at [email protected].
To request permission to repurpose copyrighted material, please contact Frances Gambino,Vice President, Technical Content Management at [email protected].
Information Builders, Inc.Two Penn PlazaNew York, NY 10121-2898
iWay XML Archive User's GuideVersion 7.0.x and Higher
DN3502299.0418