How to parse this xml
Hi Guys
I have the following xml file.
<scms:TokenDescription xmlns:scms="http://www./schema/2003/07/Passage/scms.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="SID33322800" ATR="asdfafasdfdafdasfsda" FormatVersion="1.0">
<Token SerialNumber="123456789" SmartChipSN="3232323232">
<KeySetVersion>99</KeySetVersion>
<SecurityDomainAID>fdfasfsadfsdaf</SecurityDomainAID>
<AuthenticationKey>fdasfdasfdsafsda</AuthenticationKey>
<MACKey>fdasfdsafdsaf</MACKey>
<KeyEncryptionKey>asdfasdfasdfsdafa</KeyEncryptionKey>
<DefaultPUK>fdsafsdafsdfdsafasd</DefaultPUK>
</Token>
</scms:TokenDescription>I have managed to read the xml fine and bind it manuall to an object as follows:
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse (new File("xml.xml"));
NodeList keySetVersion = firstPersonElement.getElementsByTagName("KeySetVersion");
Element firstNameElement = (Element)keySetVersion.item(0);
NodeList textFNList = firstNameElement.getChildNodes();
System.out.println("keySetVersion : " +
((Node)textFNList.item(0)).getNodeValue().trim());My Question is can anyone tell me how i can read this part of the xml from this document the serial number and smartChipSN
<Token SerialNumber="123456789" SmartChipSN="3232323232">
Try this code,
Nodelist nList = doc.getElementByTagName("Token ") ;
Element node = (Element)nList.item(0);
To read the values of "SerialNumber" and "SmartChipSN", you can use getAttribute method.
String serailNo = node.getAttribute("SerialNumber");
String chipSN = node.getAttribute("SmartChipSN");
Similar Messages
-
I need to get the complete element including tag. How to parse this xml?
I am sure there should be some solution to this. I have XML file like this
<test>
<data value="123" color="RED">
<type>single</type>
</data>
<data value="13323" color="BLUE">
<type>double</type>
</data>
</test>
I need to parse this XML and get the data element(s). The problem is that I need to get the complete data element include tags like
"<data value="123" color="RED"><type>single</type></data>". I need to parse the complete XML file and get every data element including tag and send it to another upstream process.
Any solution to this will be appreciated. I am little familiar with SAX. Is there any solution around using xerces SAX parser.
Other solution is also appreciated.
ThanksDocumentBuilder builder = factory.newDocumentBuilder();
document = builder.parse(srcFile);
NodeList list = document.getElementsByTagName("data");
Node node = list.item(0); // Loop this
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
DOMSource source = new DOMSource(node);
StreamResult result = new StreamResult(outputstream);
transformer.transform(source, result);
Using XSLT will be lot easier.No it won't. Extending DefaultHandler is easy.Do you really think so?
Hardly 10-15 lines. -
How can parse this xml tag " Cell ID="0" Type="String" Afghanistan cell "
Hi,
I have to parse this type of xml file.
so how can i parse this type of xml file like
<Row ID="1">
<Cell ID="0" Type="String" >Afghanistan</Cell>
<Cell ID="1" Type="Number" >93</Cell>
<Cell ID="2" Type="Number" >0</Cell>
<Cell ID="3" Type="Number" >1</Cell>
</Row>You haven't given us enough information. Is this for iPhone or Mac OS X? What language are you using? etc.
-
How to Parse this XML File and require below mentioned value as output using powershell script
Need values for below as an output for below xml file so help me with the script:
Under Criteria Tag-
TimeStamp Display Value
OID corresponding to display value for nodes "Criterion"
Under Report Body Tag--
name in Report Section and OID value
<?xml version="1.0" encoding="UTF-8"?>
<ReportOutput>
<ReportHead>
<Report name="Execution Action" type="detailedchanges_rpt">
<Description></Description>
</Report>
<Criteria>
<TimestampCriterion name="date" displayvalue="08/10/14 23:08">
<Timestamp displayvalue="08/10/14 23:08">1412780929000</Timestamp>
</TimestampCriterion>
<MatchCriterion name="approvalId" displayvalue="Not applied" operator="contains" />
<MatchCriterion name="promotionComment" displayvalue="Not applied" operator="contains" />
<SelectCriterion name="changeWindow" displayvalue="Not applied" />
<SelectCriterion name="auditEvents" displayvalue="(Any)">
<String>auditEventAny</String>
</SelectCriterion>
<SelectCriterion name="attributeDisplay" displayvalue="Changed attributes">
<String>changed</String>
</SelectCriterion>
<SelectCriterion name="versionCompare" displayvalue="Version with current baseline">
<String>disabled</String>
</SelectCriterion>
<BooleanCriterion name="showContentDiff" displayvalue="No">
<Boolean value="false" />
</BooleanCriterion>
<BooleanCriterion name="displayUsers" displayvalue="No">
<Boolean value="false" />
</BooleanCriterion>
<BooleanCriterion name="displayPackages" displayvalue="No">
<Boolean value="false" />
</BooleanCriterion>
<BooleanCriterion name="displayCustomProperties" displayvalue="No">
<Boolean value="false" />
</BooleanCriterion>
<BooleanCriterion name="strictPackageMatch" displayvalue="No">
<Boolean value="false" />
</BooleanCriterion>
<BooleanCriterion name="displayCriteriaAtEnd" displayvalue="No">
<Boolean value="false" />
</BooleanCriterion>
<SelectCriterion name="elementExists" displayvalue="Not applied" />
<IntegerCriterion name="maxLinesPerBlock" displayvalue="10">
<Integer>10</Integer>
</IntegerCriterion>
<NodesCriterion name="nodes" displayvalue="TripwireENT.demo.net">
<OID>-1y2p0ij32e8bw:-1y2p0ij32e7cu</OID>
</NodesCriterion>
<MatchCriterion name="nodeName" displayvalue="Not applied" operator="contains" />
<CustomPropertiesCriterion name="nodeProps" displayvalue="Not applied" />
<RulesCriterion name="rules" displayvalue="Critical System Files">
<OID>-1y2p0ij32e7q2:-1y2p0ij31snh6</OID>
</RulesCriterion>
<MatchCriterion name="ruleName" displayvalue="Not applied" operator="contains" />
<MatchCriterion name="elementName" displayvalue="Not applied" operator="contains" />
<CustomPropertiesCriterion name="elementProps" displayvalue="Not applied" />
<CustomPropertiesCriterion name="versionProps" displayvalue="Not applied" />
<AttributesCriterion name="attributes" displayvalue="Not applied">
<Integer name=".missingImpliesFailure">1</Integer>
</AttributesCriterion>
<ContentCriterion name="content" displayvalue="Not applied" />
<MatchCriterion name="auditEventUserName" displayvalue="Not applied" operator="contains" />
<IntegerCriterion name="changeType" displayvalue="Added, Modified, Removed">
<Integer>7</Integer>
</IntegerCriterion>
<SeverityRangeCriterion name="severity" displayvalue="1 - 10000">
<Integer name="min">1</Integer>
<Integer name="max">10000</Integer>
</SeverityRangeCriterion>
<BooleanCriterion name="currentVersionsOnly" displayvalue="Yes">
<Boolean value="true" />
</BooleanCriterion>
<TimeRangeCriterion name="timeRange" displayvalue="All time" />
<PackagesCriterion name="packages" displayvalue="Not applied" />
<SortCriterion name="sortNodes" displayvalue="Name, ascending" isascending="true">
<String>name</String>
</SortCriterion>
<SortCriterion name="sortRules" displayvalue="Name, ascending" isascending="true">
<String>name</String>
</SortCriterion>
<SortCriterion name="sortElements" displayvalue="Name, ascending" isascending="true">
<String>name</String>
</SortCriterion>
<SortCriterion name="sortVersions" displayvalue="Date, descending" isascending="false">
<String>date</String>
</SortCriterion>
</Criteria>
</ReportHead>
<ReportBody>
<ReportSection name="TripwireENT.demo.net" category="node">
<OID>-1y2p0ij32e8bw:-1y2p0ij32e7cu</OID>
<String name="typeName">Windows Server</String>
<ReportSection name="Critical System Files" category="rule">
<OID>-1y2p0ij32e7q2:-1y2p0ij31snh6</OID>
<String name="typeName">Windows File System Rule</String>
<ReportSection name="C:\Temp" category="element">
<OID>-1y2p0ij32e8dr:-1y2p0ij32e586</OID>
<ReportSection name="08/10/14 22:48" category="version">
<OID>-1y2p0ij32e8du:-1y2p0ij32e3ho</OID>
<Integer name="changeType">1</Integer>
<String name="changeTypeName">Added</String>
<Integer name="severity">10000</Integer>
<String name="severityName">High</String>
<Timestamp name="changeTime" displayvalue="08/10/14 22:48">1412779682000</Timestamp>
<String name="approvalId"></String>
<ReportSection name="attributes" category="attributes">
<ReportSection name="DACL" category="added">
<String name="observed">Inherits Entries: true
NT AUTHORITY\SYSTEM, Access Allowed:
Standard rights:
Full Control
Modify
Read & Execute
List Folder Contents
Read
Write
Delete
Read Control
Write DAC
Write Owner
Synchronize
Specific rights:
Full Control
Traverse Folder / Execute File
List Folder / Read Data
Read Attributes
Read Extended Attributes
Create Files / Write Data
Create Folders / Append Data
Write Attributes
Write Extended Attributes
Directory Delete Child
Read Permissions
Change Permissions
Take Ownership
Header flags:
Object Inherit
Container Inherit
Inherited
BUILTIN\Administrators, Access Allowed:
Standard rights:
Full Control
Modify
Read & Execute
List Folder Contents
Read
Write
Delete
Read Control
Write DAC
Write Owner
Synchronize
Specific rights:
Full Control
Traverse Folder / Execute File
List Folder / Read Data
Read Attributes
Read Extended Attributes
Create Files / Write Data
Create Folders / Append Data
Write Attributes
Write Extended Attributes
Directory Delete Child
Read Permissions
Change Permissions
Take Ownership
Header flags:
Object Inherit
Container Inherit
Inherited
BUILTIN\Users, Access Allowed:
Standard rights:
Read & Execute
List Folder Contents
Read
Read Control
Synchronize
Specific rights:
Traverse Folder / Execute File
List Folder / Read Data
Read Attributes
Read Extended Attributes
Read Permissions
Header flags:
Object Inherit
Container Inherit
Inherited
BUILTIN\Users, Access Allowed:
Specific rights:
Create Folders / Append Data
Header flags:
Container Inherit
Inherited
BUILTIN\Users, Access Allowed:
Specific rights:
Create Files / Write Data
Header flags:
Container Inherit
Inherited
CREATOR OWNER, Access Allowed:
Generic rights:
Generic All
Specific rights:
Full Control
Traverse Folder / Execute File
List Folder / Read Data
Read Attributes
Read Extended Attributes
Create Files / Write Data
Create Folders / Append Data
Write Attributes
Write Extended Attributes
Directory Delete Child
Read Permissions
Change Permissions
Take Ownership
Header flags:
Object Inherit
Container Inherit
Inherit Only
Inherited
</String>
</ReportSection>
<ReportSection name="Group" category="added">
<String name="observed">TRIPWIREENT\None</String>
</ReportSection>
<ReportSection name="Owner" category="added">
<String name="observed">BUILTIN\Administrators</String>
</ReportSection>
<ReportSection name="Read-Only" category="added">
<String name="observed">false</String>
</ReportSection>
<ReportSection name="SACL" category="added">
<String name="observed">(null)</String>
</ReportSection>
<ReportSection name="Type" category="added">
<String name="observed">Directory</String>
</ReportSection>
</ReportSection>
</ReportSection>
</ReportSection>
<ReportSection name="C:\Windows\System32\drivers\etc\hosts" category="element">
<OID>-1y2p0ij32e8dr:-1y2p0ij32e4kp</OID>
<ReportSection name="08/10/14 23:08" category="version">
<OID>-1y2p0ij32e8du:-1y2p0ij32e3hk</OID>
<Integer name="changeType">2</Integer>
<String name="changeTypeName">Modified</String>
<Integer name="severity">10000</Integer>
<String name="severityName">High</String>
<Timestamp name="changeTime" displayvalue="08/10/14 23:08">1412780929000</Timestamp>
<String name="approvalId"></String>
<ReportSection name="attributes" category="attributes">
<ReportSection name="SHA-1" category="modified">
<String name="expected">de375d8a456a7345323babee88975ca567a2d5c4</String>
<String name="observed">3c5520382f91cb1cd898fee2da4eba3fa338d982</String>
</ReportSection>
<ReportSection name="Size" category="modified">
<String name="expected">829</String>
<String name="observed">854</String>
</ReportSection>
</ReportSection>
</ReportSection>
</ReportSection>
</ReportSection>
</ReportSection>
<ReportSection name="reportTotals" category="reportTotals">
<Integer name="summary.nodeCount">1</Integer>
<Integer name="summary.ruleCount">1</Integer>
<Integer name="summary.elementCount">2</Integer>
</ReportSection>
</ReportBody>
</ReportOutput>Hi Ritehere,
I know this is simple but am beginner in Powershell Script so I was looking for logic to go through however the output you provided is not what i am looking for and your script is too complicated, as under timestamp i wanted display value and correspoding
to display value the OID name and then name value correspoding to that OID. May be u got it wrong.
Thanks anyways. -
How to parse this kind of XML documents and store in a relational tables
Can u guys help me out ,..how to parse these kind of XML documents..like under PR there Sr,CreationDate and DoBID.. Again under Sr...there are LD, CID,TID, RID and so on.....
so how to parse this kind of data..how to create the structure of the table....pls help me out..
<nk8:PR>
<nk8:Sr>
<nk8:LD>---------</nk8:LID>
<nk8:CID>---------</nk8:CID>
<nk8:TID>---------</nk8:TID>
<nk8:RID>---------</nk8:RID>
<nk8:CC>OnError</nk8:CC>
<nk8:AID>---------</nk8:AID>
</nk8:Sr>
<nk8:CreationDateTime>2002-07-01</nk8:CreationDateTime>
<nk8:DOBID>---------</nk8:DOBID>
</nk8:PR>
<ssm:ER>
<ssm:PN>---------</ssm:PN>
<ssm:SN>---------</ssm:SN>
<ssm:SCt>---------</ssm:SC>
<ssm:IA>
<ssm:NT>---------</ssm:NT>
<nk8:LID>---------</nk8:LID>
<nk8:CID>---------</nk8:CID>
<ssm:AN>---------</ssm:AN>
</ssm:A>
</ssm:ER>
</nk8:PR>First, your XML document is not well formatted. Once you're done with that you can extract the values and store it in a table column.
sql> WITH xml_table AS
2 (SELECT XMLTYPE(
3 '
4 <nk8:PR xmlns:nk8="http://www.w3.org">
5 <nk8:Sr>
6 <nk8:LID>LID Value</nk8:LID>
7 <nk8:CID>CID Value</nk8:CID>
8 <nk8:TID>TID Value</nk8:TID>
9 <nk8:RID>RID Value</nk8:RID>
10 <nk8:CC>OnError</nk8:CC>
11 <nk8:AID>---------</nk8:AID>
12 </nk8:Sr>
13 </nk8:PR>') XMLCOL FROM DUAL)
14 SELECT extractvalue(t.column_value,'//nk8:LID','xmlns:nk8="http://www.w3.org"') "LID",
15 extractvalue(t.column_value,'//nk8:CID','xmlns:nk8="http://www.w3.org"') "CID",
16 extractvalue(t.column_value,'//nk8:RID','xmlns:nk8="http://www.w3.org"') "RID",
17 extractvalue(t.column_value,'//nk8:CC','xmlns:nk8="http://www.w3.org"') "CC"
18 FROM xml_table, table(xmlsequence(extract(xmlcol,'/nk8:PR/nk8:Sr','xmlns:nk8="http://www.w3.org"'))) t;
LID CID RID CC
LID Value CID Value RID Value OnError -
I am a new learner to XML & JAVA,I dont't know how to parse the XML file using JAXP,Who can tell me,Who can write an Example?
thx
Best Regards.Using the SAXParser in JAXP the parsing of the XML file is event driven.
Instantiate the parser:
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
InputSource is = new InputSource(new FileReader(theXML));call the parse method:
parser.parse(is, this);The following events are fired as the parser works through the XML public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws org.xml.sax.SAXException
public void endElement(String namespaceURI, String localName, String qName) throws org.xml.sax.SAXException
characters(char[] ch, int start, int length)etc.
You write what you want within each of these sections to handle the structure of your data. Keep in mind SAX is useful only when you know the structure of your XML. -
How to parse thus XML data?
Hi,experts:
In below thread:
Receiving .Net dataset with deployed proxies
i asked how to create a external definition in IR base on above XML data.
Now,i have created a XSD file base on the XML data.And importing it into IR successfully.
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:Locale="zh-CN">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Status">
<xs:complexType>
<xs:attribute name="Result" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
And now,the question is how to parse the XML data in diffgr:diffgram segment.It seems a MS-XML syntax.Can it be parsed by XI?
I tried,but the following error occurs:
com.sap.aii.utilxi.misc.api.BaseRuntimeException: RuntimeException in Message-Mapping transformation: Cannot produce target element /ns0:ZMT_SD_ORDER01_RESULT. Check xml instance is valid for source xsd and target-field mapping fulfills requirements of target xsd at com.sap.aii.mappingtool.tf3.AMappingProgram.startHi,
The above Exception seems to be because of mapping error.
Check your mapping for all the mandatory 1-1 mapping, also the 1-unbounded parent node mapping.
Once when you import the XSD and activate your External Definition if it does without any error then there is no problem with your External Definition.
If this error occurs only when you test your mapping then this is mapping error and not because of XSD.
Please check the parent node mapping like 1-unbounded.
Reward Points if useful
Regards
Ashmi. -
How quickly parse big XML file (60 MB) ???
How quickly parse big XML file (60 MB) ???
I assume you mean load it into XML DB ?. Fundamentally your document is about the upper limit for 9.2.x. I would strongly recommend trying to break it up into a set of smaller documents using a SAX parser before trying to load it into XML DB. In 10g it should be possible to load much bigger documents than this.
-
How to Parse the XML generated by Mapping LookUp - RFC API
Hi Friends,
I m using the link by Michal Krawczyk for Mapping Lookups - RFC API
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/a03e7b02-eea4-2910-089f-8214c6d1b439
How to parse the XML created in the target node ?
Regards
PraveshHi,
Check the second half of my code in this blog,
/people/bhavesh.kantilal/blog/2006/11/20/webservice-calls-from-a-user-defined-function
It deals with webservice call's but almost the same for RFC.
Regards
Bhavesh -
How to parse nested xml file using dom
i want to parse nested xml file
please tell me how to parse nested xml
for eg.
<xml>
<row>
<name>Rahul<name>
<row><newXml>
<newXML>
<Row>
<code>12</code>
</Row>
<newXML>
<XML>
please tell how to parse this fileNormally if you have no idea about X, the first thing you should do is google "X tutorial". You will find plenty of them out there. And the advantage is, they are better written than whatever we spend two minutes throwing together here. Not to mention that it saves us the two minutes.
But if you have specific questions with your SAX parser when you get it going, then ask them here. Actually, ask them in the XML forum here, not this one. -
How to Parse an XML file using SAXParser in java.
Hi all
Am a bit new to XML files and have no idea about SAXParsers ... Now my problem is to parse this XML file below
<?xml version="1.0" encoding="UTF-8"?>
<sc:memory_segmentation xmlns:sc="sc_memory_segmentation.xsd">
<sc:architecture name="MPC55xx"></sc:architecture>
<sc:derivative name=""></sc:derivative>
<sc:configuration name=""></sc:configuration>
<sc:memory name="Internal ROM" type="ROM">
<sc:area-list>
<sc:area name="Bootmanager" type="BOOTMANAGER">
<sc:segment-list>
<sc:segment name="ROM page 1">
<sc:start></sc:start>
<sc:end></sc:end>
</sc:segment>
</sc:segment-list>
</sc:area>
<sc:area name="Bootloader SWE" type="BOOTLOADER">
<sc:segment-list>
<sc:segment name="ROM page 2">
<sc:start></sc:start>
<sc:end></sc:end>
</sc:segment>
<sc:segment name="ROM page 3">
<sc:start></sc:start>
<sc:end></sc:end>
</sc:segment>
</sc:segment-list>
</sc:area>
<sc:area name="Application SWE 1" type="APPLICATION">
<sc:segment-list>
<sc:segment name="ROM page 4">
<sc:start></sc:start>
<sc:end></sc:end>
</sc:segment>
<sc:segment name="ROM page 5">
<sc:start></sc:start>
<sc:end></sc:end>
</sc:segment>
<sc:segment name="ROM page 6">
<sc:start></sc:start>
<sc:end></sc:end>
</sc:segment>
<sc:segment name="ROM page 7">
<sc:start></sc:start>
<sc:end></sc:end>
</sc:segment>
</sc:segment-list>
</sc:area>
<sc:area name="Application SWE 2" type="APPLICATION">
<sc:segment-list>
<sc:segment name="ROM page 8">
<sc:start></sc:start>
<sc:end></sc:end>
</sc:segment>
</sc:segment-list>
</sc:area>
<sc:area name="Application SWE 3" type="APPLICATION">
<sc:segment-list>
<sc:segment name="ROM page 9">
<sc:start></sc:start>
<sc:end></sc:end>
</sc:segment>
</sc:segment-list>
</sc:area>
<sc:area name="Application SWE 4" type="APPLICATION">
<sc:segment-list>
<sc:segment name="ROM page 10">
<sc:start></sc:start>
<sc:end></sc:end>
</sc:segment>
</sc:segment-list>
</sc:area>
</sc:area-list>
</sc:memory>
<sc:memory name="Internal RAM" type="RAM">
<sc:area-list>
<sc:area name="RAM" type="RAM">
<sc:segment-list>
<sc:segment name="RAM page 1">
<sc:start></sc:start>
<sc:end></sc:end>
</sc:segment>
<sc:segment name="RAM page 2">
<sc:start></sc:start>
<sc:end></sc:end>
</sc:segment>
<sc:segment name="RAM page 3">
<sc:start></sc:start>
<sc:end></sc:end>
</sc:segment>
<sc:segment name="RAM page 4">
<sc:start></sc:start>
<sc:end></sc:end>
</sc:segment>
<sc:segment name="RAM page 5">
<sc:start></sc:start>
<sc:end></sc:end>
</sc:segment>
</sc:segment-list>
</sc:area>
</sc:area-list>
</sc:memory>
<sc:memory name="Internal EEPROM" type="EEPROM">
<sc:area-list>
<sc:area name="EEPROM" type="EEPROM">
<sc:segment-list>
<sc:segment name="EEPROM page 1">
<sc:start></sc:start>
<sc:end></sc:end>
</sc:segment>
<sc:segment name="EEPROM page 2">
<sc:start></sc:start>
<sc:end></sc:end>
</sc:segment>
<sc:segment name="EEPROM page 3">
<sc:start></sc:start>
<sc:end></sc:end>
</sc:segment>
<sc:segment name="EEPROM page 4">
<sc:start></sc:start>
<sc:end></sc:end>
</sc:segment>
<sc:segment name="EEPROM page 5">
<sc:start></sc:start>
<sc:end></sc:end>
</sc:segment>
</sc:segment-list>
</sc:area>
</sc:area-list>
</sc:memory>
</sc:memory_segmentation> And from this file I need to make 3 Hashtables out of it one for ROM , RAM and EEPROM containg Segment information i.e. Segment start and end addresses and Area type of the segment....
If anyone could at least guide me with the basic commands and structure of the parser it would be really really great ...
Thanks a lot
AnishaNormally if you have no idea about X, the first thing you should do is google "X tutorial". You will find plenty of them out there. And the advantage is, they are better written than whatever we spend two minutes throwing together here. Not to mention that it saves us the two minutes.
But if you have specific questions with your SAX parser when you get it going, then ask them here. Actually, ask them in the XML forum here, not this one. -
How to parse SOAP XML output and load to oracle9i table
Below is the SOAP output response and I need to load the data into oracle 9i database tables.
I am able to parse regular XML without namespaces but unable to parse the data with namespaces.
I would need help in parsing this XML.
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
<o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<u:Timestamp u:Id="_0">
<u:Created>2011-11-04T23:16:08.437Z</u:Created>
<u:Expires>2011-11-04T23:21:08.437Z</u:Expires>
</u:Timestamp>
</o:Security>
</s:Header>
<s:Body>
<AssetGetListResponse xmlns="http://dev.services.xerox.com">
<AssetGetListResult xmlns:a="http://schemas.datacontract.org/2004/07/Xerox.MPS" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:AssetFeed>
<a:AccountID>de5862bf-f223-e011-bd3b-0024e861b15c</a:AccountID>
<a:AccountName>MPS-API Sandbox</a:AccountName>
<a:AssetID>ecf1545a-f1e9-e011-8a8a-0024e861b15c</a:AssetID>
<a:AssetNumber>57119B28</a:AssetNumber>
<a:AssetTag3rdParty i:nil="true"/>
<a:ChargebackCodeID>1a5962bf-f223-e011-bd3b-0024e861b15c</a:ChargebackCodeID>
<a:ContractNumber i:nil="true"/>
<a:ContractTypeDescription i:nil="true"/>
<a:ControlID i:nil="true"/>
<a:Group i:nil="true"/>
<a:GroupID i:nil="true"/>
<a:InScope>false</a:InScope>
<a:MACAddress>0000AA713E97</a:MACAddress>
<a:Manufacturer>Xerox</a:Manufacturer>
<a:Model>WorkCentre Pro 265</a:Model>
<a:ModifiedDate>2011-11-02T16:52:12.947Z</a:ModifiedDate>
<a:PricePlanID>c25a62bf-f223-e011-bd3b-0024e861b15c</a:PricePlanID>
<a:SerialNumber>UTU101993N</a:SerialNumber>
<a:VersionNumber>634558495329470000</a:VersionNumber>
</a:AssetFeed>
<a:AssetFeed>
<a:AccountID>de5862bf-f223-e011-bd3b-0024e861b15c</a:AccountID>
<a:AccountName>MPS-API Sandbox</a:AccountName>
<a:AssetID>b33b5160-f1e9-e011-8a8a-0024e861b15c</a:AssetID>
<a:AssetNumber>7EE42ADC</a:AssetNumber>
<a:AssetTag3rdParty i:nil="true"/>
<a:ChargebackCodeID>1a5962bf-f223-e011-bd3b-0024e861b15c</a:ChargebackCodeID>
<a:ContractNumber i:nil="true"/>
<a:ContractTypeDescription i:nil="true"/>
<a:ControlID i:nil="true"/>
<a:Group i:nil="true"/>
<a:GroupID i:nil="true"/>
<a:InScope>false</a:InScope>
<a:MACAddress>0800379B4C2A</a:MACAddress>
<a:Manufacturer>Xerox</a:Manufacturer>
<a:Model>WorkCentre 7428</a:Model>
<a:ModifiedDate>2011-11-02T16:52:14.383Z</a:ModifiedDate>
<a:PricePlanID>c25a62bf-f223-e011-bd3b-0024e861b15c</a:PricePlanID>
<a:SerialNumber>PBB015012</a:SerialNumber>
<a:VersionNumber>634558495343830000</a:VersionNumber>
</a:AssetFeed>
</AssetGetListResult>
</AssetGetListResponse>
</s:Body>
</s:Envelope>
This is what I tried.
declare
lp_parser xmlParser.Parser;
lx_xmldoc xmlDom.DOMDocument;
ln_doc_node xmlDom.DOMNode;
lnl_product xmlDom.DOMNodeList;
lnl_meter xmlDom.DOMNodeList;
ln_product xmlDom.DOMNode;
ln_meter xmlDom.DOMNode;
li_product_cnt NUMBER;
li_product_max NUMBER;
li_meter_cnt NUMBER;
li_meter_max NUMBER;
lnl_asset_meter_nodes xmldom.DOMNodeList;
ln_asset_meter_node xmldom.DOMNode;
ls_batch_number VARCHAR2(30);
ldt_proc_dt DATE;
ls_batch_item VARCHAR2(30);
ls_place_id place.place_id%TYPE;
ls_product_id product.product_id%TYPE := ' ';
ls_contract_id contract.contract_id%TYPE;
li_contract_version contract.contract_version%TYPE;
li_contract_sequence contr_product.sequence%TYPE;
ls_meter_id meter_log.meter_id%TYPE;
ls_read_type meter_log.read_type%TYPE;
ldt_reading_dt meter_log.reading_dt%TYPE;
li_meter_value meter_log.meter_value%TYPE;
li_adjust_copies meter_log.meter_value%TYPE;
ls_meter_type VARCHAR2(20);
ls_serial_id product.serial_id%TYPE;
ls_meter_read_type VARCHAR2(50);
invalid_parsing EXCEPTION;
PRAGMA EXCEPTION_INIT(invalid_parsing, -20100);
BEGIN
FOR meter_xml_rec IN (SELECT SOAP_RESPONSE
FROM temp_table
WHERE call_id=2) LOOP
lp_parser := xmlparser.newParser;
xmlparser.parseClob(lp_parser, meter_xml_rec.SOAP_RESPONSE);
lx_xmldoc := xmlparser.getDocument(lp_parser);
xmlparser.freeParser(lp_parser);
ln_doc_node := xmlDom.makeNode(lx_xmldoc);
ls_batch_number := xslProcessor.valueOf(ln_doc_node, 'AssetGetListResponse/AssetGetListResult/AssetFeed/AccountID');
lnl_product := xslprocessor.selectNodes(ln_doc_node, 'AssetGetListResponse/AssetGetListResult/a:AssetFeed');
li_product_max := xmlDom.getLength(lnl_product)-1;
FOR li_product_cnt IN 0..li_product_max LOOP
ln_product := xmlDom.item(lnl_product, li_product_cnt);
ls_batch_item := xslProcessor.valueOf(ln_product, 'AccountName');
END LOOP;
END LOOP;
END;
OUTPUT:
=========================================
3:32:41 PM *
**3:32:41 PM ORA-20100: Error occurred while processing: Namespace prefix 'a' used but not declared.**
3:32:41 PM ORA-06512: at "SYS.XSLPROCESSOR", line 22
3:32:41 PM ORA-06512: at "SYS.XSLPROCESSOR", line 502
3:32:41 PM ORA-06512: at line 50
3:32:41 PM *** Script stopped due to error ***
3:32:41 PM End SQL Editor ExecutionHi,
Something like this :
lnl_product := xslprocessor.selectNodes(
ln_doc_node
, '/s:Envelope/s:Body/AssetGetListResponse/AssetGetListResult/a:AssetFeed'
, 'xmlns:s="http://schemas.xmlsoap.org/soap/envelope/", xmlns="http://dev.services.xerox.com", xmlns:a="http://schemas.datacontract.org/2004/07/Xerox.MPS"'
li_product_max := xmlDom.getLength(lnl_product)-1;
FOR li_product_cnt IN 0..li_product_max LOOP
ln_product := xmlDom.item(lnl_product, li_product_cnt);
ls_batch_item := xslProcessor.valueOf(ln_product, 'a:AccountName', 'xmlns:a="http://schemas.datacontract.org/2004/07/Xerox.MPS"');
END LOOP;
...Or, using a single query :
SQL> SELECT extractValue(value(x), '/AssetFeed/AccountID', 'xmlns="http://schemas.datacontract.org/2004/07/Xerox.MPS"') as AccountID
2 , extractValue(value(x), '/AssetFeed/AccountName', 'xmlns="http://schemas.datacontract.org/2004/07/Xerox.MPS"') as AccountName
3 , extractValue(value(x), '/AssetFeed/AssetID', 'xmlns="http://schemas.datacontract.org/2004/07/Xerox.MPS"') as AssetID
4 , extractValue(value(x), '/AssetFeed/AssetNumber', 'xmlns="http://schemas.datacontract.org/2004/07/Xerox.MPS"') as AssetNumber
5 , extractValue(value(x), '/AssetFeed/SerialNumber', 'xmlns="http://schemas.datacontract.org/2004/07/Xerox.MPS"') as SerialNumber
6 FROM temp_table t
7 , TABLE(
8 XMLSequence(
9 EXTRACT(
10 XMLType(t.soap_response)
11 , '/s:Envelope/s:Body/AssetGetListResponse/AssetGetListResult/a:AssetFeed'
12 , 'xmlns:s="http://schemas.xmlsoap.org/soap/envelope/", xmlns="http://dev.services.xerox.com", xmlns:a="http://schemas.datacontract.org/2004/07/Xerox.MPS"'
13 )
14 )
15 ) x
16 WHERE t.call_id = 2
17 ;
ACCOUNTID ACCOUNTNAME ASSETID ASSETNUMBER SERIALNUMBER
de5862bf-f223-e011-bd3b-0024e861b15c MPS-API Sandbox ecf1545a-f1e9-e011-8a8a-0024e861b15c 57119B28 UTU101993N
de5862bf-f223-e011-bd3b-0024e861b15c MPS-API Sandbox b33b5160-f1e9-e011-8a8a-0024e861b15c 7EE42ADC PBB015012 -
How to parse/extract XML from clob field using ODI
Hi,
I am very new to ODI. I have an oracle table which has clob field. This clob field contains xml. I would like to parse this xml and convert it to oracle table. Means I would like to make all the tags of xml as oracle table columns.
I have created a PL/SQL procedure and used XMLTABLE function and I have achieved my goal. The same this I am trying to do with ODI. Since I am new to ODI so any help is appreciated.
ThanksIn 9.2, you are limited into your options. Have a look into, among others, updateXML. Updating tp 10gR2 will give you more options to succeed.
-
Liquid data--how to parse the xml which is generated on the fly
I am using liquid data for retreiving data from database which I am able to do
but the problem is that it generates the xml on the fly and prints the response
in xml format in html document .My need is that I want to parse this xml and use
the data on need basis in my jsp document.
I am usig following weblogic workshop 8.1 tags in my jsp :
<lds:query name="bdemo_cust_info" server="t3://localhost:7001">
<lds:param name="cust_name" value="<%=\"MCD\"%>"/>
</lds:query>;
Please help??
Thaks and Regards,
Ajay Jindalhi Ajay
You can create a Liquid Data Control and display it using NetUI - or see the QueryClient
example in weblogic\samples\liquiddata\ejbAPI and create an XML Bean from the
result.
- Mike
"ajayjidal" <[email protected]> wrote:
>
I am using liquid data for retreiving data from database which I am able
to do
but the problem is that it generates the xml on the fly and prints the
response
in xml format in html document .My need is that I want to parse this
xml and use
the data on need basis in my jsp document.
I am usig following weblogic workshop 8.1 tags in my jsp :
<lds:query name="bdemo_cust_info" server="t3://localhost:7001">
<lds:param name="cust_name" value="<%=\"MCD\"%>"/>
</lds:query>;
Please help??
Thaks and Regards,
Ajay Jindal -
How to parse a XML stream sent to servlet with PUT method
Hi,
I have to interface my servlet app with other apps communicating with XML.
This way, My servlet will receive a XML stream in the http request, parse it and send back a XML message.
What I've done is :
An html page to send a XML File with a put method :
<form enctype="multipart/form-data" method="PUT" action="http://localhost:8080/MyApp/servlet/TestUploadServlet">
<input type="file" size="20" name="FileToUpload" value="Select File">
<input type="submit" name="UploadFile" value="Upload">
<input type="reset" value="Reset">
</form>
A servlet TestUploadServlet with :
SAXParser parser = new SAXParser( );
Trace.traceLine( "SAXParser" );
parser.setContentHandler (this);
try {
parser.parse( new InputSource( requete.getInputStream() ) );
catch (SAXException e) {
Trace.traceLine( e.getMessage() );
catch (IOException e) {
Trace.traceLine( e.getMessage() );
and the methods startElement, stopElement and other to work with the elements detected by the parser (already used by other programs parsing local xml files).
And it doesn't work.
is the html code is a good way to send a file in the http Put method ?
is the parser.parse( new InputSource( requete.getInputStream() ) ); a good method to read the stream ?
please help.I think the problemn comes from the method used to send the <XML> stream.
Using an html form doesn't seem to be a good method.
I tried several methods or examples found and none of them seems to work.
here is another example in the servlet side :
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
ServletOutputStream output = res.getOutputStream();
output.println("ContentType: " + req.getContentType() + "<BR>");
int content_length = req.getContentLength();
output.println("ContentLength: " + content_length + "<BR>");
if(content_length > 0) {
output.println("Content: ");
ServletInputStream input = req.getInputStream();
byte [] buffer = new byte[1024];
int nb;
while((nb=input.read(buffer))!= -1) {
output.write(buffer,0,nb);
Can somebody tell me how to write a java code sending a http request with the content of a file in the content of the request ?
Maybe you are looking for
-
Creating NWDI track for ESS/MSS
Hi, I am trying to implement ESS/MSS (600 SP7). For customization I need to import the package on the track in CMS. Import of JEE, JTECHS, BUILDT and PCUIG were successful. When i tried importing ESS and MSS, import is failing. Check-In of both the c
-
Copying simulation from one CP file into another...issues
Hi, I am trying to copy slides from one simualtion into another, but when I do, all the objects et are covered with a background. For example, I copy some slides that are instructing to click on the Start menu, then selecting the program from the sta
-
Panel Close? Event causes front panel to be unresponsive
I'm trying to create a simple program. There is a while loop that generates random numbers just so I can see it's running. An "Exit" button is wired to the exit terminal of the while loop. An event structure is also in this while loop, which catches
-
RAW (NEF) photos from my new Nikon D750 will not open in Camera RAS with Photoshop Elements 11. This has not been a problem with previous Nikon cameras. I'm using a MacBook Pro with OS X 10.9.5. How can I solve this problem? Thanks.
-
Word processors that don't lose data?
I'm about to get my first iPad. My wife, who goes back to the iPad 1, just lost hours of work yesterday to a corrupted file. In both our cases, the most important business-like use cases are word processing. Features we both want include: Doesn't r