Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 9th, 2005, 11:58 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default pick data from xml structure

I have this XML reply:

- <PoweredPNR_PNRReply>
- <pnrHeader>
- <reservationInfo>
- <reservation>
  <companyId>1A</companyId>
  <controlNumber>YWXZ3G</controlNumber>
  <date>090205</date>
  <time>1417</time>
  </reservation>
  </reservationInfo>
  </pnrHeader>
- <securityInformation>
- <responsibilityInformation>
  <typeOfPnrElement>RP</typeOfPnrElement>
  <agentId>AASU</agentId>
  <officeId>LONU128VL</officeId>
  </responsibilityInformation>
- <queueingInformation>
  <queueingOfficeId>LONU128VL</queueingOfficeId>
  </queueingInformation>
  <cityCode>AGY</cityCode>
- <secondRpInformation>
  <creationOfficeId>LONU128VL</creationOfficeId>
  <agentSignature>0001AA</agentSignature>
  <creationDate>090205</creationDate>
  <creationTime>1417</creationTime>
  </secondRpInformation>
  </securityInformation>
- <travellerInfo>
- <elementManagementPassenger>
- <reference>
  <qualifier>PT</qualifier>
  <number>11</number>
  </reference>
  <segmentName>NM</segmentName>
  <lineNumber>1</lineNumber>
  </elementManagementPassenger>
- <travellerInformation>
- <traveller>
  <surname>TESTCRMTEST</surname>
  <quantity>1</quantity>
  </traveller>
- <passenger>
  <firstName>AMR</firstName>
  <type>ADT</type>
  </passenger>
  </travellerInformation>
  </travellerInfo>
- <originDestinationDetails>
  <originDestination />
- <itineraryInfo>
- <elementManagementItinerary>
- <reference>
  <qualifier>ST</qualifier>
  <number>1</number>
  </reference>
  <segmentName>AIR</segmentName>
  <lineNumber>2</lineNumber>
  </elementManagementItinerary>
- <travelProduct>
- <product>
  <depDate>100505</depDate>
  <depTime>0610</depTime>
  <arrDate>100505</arrDate>
  <arrTime>0900</arrTime>
  </product>
- <boardpointDetail>
  <cityCode>GLA</cityCode>
  </boardpointDetail>
- <offpointDetail>
  <cityCode>AMS</cityCode>
  </offpointDetail>
- <companyDetail>
  <identification>KL</identification>
  </companyDetail>
- <productDetails>
  <identification>1470</identification>
  <classOfService>L</classOfService>
  </productDetails>
- <typeDetail>
  <detail>ET</detail>
  </typeDetail>
  </travelProduct>
- <itineraryMessageAction>
- <business>
  <function>1</function>
  </business>
  </itineraryMessageAction>
- <relatedProduct>
  <quantity>1</quantity>
  <status>HK</status>
  </relatedProduct>
- <flightDetail>
- <productDetails>
  <equipment>100</equipment>
  <numOfStops>0</numOfStops>
  <weekDay>2</weekDay>
  </productDetails>
- <departureInformation>
  <departTerminal>M</departTerminal>
  </departureInformation>
  </flightDetail>
- <selectionDetails>
- <selection>
  <option>P2</option>
  </selection>
  </selectionDetails>
  </itineraryInfo>
- <itineraryInfo>
- <elementManagementItinerary>
- <reference>
  <qualifier>ST</qualifier>
  <number>2</number>
  </reference>
  <segmentName>AIR</segmentName>
  <lineNumber>3</lineNumber>
  </elementManagementItinerary>
- <travelProduct>
- <product>
  <depDate>100505</depDate>
  <depTime>0955</depTime>
  <arrDate>100505</arrDate>
  <arrTime>1205</arrTime>
  </product>
- <boardpointDetail>
  <cityCode>AMS</cityCode>
  </boardpointDetail>
- <offpointDetail>
  <cityCode>BCN</cityCode>
  </offpointDetail>
- <companyDetail>
  <identification>KL</identification>
  </companyDetail>
- <productDetails>
  <identification>1671</identification>
  <classOfService>L</classOfService>
  </productDetails>
- <typeDetail>
  <detail>ET</detail>
  </typeDetail>
  </travelProduct>
- <itineraryMessageAction>
- <business>
  <function>1</function>
  </business>
  </itineraryMessageAction>
- <relatedProduct>
  <quantity>1</quantity>
  <status>HK</status>
  </relatedProduct>
- <flightDetail>
- <productDetails>
  <equipment>737</equipment>
  <numOfStops>0</numOfStops>
  <weekDay>2</weekDay>
  </productDetails>
  </flightDetail>
- <selectionDetails>
- <selection>
  <option>P2</option>
  </selection>
  </selectionDetails>
  </itineraryInfo>
- <itineraryInfo>
- <elementManagementItinerary>
- <reference>
  <qualifier>ST</qualifier>
  <number>3</number>
  </reference>
  <segmentName>AIR</segmentName>
  <lineNumber>4</lineNumber>
  </elementManagementItinerary>
- <travelProduct>
- <product>
  <depDate>300505</depDate>
  <depTime>0625</depTime>
  <arrDate>300505</arrDate>
  <arrTime>0850</arrTime>
  </product>
- <boardpointDetail>
  <cityCode>BCN</cityCode>
  </boardpointDetail>
- <offpointDetail>
  <cityCode>AMS</cityCode>
  </offpointDetail>
- <companyDetail>
  <identification>KL</identification>
  </companyDetail>
- <productDetails>
  <identification>1664</identification>
  <classOfService>L</classOfService>
  </productDetails>
- <typeDetail>
  <detail>ET</detail>
  </typeDetail>
  </travelProduct>
- <itineraryMessageAction>
- <business>
  <function>1</function>
  </business>
  </itineraryMessageAction>
- <relatedProduct>
  <quantity>1</quantity>
  <status>HK</status>
  </relatedProduct>
- <flightDetail>
- <productDetails>
  <equipment>737</equipment>
  <numOfStops>0</numOfStops>
  <weekDay>1</weekDay>
  </productDetails>
- <departureInformation>
  <departTerminal>A</departTerminal>
  </departureInformation>
  </flightDetail>
- <selectionDetails>
- <selection>
  <option>P2</option>
  </selection>
  </selectionDetails>
  </itineraryInfo>
- <itineraryInfo>
- <elementManagementItinerary>
- <reference>
  <qualifier>ST</qualifier>
  <number>4</number>
  </reference>
  <segmentName>AIR</segmentName>
  <lineNumber>5</lineNumber>
  </elementManagementItinerary>
- <travelProduct>
- <product>
  <depDate>300505</depDate>
  <depTime>1355</depTime>
  <arrDate>300505</arrDate>
  <arrTime>1435</arrTime>
  </product>
- <boardpointDetail>
  <cityCode>AMS</cityCode>
  </boardpointDetail>
- <offpointDetail>
  <cityCode>GLA</cityCode>
  </offpointDetail>
- <companyDetail>
  <identification>KL</identification>
  </companyDetail>
- <productDetails>
  <identification>1477</identification>
  <classOfService>L</classOfService>
  </productDetails>
- <typeDetail>
  <detail>ET</detail>
  </typeDetail>
  </travelProduct>
- <itineraryMessageAction>
- <business>
  <function>1</function>
  </business>
  </itineraryMessageAction>
- <relatedProduct>
  <quantity>1</quantity>
  <status>HK</status>
  </relatedProduct>
- <flightDetail>
- <productDetails>
  <equipment>737</equipment>
  <numOfStops>0</numOfStops>
  <weekDay>1</weekDay>
  </productDetails>
  </flightDetail>
- <selectionDetails>
- <selection>
  <option>P2</option>
  </selection>
  </selectionDetails>
  </itineraryInfo>
  </originDestinationDetails>
- <segmentGroupingInfo>
  <groupingCode>CNX</groupingCode>
- <marriageDetail>
  <tatooNum>1</tatooNum>
  </marriageDetail>
- <marriageDetail>
  <tatooNum>2</tatooNum>
  </marriageDetail>
  </segmentGroupingInfo>
- <segmentGroupingInfo>
  <groupingCode>CNX</groupingCode>
- <marriageDetail>
  <tatooNum>3</tatooNum>
  </marriageDetail>
- <marriageDetail>
  <tatooNum>4</tatooNum>
  </marriageDetail>
  </segmentGroupingInfo>
- <dataElementsMaster>
  <marker2 />
- <dataElementsIndiv>
- <elementManagementData>
- <reference>
  <qualifier>OT</qualifier>
  <number>16</number>
  </reference>
  <segmentName>AP</segmentName>
  <lineNumber>6</lineNumber>
  </elementManagementData>
- <otherDataFreetext>
- <freetextDetail>
  <subjectQualifier>3</subjectQualifier>
  <type>4</type>
  </freetextDetail>
  <longFreetext>AGENCY : DONALD MACKENZIE TRAVEL</longFreetext>
  </otherDataFreetext>
  </dataElementsIndiv>
- <dataElementsIndiv>
- <elementManagementData>
- <reference>
  <qualifier>OT</qualifier>
  <number>15</number>
  </reference>
  <segmentName>TK</segmentName>
  <lineNumber>7</lineNumber>
  </elementManagementData>
- <ticketElement>
- <ticket>
  <indicator>OK</indicator>
  <date>090205</date>
  <officeId>LONU128VL</officeId>
  </ticket>
  </ticketElement>
  </dataElementsIndiv>
- <dataElementsIndiv>
- <elementManagementData>
- <reference>
  <qualifier>OT</qualifier>
  <number>18</number>
  </reference>
  <segmentName>RM</segmentName>
  <lineNumber>8</lineNumber>
  </elementManagementData>
- <miscellaneousRemarks>
- <remarks>
  <type>RM</type>
  <category>F</category>
  <freetext>ADULT NETNET:134,GROSS:169,TAX:69.70,ADDON:35,WKEND:0,FU EL:0,MRKUP:0,AGYMRKUP:0,FEE:0,TTL:273.70,CID/CTC: 39/IT5AFKLE</freetext>
  </remarks>
  </miscellaneousRemarks>
  </dataElementsIndiv>
- <dataElementsIndiv>
- <elementManagementData>
- <reference>
  <qualifier>OT</qualifier>
  <number>19</number>
  </reference>
  <segmentName>RM</segmentName>
  <lineNumber>9</lineNumber>
  </elementManagementData>
- <miscellaneousRemarks>
- <remarks>
  <type>RM</type>
  <freetext>*MK/AGENCY:MK/AGENT:MK01</freetext>
  </remarks>
  </miscellaneousRemarks>
  </dataElementsIndiv>
- <dataElementsIndiv>
- <elementManagementData>
- <reference>
  <qualifier>OT</qualifier>
  <number>0</number>
  </reference>
  <segmentName>ES</segmentName>
  </elementManagementData>
- <pnrSecurity>
- <security>
  <identification>GLAU12106</identification>
  <accessMode>B</accessMode>
  </security>
- <securityInfo>
  <creationDate>090205</creationDate>
  <agentCode>AASU</agentCode>
  <officeId>LONU128VL</officeId>
  </securityInfo>
  <indicator>G</indicator>
  </pnrSecurity>
  </dataElementsIndiv>
  </dataElementsMaster>
  </PoweredPNR_PNRReply>

_______________________________________

How do i pick data from it?

I want to get out:

<freetext>ADULT NETNET:134,GROSS:169,TAX:69.70,ADDON:35,WKEND:0,FU EL:0,MRKUP:0,AGYMRKUP:0,FEE:0,TTL:273.70,CID/CTC: 39/IT5AFKLE</freetext>

Thanks.

Picco


www.crmpicco.co.uk
__________________
_______________________
Ayrshire Minis - a Mini E-Community
http://www.ayrshireminis.com
http://www.crmpicco.co.uk
 
Old February 24th, 2005, 06:19 AM
Registered User
 
Join Date: Feb 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi picco

Well i used sax parser and got the text out, but it looks like there are 2 freetext tag, so i guess both freetext will be printed, but you can match the string and get if you want only one freetext tag, anyway here is the code for printing both the freetext tag,


import org.xml.sax.Attributes;
import org.xml.sax.helpers.DefaultHandler;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.SAXParser;
import java.io.File;
import java.io.IOException;


public class SampleXML extends DefaultHandler
{
    public static void main(String[] args) throws Exception
    {
        SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
        SAXParser saxParser = saxParserFactory.newSAXParser();
        SampleXML xml = new SampleXML();
        saxParser.parse(new File("testxml.xml"), xml);
    }
    boolean isTitle;
    public void startElement(String uri, String localName, String qName, Attributes atts)
    {
        if(qName.equals("freetext"))
        {
            isTitle = true;
            System.out.println("<" + qName + ">");
        }
    }
    public void endElement(String uri, String localName, String qName)
    {
        if(qName.equals("freetext"))
        {
            isTitle = false;
            System.out.println("</" + qName + ">");
        }
    }
    public void characters(char[] chars, int start, int length)
    {
        if(isTitle)
        {
            System.out.println(new String(chars, start, length));
        }
    }
}

The output of the above program is shown below,

C:\Test>java SampleXML

<freetext>
ADULT NETNET:134,GROSS:169,TAX:69.70,ADDON:35,WKEND:0,FU EL:0,MRKUP:0,AGYMRKUP:0,
FEE:0,TTL:273.70,CID/CTC: 39/IT5AFKLE
</freetext>
<freetext>
*MK/AGENCY:MK/AGENT:MK01
</freetext>

I hope this helps.

-viks



 
Old December 1st, 2006, 11:01 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

wow, its been a while since i've seen Java :-)
thanks

www.crmpicco.co.uk
www.ie7.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Directory structure to XML. harshm XML 2 March 8th, 2013 04:55 PM
problem in e-mail structure sending data from data tiawebchd General .NET 3 May 5th, 2008 08:07 AM
XML structure for easy XSLT coldstar XSLT 2 September 10th, 2006 04:09 PM
backslash in XML structure crmpicco Classic ASP Basics 0 May 3rd, 2005 06:45 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.