XSD schema to xml file generation using C#
Hi fellow developers,
I need small help with my current scenario.
I have 2 xsd schemas one is input and other is output.
Now my requirement is based on those xsd template or structure, i need to write a C# code that takes the 1 xsd template as input in xml format and then do some mapping and then set that values to 2 xsd template in xml format.
Can you please guide or assist in this regards ??
It would be helpful if we have the flexibility of configuring the schema properties.
Hi
Venky_Ferrari.
Based on your description, your case related to XMLXSD, SO I will move your thread to
Data Platform Development > XML, System.Xml, MSXML and XmlLite
forum for better support.
Best regards,
Kristin
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey.
Similar Messages
-
Error in XML file generation :240416
Hi All,
I am facing problem with XML file generation.
Steps:
1. Source-->Query Transform and maintained Nested Stucture
2. Generated XML fomat from query transform
3. Created XML format file
4. Make XML format as target and given XML generate path
source table-->Query(nested structure)-->XML Format
when I validate the job no errors found.
Note: XSD file is in Local mechine and XML file will be generated in SFTP.
Prooblems:
1. Getting below error
The input XML refers to file which is not part of the definition of this XML Schema format. Check your schema and XML files,
and check that the root element in the XML file corresponds to the root element in the XML Schema
Validate your XML Schema using external schema validators (found at w3.org)
Thanks,
DeepaHi,
I think issue Because in your Query Transform output the Root element is Query and XML target is having some other root element. Make the Query trasform name similar to root element and try... -
I am wondering if there is a way to validate XML file without using the <!DOCTYPE... but pass in the location of the schema/DTD file as a parameter to a validating method?
thanksNone that I know of. The only thing close is to use the EntityResolver interface where you can modify the location of the DTD file before it's being loaded and parsed, but that requires a <!DOCTYPE ...> in the XML file.
Good luck. -
Web.xml file generation problem
Hi,
I am trying to create web.xml file automatically using "java weblogic.marathon.ddinit.WebInit
" command.
I got the following message in the command prompt:
Found Web components. Initializing descriptors
filters=0 servlets=0 tags=0
Above command is creating the web.xml and weblogic.xml files but it is not including
the servlet-mapping information. why?
Thanks,
PrakashIt doesn't look like it found any servlets. You'd have to show me your
files if I'm to understand what's going on.
-- Rob
Prakash wrote:
Hi,
I am trying to create web.xml file automatically using "java weblogic.marathon.ddinit.WebInit
" command.
I got the following message in the command prompt:
Found Web components. Initializing descriptors
filters=0 servlets=0 tags=0
Above command is creating the web.xml and weblogic.xml files but it is not including
the servlet-mapping information. why?
Thanks,
Prakash -
XML File Generation Issues using DBMS_XMLGEN
Hi,
I am using DBMS_XMLGEN package in a stored procedure to generate an XML file on Oracle 10 G R2 .But, the problem is the format in which the file is generated.
CREATE OR REPLACE TYPE "state_info" as object (
"@product_type" Number
CREATE OR REPLACE TYPE prod_tab as TABLE OF "state_info";
CREATE OR REPLACE TYPE state_t as object (
"state_code" CHAR(2),
"state_info" prod_tab
CREATE OR REPLACE PROCEDURE get_xml_serviced_state (p_clob OUT clob)
IS
v_xmlctx DBMS_XMLGEN.ctxhandle;
v_str VARCHAR2 (1000);
BEGIN
v_str := 'SELECT state_t(a.st_cd,CAST(MULTISET(select veh_type_id from svcd_st where st_cd =a.st_cd)as prod_tab)) as "state_info"
from svcd_st a where a.st_cd in (select distinct st_cd from svcd_st) group by a.st_cd having count(*)>=1';
v_xmlctx := DBMS_XMLGEN.newcontext (v_str);
DBMS_XMLGEN.setrowsettag (v_xmlctx,'serviced_state');
DBMS_XMLGEN.setrowtag (v_xmlctx,NULL);
p_clob := DBMS_XMLGEN.getxml (v_xmlctx);
printclobout(p_clob);
EXCEPTION
WHEN NO_DATA_FOUND
THEN
NULL;
WHEN OTHERS
THEN
RAISE;
END;
SHOW ERRORS
Output :
<serviced_state>
<state_info state_code="VA">
<state_info>
<state_info product_type="2"/>
<state_info product_type="5"/>
<state_info product_type="9"/>
</state_info>
</state_info>
<state_info state_code="AB">
<state_info>
<state_info product_type="2"/>
<state_info product_type="5"/>
<state_info product_type="9"/>
</state_info>
</state_info>
</serviced_state>
Required it in below format:
<serviced_state>
<state_info state_code="VA">
<state_info product_type="2"/>
<state_info product_type="5"/>
<state_info product_type="9"/>
</state_info>
<state_info state_code="AB">
<state_info product_type="2"/>
<state_info product_type="5"/>
<state_info product_type="9"/>
</state_info>
</serviced_state>
I just need to put in all the rows under one single tag.Appreciate your early responses.
Thanks.Your wanted XML output is NOT VALID...(try it yourself on http://tools.decisionsoft.com/schemaValidate/)
-
Datalink sequence method (XML file generation problem using Rdf)
Hi All
I want to Generate XML File using RDF , Here i used 4 datablocks and i lilnked each datablock with datalink like 1 to 2, 1to 3 and 1 to 4 respectively. while executing the report it choosing only one link like 1 to 2 and writting the data in the file for the same. its not touching 3rd and 4th datablocks I need to have data for all the blocks that are available.
One more thing i want to close each blockonce the data is written in the file.But in this case the tags get open wites data goes to the other block write the data for this block come back to the first block and closes the block.
eg: <Start>
<First block>
<Second block>
<Third Block>
</Third block>
</second block>
</First block>
</Start>
My requirment is
<start>
<First block>
</First block>
<Second block>
</Second block>
<Third Block>
</Third block>
</Start>You might want to look at the SQL/XML operators XMLAGG, XMLELEMENT, XMLFOREST, XMLATTRIBUTES. They provide you with fine grained control over the XML generated.
-
Hello,
I'm using XML files to communicate two systems. The XML files fulfill a W3C Schema.
I want to know if there is any Java library, API or something like this, to generate automatically XML files that fulfill a schema, giving the schema file and the data to fill the XML file.
Thanks,
Laura.Please use the code tags when posting code, as described in the formatting tips.
http://forum.java.sun.com/help.jspa?sec=formatting -
How we can generate XML file using Oracle PL/SQL!!
We have oracle supplied packages for this!!! Which is preferable for printing table data into XML file!!!!
DBMS_XMLDOM
DBMS_XMLGEN
DBMS_XMLPARSER
DBMS_XMLQUERY
DBMS_XMLSAVE
DBMS_XMLSchema
DBMS_XMLStore
UTL_FILE
ThanksThere may be several alternative ways, but maybe the simplest way around is using object views and spool the data coming -
CREATE TABLE warehouse_table (
WarehouseID NUMBER,
Area NUMBER,
Docks NUMBER,
DockType VARCHAR2(100),
WaterAccess VARCHAR2(10),
RailAccess VARCHAR2(10),
Parking VARCHAR2(20),
VClearance NUMBER );
INSERT INTO warehouse_table
VALUES(5, 103000,3,’Side Load’,'false’,'true’,'Lot’,15);
CREATE VIEW warehouse_view OF XMLTYPE
– XMLSCHEMA “http://www.oracle.com/xwarehouses.xsd”
– ELEMENT “Warehouse”
WITH OBJECT ID
(extract(OBJECT_VALUE, ‘/Warehouse/Area/text()’).getnumberval())
AS SELECT XMLELEMENT(”Warehouse”,
XMLFOREST(WarehouseID as “Building”,
area as “Area”,
docks as “Docks”,
docktype as “DockType”,
wateraccess as “WaterAccess”,
railaccess as “RailAccess”,
parking as “Parking”,
VClearance as “VClearance”))
FROM warehouse_table;
SELECT VALUE(e) FROM warehouse_view e;
VALUE(E)
<Warehouse><Building>5</Building><Area>103000</Area><Docks>3</Docks><DockType>Si..
Best regards. -
Generating "XSD" from an "XML" file
Hi,
I want a java program through which we can generate an "XSD" for
the given "XML" file.
I don't want any ready to use tools or ide's.
Please send me links or code if exists.
Thank You.http://forum.java.sun.com/thread.jspa?threadID=491512&messageID=2314233
-
Cant load schema-based xml-file to default table via http/ftp
Hola,
we are running ORACLE 10.2.0.3.0 with installed XML-DB.
HTTP- and ftp-listeners where configured successfully, we are able to register a designed XSD-file within XML-DB. Autogen types and tables where set "true" and default table for root object within xsd and several type objects where also created successful.
Oracle DB is running on a Linux environment, it is possible to establish a WEBDAV-connection to this machine via my Windows client.
As far as I understood the Oracle examples, there should be some kind of automatism. Putting a valid (and registered via xsi:noNamespaceSchemaLocation=<pointing to xsd-file>) XML file into my WEBDAV folder should create an XML object in the XML repository AND create a dataset in the default table.
Last thing doesn´t work.
Any idea?!Can you try this simple example
SQL> set echo on
SQL> spool testase.log
SQL> --
SQL> connect / as sysdba
Connected.
SQL> --
SQL> set define on
SQL> set timing on
SQL> --
SQL> define USERNAME = OTN
SQL> --
SQL> def PASSWORD = &USERNAME
SQL> --
SQL> def USER_TABLESPACE = USERS
SQL> --
SQL> def TEMP_TABLESPACE = TEMP
SQL> --
SQL> drop user &USERNAME cascade
2 /
old 1: drop user &USERNAME cascade
new 1: drop user OTN cascade
User dropped.
Elapsed: 00:00:00.18
SQL> grant create any directory, drop any directory, connect, resource, alter session, create view to &USERNAME identified by &PASSWORD
2 /
old 1: grant create any directory, drop any directory, connect, resource, alter session, create view to &USERNAME identified by &PASSWORD
new 1: grant create any directory, drop any directory, connect, resource, alter session, create view to OTN identified by OTN
Grant succeeded.
Elapsed: 00:00:00.09
SQL> alter user &USERNAME default tablespace &USER_TABLESPACE temporary tablespace &TEMP_TABLESPACE
2 /
old 1: alter user &USERNAME default tablespace &USER_TABLESPACE temporary tablespace &TEMP_TABLESPACE
new 1: alter user OTN default tablespace USERS temporary tablespace TEMP
User altered.
Elapsed: 00:00:00.00
SQL> connect &USERNAME/&PASSWORD
Connected.
SQL> --
SQL> -- create or replace directory XMLDIR as '&XMLDIR'
SQL> -- /
SQL> var SCHEMAURL varchar2(256)
SQL> VAR XMLSCHEMA CLOB;
SQL> VAR INSTANCE CLOB;
SQL> VAR DOCPATH VARCHAR2(700)
SQL> --
SQL> set define off
SQL> --
SQL> alter session set events='31098 trace name context forever'
2 /
Session altered.
Elapsed: 00:00:00.01
SQL> begin
2 :SCHEMAURL:= 'http://oradb4.min.local:8080/public/CSBF/xsd/CSBF_Vergabemeldung_Formular.xsd';
3 :XMLSCHEMA :=
4 '<?xml version="1.0" encoding="UTF-8"?>
5 <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xdb="http://xmlns.oracle.com/xdb" version="1.0" xdb:storeVarrayAsTable="true">
6 <xs:simpleType name="string_5">
7 <xs:restriction base="xs:string"><xs:maxLength value="5"/></xs:restriction>
8 </xs:simpleType>
9 <xs:simpleType name="string_6">
10 <xs:restriction base="xs:string"><xs:maxLength value="6"/></xs:restriction>
11 </xs:simpleType>
12 <xs:simpleType name="string_8">
13 <xs:restriction base="xs:string"><xs:maxLength value="8"/></xs:restriction>
14 </xs:simpleType>
15 <xs:simpleType name="string_20">
16 <xs:restriction base="xs:string"><xs:maxLength value="20"/></xs:restriction>
17 </xs:simpleType>
18 <xs:simpleType name="string_30">
19 <xs:restriction base="xs:string"><xs:maxLength value="30"/></xs:restriction>
20 </xs:simpleType>
21 <xs:simpleType name="string_60">
22 <xs:restriction base="xs:string"><xs:maxLength value="60"/></xs:restriction>
23 </xs:simpleType>
24 <xs:element name="CSBF_Vergabemeldung" xdb:defaultTable="CSBF_VERGABE_INFO_XML">
25 <xs:complexType>
26 <xs:sequence>
27 <xs:element name="CSBF_Vergabemeldung_Info">
28 <xs:complexType>
29 <xs:sequence>
30 <xs:element name="Identnummer" type="string_30"/>
31 <xs:element name="Version_CSBF_Vergabevermerk_Formular" type="string_30"/>
32 <xs:element name="Fertigstellung_Vergabevermerk" type="xs:date"/>
33 </xs:sequence>
34 </xs:complexType>
35 </xs:element>
36 <xs:element name="Strassenbaudienststelle">
37 <xs:complexType>
38 <xs:sequence>
39 <xs:element name="Kennung" type="string_8"/>
40 <xs:element name="Strassenbau_Organisation_Bezeichnung" type="string_60"/>
41 <xs:element name="Adresszeile_2" type="string_60" minOccurs="0"/>
42 <xs:element name="Adresszeile_3" type="string_60" minOccurs="0"/>
43 <xs:element name="Adresszeile_4" type="string_60" minOccurs="0"/>
44 <xs:element name="Strasse" type="string_60"/>
45 <xs:element name="PLZ" type="string_6"/>
46 <xs:element name="Ort" type="string_60"/>
47 <xs:element name="NUTS" type="string_5"/>
48 <xs:element name="Telefon" type="string_20" minOccurs="0"/>
49 <xs:element name="Fax" type="string_20" minOccurs="0"/>
50 <xs:element name="E_Mail" type="string_30"/>
51 </xs:sequence>
52 </xs:complexType>
53 </xs:element>
54 </xs:sequence>
55 </xs:complexType>
56 </xs:element>
57 </xs:schema>';
58 :DOCPATH := '/public/CSBF_Vergabemeldung.xml';
59 :INSTANCE :=
60 '<?xml version="1.0" encoding="ISO-8859-15"?>
61 <CSBF_Vergabemeldung xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://oradb4.min.local:8080/public/CSBF/xsd/CSBF
_Vergabemeldung_Formular.xsd">
62 <CSBF_Vergabemeldung_Info>
63 <Identnummer>xxxxxxxxxxxxxxxxxxxxxxxxxxxxx</Identnummer>
64 <Version_CSBF_Vergabevermerk_Formular>xxxxxxxxxxxxxxxx</Version_CSBF_Vergabevermerk_Formular>
65 <Fertigstellung_Vergabevermerk>1900-01-01</Fertigstellung_Vergabevermerk>
66 </CSBF_Vergabemeldung_Info>
67 <Strassenbaudienststelle>
68 <Kennung>xxxxx</Kennung>
69 <Strassenbau_Organisation_Bezeichnung>xxxxxxx</Strassenbau_Organisation_Bezeichnung>
70 <Adresszeile_2>xxxxxxxxxxxxx</Adresszeile_2>
71 <Adresszeile_3>xxxxxxxxxxxxxx</Adresszeile_3>
72 <Adresszeile_4>xxxxxxxxxxxxxxxxx</Adresszeile_4>
73 <Strasse>xxxxxxxxxxxxxx</Strasse>
74 <PLZ>xxxxx</PLZ>
75 <Ort>xxxxxxxxxxxxxx</Ort>
76 <NUTS>xxxxx</NUTS>
77 <Telefon>xxxxxxxxxxx</Telefon>
78 <Fax>xxxxxxxxxxx</Fax>
79 <E_Mail>[email protected]</E_Mail>
80 </Strassenbaudienststelle>
81 </CSBF_Vergabemeldung>';
82 end;
83 /
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.01
SQL> begin
2 dbms_xmlschema.registerSchema
3 (
4 schemaurl => :SCHEMAURL,
5 schemadoc => :XMLSCHEMA,
6 local => TRUE,
7 genTypes => TRUE,
8 genBean => FALSE,
9 genTables => TRUE
10 );
11 end;
12 /
PL/SQL procedure successfully completed.
Elapsed: 00:00:03.80
SQL> desc CSBF_VERGABE_INFO_XML
Name Null? Type
TABLE of SYS.XMLTYPE(XMLSchema "http://oradb4.min.local:8080/public/CSBF/xsd/CSBF_Vergabemeldung_Formular.xsd" Element "CSBF_Vergabemeldung") STORAGE Object-rel
ational TYPE "CSBF_Vergabemeldung3270_T"
SQL> --
SQL> declare
2 V_RESULT BOOLEAN;
3 begin
4 if dbms_xdb.existsResource(:DOCPATH) then
5 dbms_xdb.deleteResource(:DOCPATH);
6 end if;
7 V_RESULT := DBMS_XDB.CREATERESOURCE(:DOCPATH,:INSTANCE);
8 COMMIT;
9 end;
10 /
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.79
SQL> select count(*)
2 from CSBF_VERGABE_INFO_XML
3 /
1
Elapsed: 00:00:00.15
SQL> set long 10000 pages 0 lines 160
SQL> --
SQL> select object_value
2 from CSBF_VERGABE_INFO_XML
3 /
<?xml version="1.0" encoding="WINDOWS-1252"?>
<CSBF_Vergabemeldung xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://oradb4.min.local:8080/public/CSBF/xsd/CSBF_Verg
abemeldung_Formular.xsd">
<CSBF_Vergabemeldung_Info>
<Identnummer>xxxxxxxxxxxxxxxxxxxxxxxxxxxxx</Identnummer>
<Version_CSBF_Vergabevermerk_Formular>xxxxxxxxxxxxxxxx</Version_CSBF_Vergabevermerk_Formular>
<Fertigstellung_Vergabevermerk>1900-01-01</Fertigstellung_Vergabevermerk>
</CSBF_Vergabemeldung_Info>
<Strassenbaudienststelle>
<Kennung>xxxxx</Kennung>
<Strassenbau_Organisation_Bezeichnung>xxxxxxx</Strassenbau_Organisation_Bezeichnung>
<Adresszeile_2>xxxxxxxxxxxxx</Adresszeile_2>
<Adresszeile_3>xxxxxxxxxxxxxx</Adresszeile_3>
<Adresszeile_4>xxxxxxxxxxxxxxxxx</Adresszeile_4>
<Strasse>xxxxxxxxxxxxxx</Strasse>
<PLZ>xxxxx</PLZ>
<Ort>xxxxxxxxxxxxxx</Ort>
<NUTS>xxxxx</NUTS>
<Telefon>xxxxxxxxxxx</Telefon>
<Fax>xxxxxxxxxxx</Fax>
<E_Mail>[email protected]</E_Mail>
</Strassenbaudienststelle>
</CSBF_Vergabemeldung>
Elapsed: 00:00:01.99
SQL> select xdburitype(:DOCPATH).getXML()
2 from DUAL
3 /
<?xml version="1.0" encoding="WINDOWS-1252"?>
<CSBF_Vergabemeldung xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://oradb4.min.local:8080/public/CSBF/xsd/CSBF_Verg
abemeldung_Formular.xsd">
<CSBF_Vergabemeldung_Info>
<Identnummer>xxxxxxxxxxxxxxxxxxxxxxxxxxxxx</Identnummer>
<Version_CSBF_Vergabevermerk_Formular>xxxxxxxxxxxxxxxx</Version_CSBF_Vergabevermerk_Formular>
<Fertigstellung_Vergabevermerk>1900-01-01</Fertigstellung_Vergabevermerk>
</CSBF_Vergabemeldung_Info>
<Strassenbaudienststelle>
<Kennung>xxxxx</Kennung>
<Strassenbau_Organisation_Bezeichnung>xxxxxxx</Strassenbau_Organisation_Bezeichnung>
<Adresszeile_2>xxxxxxxxxxxxx</Adresszeile_2>
<Adresszeile_3>xxxxxxxxxxxxxx</Adresszeile_3>
<Adresszeile_4>xxxxxxxxxxxxxxxxx</Adresszeile_4>
<Strasse>xxxxxxxxxxxxxx</Strasse>
<PLZ>xxxxx</PLZ>
<Ort>xxxxxxxxxxxxxx</Ort>
<NUTS>xxxxx</NUTS>
<Telefon>xxxxxxxxxxx</Telefon>
<Fax>xxxxxxxxxxx</Fax>
<E_Mail>[email protected]</E_Mail>
</Strassenbaudienststelle>
</CSBF_Vergabemeldung>
Elapsed: 00:00:00.11
SQL> -
Xml file manipulation using XI file adapter
my requirement is to change an attribute value in an xml file using XI.
example
<County InternalID="24581" Action="None">
should be changed to
<County InternalID="24581" Action="Insert">
I have used Adapter specific attributes to get thesame file name, which is looking at the target folder,
but the problem is
once it reached the target foelder
it looks like this
<ns0:County InternalID="24581" Action="Insert">
I donot need ns0:
Any thoughts please.I have single xsd which I uploaded as External defintion, with names ED_source and ED_target in Repository
after that directly I created Message interfaces( no Message Type, no DataType)
I tried to remove namespace in repository, do I need to remove name space in the XSD itself and then upload it in repository. -
DTD and XSD Validation for xml file
hi kindly reply to this mail guru'ssss
i am facing a problem in parising a xml file against dtd and xsd.
i have the dtd which contains only enitities that can be present in the xml file and the xsd file for validation against elements and attribute.
when DTD is present then it is throwing errors like the elements should be declared.
when i take out the doctype line and validate against schema its throwing the error that particular entity is not found or declared.
public Vector validateSchema(String SchemaUrl, String XmlDocumentUrl)
SAXParser parser =new SAXParser();
try{
//parser.setNamespaceAware (true);
//parser.s
parser.setFeature("http://xml.org/sax/features/validation",true);
parser.setFeature("http://apache.org/xml/features/validation/schema",true);
parser.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true);
// parser.setProperty("http://xml.org/sax/properties/declaration-handler", new DTDHandl());
parser.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",SchemaUrl);
// parser.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
// System.out.println(parser.getDTDHandler());
// UnparsedCache cache = new UnparsedCache();
// parser.setDTDHandler(cache);
InputSource inputSource =new InputSource(new java.io.FileInputStream(new java.io.File(XmlDocumentUrl)));
// parser.setDTDHandler(new myDTDHandler());
//parser.setEntityResolver(new CustomResolver());
// parser.setContentHandler(this);
Validator handler=new Validator();
parser.setErrorHandler(handler);
parser.parse(inputSource);
if(handler.validationError==true)
System.out.println("XML Document is not valid");
else
System.out.println("XML Document is valid");
for(int i=0;i<ErrorLines.size();i++){
System.out.println(ErrorLines.elementAt(i));
}catch(java.io.IOException ioe){
System.out.println("IOException"+ioe.getMessage());
}catch (SAXParseException e) {
System.out.println("SAXParseException "+e.getMessage());
}catch (SAXException e) {
System.out.println("SAXException"+e.getMessage());
return ErrorLines;
what could be soln to this.Hi
Venky_Ferrari.
Based on your description, your case related to XMLXSD, SO I will move your thread to
Data Platform Development > XML, System.Xml, MSXML and XmlLite
forum for better support.
Best regards,
Kristin
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
Can XML files be used for data?
We have an XML file that contains all of the data we want to use for a model. Is there any way that this can be used instead of a database query?
If you find a JDBC driver for XML, then yes.
Check out the Visual Composer WIKI under JDBC:
https://wiki.sdn.sap.com/wiki/display/VC/Connectivity
and also
Where can I find JDBC drivers?
https://wiki.sdn.sap.com/wiki/display/VC/JDBC+Drivers -
Read any XML File Elements using SAX Parser in J2se
Hi All
I can able to parsed one structured XML file using SAX
Sample code :
// ===========================================================
// SAX DocumentHandler methods
// ===========================================================
public void startDocument() throws SAXException {
logger.info("Start of document");
public void endDocument() throws SAXException {
logger.info("End of document");
public void startElement(String namespaceURI, String localName, // local
// name
String qualName, // qualified name
Attributes attrs) throws SAXException {
elemName = new String(localName); // element name
if (elemName.equals(""))
elemName = new String(qualName); // namespaceAware = false
tagPosition = TAG_START;
// Set the string for accumulating the text in a tag to empty
elemChars = "";
// If the element name is "row", create a new row instance
// If the element is "indexxid", "ModelPrice", or "ModelSpread",
// the value will be read in the method "characters" and stored.
if (elemName.equals("row")) {
row = new IndexRow();
numRows++;
// logger.info("Number of numRow:"+numRows);
} // end method startElement
public void endElement(String namespaceURI, String simpleName, // simple
// name
String qualName // qualified name
) throws SAXException {
elemName = new String(simpleName);
if (elemName.equals(""))
elemName = new String(qualName); // namespaceAware = false
tagPosition = TAG_END;
String indexId = new String();
Double dblVal = new Double(0);
// If element name is "row", put the current row in the map for row
// instances
if (elemName.equals("row")) {
if (numRows <= 5) { logger.info("Row is: " + row.toString()); }
//ABX
//indexRows.put(row.getIndexxId(), row);
if (family.equals("ABX.HE")){
indexRows.put(row.getIndexREDId(), row);
else {
//CDX ITRXX
indexRows.put(row.getIndexxId(), row);
} else if (elemName.equals("IndexID")) {
row.setIndexxId(elemChars);
// Leave double value at default of zero if there are no chars
if (elemChars.trim().length() != 0) {
dblVal = new Double(elemChars);
row.setCompositeSpread(dblVal);
indexId = row.getIndexxId();
} else if (elemName.equals("REDCode")) {
row.setRedCode(elemChars);
else if (elemName.equals("Name")) {
row.setRowName(elemChars);
} else if (elemName.equals("Series")) {
row.setSeries(elemChars);
} else if (elemName.equals("Version")) {
row.setVersion(elemChars);
} else if (elemName.equals("Term")) {
row.setTerm(elemChars);
} else if (elemName.equals("Maturity")) {
row.setMaturity(elemChars);
} else if (elemName.equals("OnTheRun")) {
row.setOnTheRun(elemChars);
} else if (elemName.equals("Date")) {
row.setRowDate(elemChars);
} else if (elemName.equals("Depth")) {
row.setDepth(elemChars);
else if (elemName.equals("Heat")) {
// logger.info("Chars for element " + elemName + " are '" +
// elemChars + "'");
// Leave double value at default of zero if there are no chars
if (elemChars.trim().length() != 0) {
dblVal = new Double(elemChars);
row.setHeat(dblVal);
indexId = row.getIndexxId();
// ABX.HE
else if (elemName.equals("IndexREDId")){
row.setIndexREDId(elemChars);
else if (elemName.equals("Coupon")){
row.setCoupon(elemChars);
if (elemName.equals("Ontherun")) {
row.setOnTheRun(elemChars);
} // end method endElement
public void characters(char buf[], int offset, int len) throws SAXException {
// If at end of element, there will be no characters
if (tagPosition == TAG_END) {
return;
// The characteres method may be called more than once
// for an element if the internal buffer fills up.
// Append the characters until the end of the element.
String strVal = new String(buf, offset, len);
elemChars = elemChars + strVal;
} // end method characters
} // end class MarkItIndexLoader
but the problem is i want to read (parse) any XML file means any Elemets would be change any time using SAX .In the above example
else if (elemName.equals("Heat")) {
else if (elemName.equals("IndexREDId")){
} else if (elemName.equals("Maturity")) {
like above I am doing hard code Elements names and reading the values so i don't want hard coding the elements names I want to read any element name and value dynamically.
If i give any one below XML file i want to read the Elements and displaying to console without changing any code i want to read the XML document.
EX:
Student.XML: <root>..</StName>..</StAge>...</root>
Employee.XML: <root>..</EmpName>..</EmpAge>...</root>
CdCatalog.XML: <root>..</Cdtitle>...</CdNumber>...</root>
I need one java program can ready any type of XML file elements and send to the Database table.
Please any one done like this task please suggest some reference links or books or sample snippet which can help me to develop program in my requirement.
Thanks in advance
Regards
satishYou should ask in the Java forum.
Regards
Stefan -
Missing XSD line in XML file - how to add it?
Dear all,
We're trying to add in the XSD information to a file generated from R/3 by a standard program, which the developers don't want to adapt, as it's used by several other programs. We'd like to do this in XI - does anyone know how or have any experience about why this would be a bad idea?
Many thanks in advance,
Lisa HowdleHi Lisa,
What I understood from your question is: SAP is generating a file and you want to add few more things to that file in XI.
If we both are on the same page then you can create a xsd or extend the current xsd with the additional fields and then can load the file and send across XI.
If we are not on the same page then can you throw some more light on this?
Regards,
---Satish
Maybe you are looking for
-
Connecting MiFi 4510L mobile hotspot to a PC
I recently upgraded my mobile hotspot to the 4510L 4G LTE. My previous MiFi device allowed me to connect my PC to the internet by USB cable. My new device came with a USB cable however it says its only used for updates/upgrades. I tried to use it any
-
Dynamic configuration : possibility of adding custom Key?
hi experts, is it possible that i can add a new custom key like for example namespace : http://sap.com/xi/XI/System/ERROR key : ERRORDESC and put it inside the Dynamic configuration during a mapping and then use it further? or are we limited to t
-
Have only got test call page on my android phone and Can't access my contacts list
Help
-
Database Adapter Wizard does not show accessible table
HI guys, in the wizard I am unable to see the tables which I need to use for database adapter. But I do have access to those tables, and able to select from them in SQL worksheet from with in Jdev. I dont own the tables, but my user id have readable
-
I want to know the significance of AUC per source strucutre,line item settlement and summary settlement in details with examples in tcode oita(in spro).