Problem in parsing xml
hi,
my condition on the parsing of my xml data is not working.
xml = new XML(e.target.data);
totalArticles.text = xml.*.length();
var objectArray:Array = [];
var xmllist:XMLList = xml.children();
for(var a:Number = 0; a<xmllist.length(); a++){
var object:Object = {};
for(var b:Number = 0; b< xmllist[a].children().length(); b++){
var item:XML = xmllist[a].children()[b];
trace(item);
if(item.name().toString() == "RelatedTopic"){
var topicObject:Object = {};
trace(topicObject);
for(var c:Number = 0; c<item.children().length(); c++){
topicObject[item.children()[c].name().toString()] = item.children()[c].toString()
object[item.name()] = topicObject;
}else{
object[item.name()] = item.toString();
objectArray.push(object);
the code is not entering on the if statement.. i'm trying to parse all the children of Related Topic node and push it in an array.
please help.. thanks..
how will i get the parent node Related Topics?
<RelatedTopics>
<RelatedTopic>
<thumbImage>pics/img_1.png</thumbImage>
<summary color="black">This is a text summary</summary>
<footer color="white">Read more</footer>
<postingURL>http://www.accenture.com</postingURL>
<bgColor>green</bgColor>
</RelatedTopic>
what i'm getting in the trace are the children of relatedtopics. basically its what i want and then push its children to an array. because i'll be using all its node.
example. ill get the thumbImage and display it's image on a movie clip..and same as the summary, where i'll display it in a dynamic text..
i'm not really good at this..
thanks for the help..
Similar Messages
-
I am trying to parse XML Schema using XSOM. The Schema has <xs:include>s
e.g. I have first.xsd which includes second.xsd and second.xsd again includes third.xsd.
First.xsd
<xs:include schemaLocation="../Second.xsd">....
Second.xsd
<xs:include schemaLocation="Third.xsd">....
When I parse "First.xsd" parser passes the correct path "C:/XSDSchema/Second.xsd"(First.xsd resides in "C:/XSDSchema/Schema/") to the EntityResolver's resolveEntity method. But for Second.xsd it passes "Third.xsd" only (Third.xsd resides in "C:/XSDSchema/" ) .
Any Idea ?????Here is a screenshort of the part of my workflow:
In the mappings of the "Set Value" activity, I have one line with those properties:
Location: /process_data/bonusValidationForm/object/data/xdp/datasets/data/BonusValidationForm/buMan agerID
Expression: /process_data/currentUser/object/@userId
Where:
bonusValidationForm is a process variable of my workflow that point my xdp form
buManagerID is the textfield I want to set
currentUser is a process variable (type User) that was well setted by the task Find BU Manager -
Problem in parsing XML using DOM Parser.
Hi,
I am parsing an XML using DOM Parser.
When i try to get attributes of a node, i dont get in the order it is written. For Eg. This the node:
<Level0 label="News" link="/website/ing_news.nsf/ViewNewsForm?OpenForm&All" level="202" uid="COGN-4MNMT3" parentid="aaaa">
When i try to print the attribute values i should get in the order:
News, /website/ing_news.nsf/ViewNewsForm?OpenForm&All, 202, COGN-4MNMT3, aaaa
BUT I AM GETTING IN THE ORDER:
News, 202, /website/ing_news.nsf/ViewNewsForm?OpenForm&All, aaaa, COGN-4MNMT3
Is there any way to sort this problem out?
Thanks and Regards,
AshokHi Guys,
Thanks a lot for your replies.
But i want to keep all the values as attributes only.
the XML file is as shown below:
<Menu>
<Level0 label="News" link="/website/ing_news.nsf/ViewNewsForm?OpenForm&All" level="202" uid="COGN-4MNMT3" parentid="aaaa" children="3">
<Level1 label="ING News" link="" level="1" uid="COGN-4MNN89" parentid="COGN-4MNMT3" children="3" >
<Level2 label="All ING News" link="/website/ing_news.nsf/ViewNewsForm?OpenForm&All" level="2" uid="INGD-4MVTK2" parentid="COGN-4MNN89" children="0">
</Level2>
</Level1>
</Level0>
The code i was using to get attributes is:
String strElementName = new String(node.getNodeName());
// System.out.println("strElementName:"+node.getNodeName());
NamedNodeMap attrs = node.getAttributes();
if (attrs != null) {
int iLength = attrs.getLength();
for (int i = 0; i < iLength; i++) {
String strAttributes = (String) attrs.item(i).getNodeName();
String strValues = (String) attrs.item(i).getNodeValue();
Also is it not possible to Enforce the order using some Schema/DTD in this case?
TIA
Ashok -
Problem in parsing XML using DOM
I am getting one XML file as string like <?xml version="1.0" encoding="ISO-8859-1" ?> <DMSI-ACTIVITY-COMMENTS> </DMSI-ACTIVITY-COMMENTS>
Every time I want to add new node <ACTIVITY>
<NAME></NAME>
<ID></ID>
<COMMENT></COMMENT>
</ACTIVITY> whenever user make any change in my application.
I wrote code....
InputStream inputStream = new ByteArrayInputStream(file.getBytes());
Document doc = docBuilder.parse(inputStream);
Element activityNode = doc.createElement("ACTIVITY");
Element nameNode = doc.createElement("NAME");
activityNode.appendChild(nameNode);
Text nametextNode = doc.createTextNode(name);
nameNode.appendChild(nametextNode);
Element root = doc.getDocumentElement();
root.appendChild(activityNode);
String resultUDA = doc.toString();
Problem: Here I am getting value of resultUDA is [#document: null]. I need updated XML as String....
any one can give me suggestion or any other option to solve this issue...
thanks in advance...I got it ....pls check on it
http://www.theserverside.com/discussions/thread.tss?thread_id=26060 -
XI Soap Adapter: problems in parsing XML
Hallo,
I call a Web Service using XMLSpy and this is the response (note tag <File>):
<SOAPSDK4:ExpBaselineResponse xmlns:SOAPSDK4="http://tempuri.org/PRWBS_PRIMAVERA/message/">
<RESULT>OK</RESULT>
<File><?xml version='1.0' encoding='UTF-8'?>
<Dati:Parametri xmlns:Dati="Schema">
<ELSAG xmlns="Schema">
<proj_id>4623</proj_id>
<BS_short_name>FS0084AAAA01 - B1</BS_short_name>
<BS_proj_id>1302</BS_proj_id>
<TARGET_START>2004-04-01</TARGET_START>
....etc...
If I call the same Web Service from XI, this is the response:
<SOAPSDK4:ExpBaselineResponse xmlns:SOAPSDK4="http://tempuri.org/PRWBS_PRIMAVERA/message/" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAPSDK3="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAPSDK2="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAPSDK1="http://www.w3.org/2001/XMLSchema">
<RESULT>OK</RESULT>
<File><?xml version="1.0" standalone="yes"?>
<Dati:Parametri xmlns:Dati="Schema">
<ELSAG xmlns="Schema">
<proj_id>4623</proj_id>
<BS_short_name>FS0084AAAA01 - B1</BS_short_name>
<BS_proj_id>1302</BS_proj_id>
<TARGET_START>2004-04-01</TARGET_START>
....etc....
In my flow, I use a java mapping to parse the content of tag <File> into a message.
My mapping works correctly only with the first option.
Is it possible to change XI Soap Adapter encoding for HTML?
My java mapping uses this parser:
public void execute(InputStream MyInputStream, OutputStream MyOutputStream)
throws StreamTransformationException {
SAXReader reader = new SAXReader();
Document document;
try {
document = reader.read(MyInputStream);
this instruction generates an Exception only with XI message.
Can anybody help me??
Thanks;-)Hi,
I would suggest you go through this Pdf for the SOAP Adapter configuration:
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/40728f7b-0401-0010-d9bc-8c73884a3789
And also have a glance on the info for webservices given below,
Just go through these links and they will surely help you learn more about Webservices:
<a href="/people/siva.maranani/blog/2005/09/03/invoke-webservices-using-sapxi Webservices using SAPXI</a>
<a href="/people/siva.maranani/blog/2005/05/23/communication-between-sap-system-webservice-using-proxies between SAP System & Webservice Using Proxies</a>
You can Go through these links to get some info about accessing Webservices:
http://help.sap.com/saphelp_nw04/helpdata/en/d6/f9bc3d52f39d33e10000000a11405a/content.htm
http://help.sap.com/saphelp_nw04/helpdata/en/b7/d7baaf1481a349ab723e3acd7334b3/content.htm
Go through these links which will surely help you find an answer to your problem.....
Regards,
Abhy -
Problems whilst Parsing XML with KXML2
I have been doing a lot of reading up on the APIs of XMLPull and KXML2.
I seem to be facing a problem which can't be solved just by reading but rather the expertise of the more experienced programmers dealing with XML parsing in J2ME.
I know how long it takes to process an entire XML document, I just would like to parse certain parts of the document. For e.g. instead of reading the whole document, say I just want to read the first 7 items and subsequently, the next 7 items when the user clicks on the next page?
In other words, I wish to incorporate paging. Is it possible? Or if you have an alternative solution which will not make a user wait too long, please share it!
Can anyone help me?I don't think that is possible. We can't make the XML
any smaller because it contains all the information I
want to display. Just that I want to display it in
pages/sections so as to reduce the load.
So I was thinking of whether it is possible to read
the first 5 <title> tags and next 5 for every page
... etcimagine that you have 20 pages so the user will have to download a 20 x 5 items xml file?
if the user stops the navigation at page 4, he will download 16 pages for nothing so that's
why i told you to separate the results...
an xml file for each page and not a huge for all ! -
Problem while parsing xml file
HI
I have a xml file which looks like this
<--A>
<ID>ABCD</ID>
<--B>
<Amount1>1</Amount1>
<Amount2>2</Amount2>
<--/B>
<--B>
<Amount1>3</Amount1>
<Amount2>4</Amount2>
<--/B>
<--/A>
<--A>
<ID>EFGH</ID>
<--B>
<Amount1>5</Amount1>
<Amount2>6</Amount2>
<--/B>
<--B>
<Amount1>7</Amount1>
<Amount2>8</Amount2>
<--/B>
<--/A>
(Appended -- before tags so that its displayed properly here)
I have to parse through this xml file and for each ID,i have to display corresponding amounts.As we can see //A represents each row.
I have written code like this.
l_clob := '<<<XML Content as shown above >>>;
dbms_xmlparser.parseClob(l_parser, l_clob);
l_doc := dbms_xmlparser.getDocument(l_parser);
-- Free resources associated with the CLOB and Parser now they are no longer needed.
dbms_xmlparser.freeParser(l_parser);
l_nl1 := dbms_xslprocessor.selectNodes(dbms_xmldom.makeNode(l_doc),'//A');
FOR cur_rec IN 0 .. dbms_xmldom.getLength(l_nl1) - 1 LOOP
l_n1 := dbms_xmldom.item(l_nl1, cur_rec);
lv_id := dbms_xslprocessor.valueOf(l_n1,'ID/text()');
l_nl2 := dbms_xslprocessor.selectNodes(dbms_xmldom.makeNode(l_doc),'//B');
FOR cur_rec2 IN 0 .. dbms_xmldom.getLength(l_nl2) - 1 LOOP
l_n2 := dbms_xmldom.item(l_nl2, cur_rec2);
lv_Amount1 := dbms_xslprocessor.valueOf(l_n2,'Amount1/text()');
lv_Amount2 := dbms_xslprocessor.valueOf(l_n2,'Amount2/text()');
dbms_Output.put_line (lv_id ||lv_Amount1|| lv_Amount2 );
end loop;
end loop;
The problem i am facing is , in the second loop i want to disdplay only values corresponding to ID which is coming in first loop.But when i give //B,its going through all the values in xml file under //B but not going through //B part of each record fethed in loop1.
How can we display Each ID and corresponding amounts only(Not all the Amounts in XML File).
Thanks
Pramod
Edited by: 842802 on Mar 21, 2011 9:27 AMNo need for Pl/SQL:
with t as (
select '<A>
<ID>ABCD</ID>
<B>
<Amount1>1</Amount1>
<Amount2>2</Amount2>
</B>
<B>
<Amount1>3</Amount1>
<Amount2>4</Amount2>
</B>
</A>
<A>
<ID>EFGH</ID>
<B>
<Amount1>5</Amount1>
<Amount2>6</Amount2>
</B>
<B>
<Amount1>7</Amount1>
<Amount2>8</Amount2>
</B>
</A>' x from dual
select id,
amount1,
amount2
from t,
xmltable(
'$d/D/A'
passing xmltype('<D>' || x || '</D>') as "d"
columns id varchar2(10) path 'ID',
B xmltype path '/'
) y,
xmltable(
'$d/A/B'
passing y.b as "d"
columns amount1 number path '/B/Amount1',
amount2 number path '/B/Amount2'
) z
ID AMOUNT1 AMOUNT2
ABCD 1 2
ABCD 3 4
EFGH 5 6
EFGH 7 8
SQL> SY. -
Problem while parsing xml file using DOM
I have a xml file NewXML.xml. When I parse it I'm not getting the expected output: I'm trying to get only the value of the "name" tag. When I tried getElementByTagName("name"), I'm not getting the expected result.
Here is my xml file based on a schema
<?xml version="1.0" encoding="UTF-8"?>
<student xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="NewXMLSchema.xsd">
<name>john</name>
<id>1000</id>
</student>
Coding:
public static void main(String argv[])
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
Document document ;
try {
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.parse( "NewXML.xml" );
NodeList nodeList = (document.getElementsByTagName("name") );
System.out.println(nodeList.getLength()+" node list "+nodeList.item(0));
System.out.println(nodeList.item(0).getNodeValue());
NodeList nodeList1 = nodeList.item(0).getChildNodes();
System.out.println(nodeList1.getLength()+" node list "+nodeList1.item(0));
System.out.println(nodeList1.item(0).getNodeValue());
When I ran the above coding I got:
1 node list [name: null]
null
1 node list [#text: name]
name
What should I do to get the result "john" inorder to change it
Thanks
rathiSystem.out.println(nodeList.item(0).getFirstChild().getNodeValue());
-
Problem in parsing xml file via JWS
We are using custom java api to send xml request to our xmlserver. This does request/response in xml. When I run the application in standalone environment it works fine. But after using JWS, HttpResponse object is skipping some bytes (specifically content type node) from the xml response sent by server. So getting parserexception in custom API. Is there any limit or memory setting that is required to handle large xml file?
I got it ....pls check on it
http://www.theserverside.com/discussions/thread.tss?thread_id=26060 -
Encoding problem (c++ parser v2).
Hi,
I have problems with parsing XML that contains locale specific chars.
My ORACLE_HOME and ORA_NLS env. vars are set correctly.
Here is a sample:
<?xml version="1.0" encoding="ISO-8859-1"?>
<ROOT>
<TEST>i</TEST>
</ROOT>
After xmlparse() method call I get LPX-00225 error. But when I add two SPACES or non-locale specific characters in front of </TEST> tag xmlparse() works fine.
Any suggestion?
I'm using Oracle 8.1.7, 2.0.4.0.0 version of XDK for C++ on AIX4.3 and Compaq Tru64
An other sample :
<?xml version="1.0" encoding="ISO-8859-1"?>
<ROOT>
<TEST att="i">bla bla bla</TEST>
</ROOT>
I get LPX-00244 error.
If i add two spaces after non-locale specific character it works fine.
I've read that 2.0.7.0.0 version solve this problem, so when this version will be available on AIX4.3 and Compaq Tru64 ?
I've read that you are planning on shipping the NLS datafile along with the XDK in a future release. I'm intersted to known when, because I don't want to install the Oracle 8i client on all the machine wich run Xml application.
Thanks
DidierI verified that your test case is fixed in 2.0.7. You will get that version with Oracle 9.0.0 on AIX and Compaq Unix.
Unfortunately, there is no schedule for shipping the NLS data files with the XDK. -
Problem in parsing white spaces using if_ixml_parser
Hello People,
I have a problem in parsing XML file in one of my programs.
The program uses the method get_value( ) of class if_ixml_node to fetch a value. In the XML file when the value is spaceA, then after parsing, the value fetched is A and not spaceA.
Is there any way to fetch the white spaces also?
Here is the sample tag. The value inside the tags is " A" and after parsing I get "A" the blank is ignored.
<ns1:IndiceCible> A</ns1:IndiceCible>
DATA : l_node_fils TYPE REF TO if_ixml_node.
indice_val = l_node_fils->get_value( ).
In some XML parsing forums I saw that if we add the option as shown below, then the parsing works properly. But this did not work in my case.
<ns1:IndiceCible xml:space="preserve"> A</ns1:IndiceCible>
The input XML file is as follows.
<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header><env:Flow xmlns:env="http://xml.inetpsa.com/Structure/Informatique/DeveloppementSI/ReferentielEchange"><env:MessageID>0414
2636F4888F4B4A579A21E10000000A52931C</env:MessageID><env:From>R3P INTERFACES</env:From><env:To>SAP</env:To><env:TimeStamp>2010-03-04T14:26:36.672+01:00</env:TimeStamp></env:Flow></SOAP-ENV:Header><SOAP-ENV:Body><env:Response xmlns:env="http://xml.inetpsa.
com/Structure/Informatique/DeveloppementSI/ReferentielEchange"><env:Values><ns1:ListeTranscodifications xmlns:ns1="http://xml.inetpsa.com/ProduitProcess/Produit/Transcodification"><ns1:Transcodification id="1 "><ns1:Statut>KO</ns1:Statut><ns1:Message>ERRO
R : Indice incorrect</ns1:Message><ns1:ReferenceCible>969099979A</ns1:ReferenceCible><ns1:IndiceCible> A</ns1:IndiceCible><ns1:ColoreCible>SS_TEINTE</ns1:ColoreCible></ns1:Transcodification></ns1:ListeTranscodifications></env:Values><env:Status><env:Code>
0</env:Code><env:Label></env:Label></env:Status></env:Response></SOAP-ENV:Body></SOAP-ENV:Envelope>
Regards,
Praveenuse IF_XML_PARSER~CL_ADD_PRESERVE_SPACE_ELEMENT method:
PARAMETERS preserve TYPE flag AS checkbox.
DATA lo_ixml TYPE REF TO if_ixml.
DATA lo_streamfactory TYPE REF TO if_ixml_stream_factory.
DATA lo_parser TYPE REF TO if_ixml_parser.
DATA lo_istream TYPE REF TO if_ixml_istream.
DATA lo_document TYPE REF TO if_ixml_document.
DATA lo_node TYPE REF TO if_ixml_node.
DATA l_node_value TYPE string.
lo_ixml = cl_ixml=>create( ).
lo_streamfactory = lo_ixml->create_stream_factory( ).
lo_istream = lo_streamfactory->create_istream_string(
string = '<?xml version="1.0" encoding="iso-8859-1"?><DATA> WAAA</DATA>' ).
lo_document = lo_ixml->create_document( ).
lo_parser = lo_ixml->create_parser( stream_factory = lo_streamfactory
istream = lo_istream
document = lo_document ).
IF preserve = 'X'.
lo_parser->ADD_PRESERVE_SPACE_ELEMENT( ). "<========= HERE
ENDIF.
lo_parser->parse( ).
lo_node = lo_document->find_from_name( name = 'DATA').
l_node_value = lo_node->get_value( ).
ASSERT ( preserve = 'X' AND l_node_value = ' WAAA' )
OR ( preserve = space AND l_node_value = 'WAAA' ). -
Problem in parsing huge XML document
Hi,
i am getting the problem when trying to parse xml doc. which contains data more then 1 lacs. using jaxp (i.e. NodeList). i get the execption outofmemory.Which implementation of JAXP are you using? If it is a large file containing many of the same "documents", then consider using SAX as it is an event driven parser meaning it does not have to read the whole of the file before it can start processing it. Instead, it fires events when it sees the beginning and end of a "document" and also on completion of the elements. You can then create and destroy objects during the document processing stage which helps keep the memory consumption under control.
-
Problem in parsing an XML using SAX parser
Hai All,
I have got a problem in parsing an XML using SAX parser.
I have an XML (sample below) which need to be parsed
<line-items>
<item num="1">
<part-number>PN1234</part-number>
<quantity uom="ea">10</quantity>
<lpn>LPN1060</lpn>
<reference num="1">Line ref 1</reference>
<reference num="2">Line ref 2</reference>
<reference num="3">Line ref 3</reference>
</item>
<item num="2">
<part-number>PN1527</part-number>
<quantity uom="lbs">5</quantity>
<lpn>LPN2152</lpn>
<reference num="1">Line ref 1</reference>
<reference num="2">Line ref 2</reference>
<reference num="3">Line ref 3</reference>
</item>
<item num="n">
</item>
</line-items>
There can be any number of items( 1 to n). I need to parse these
item values using SAX parser and invoke a stored procedure for
each item with its
values(partnumber,qty,lpn,refnum1,refnum2,refnum3).
Suppose if there are 100 items, i need to invoke the stored
procedure sp1() 100 times for each item.
I need to invoke the stored procedure in endDocument() method of
SAX event handler and not in endelement() method.
What is the best way to store those values and invoke the stored
procedure in enddocument() method.
Any help would br greatly appreciated.
Thanks in advance
Pooja.VO or ValueObject is a trendy new name for Beans.
So just create an item class with variables for each of the sub elements.
<item>
<part-number>PN1234</part-number>
<quantity uom="ea">10</quantity>
<lpn>LPN1060</lpn>
<reference num="1">Line ref 1</reference>
<reference num="2">Line ref 2</reference>
<reference num="3">Line ref 3</reference>
</item>
public class ItemVO
String partNumber;
int quantity;
String quantityType;
String lpn;
List references = new ArrayList();
* @return Returns the lpn.
public String getLpn()
return this.lpn;
* @param lpn The lpn to set.
public void setLpn(String lpn)
this.lpn = lpn;
* @return Returns the partNumber.
public String getPartNumber()
return this.partNumber;
* @param partNumber The partNumber to set.
public void setPartNumber(String partNumber)
this.partNumber = partNumber;
* @return Returns the quantity.
public int getQuantity()
return this.quantity;
* @param quantity The quantity to set.
public void setQuantity(int quantity)
this.quantity = quantity;
* @return Returns the quantityType.
public String getQuantityType()
return this.quantityType;
* @param quantityType The quantityType to set.
public void setQuantityType(String quantityType)
this.quantityType = quantityType;
* @return Returns the references.
public List getReferences()
return this.references;
* @param references The references to set.
public void setReferences(List references)
this.references = references; -
SAX Parser XML Validation Problems
Hi,
I’m having problems getting an xml document to validate within Weblogic 8.1. I am trying to parse a document that references both a dtd and xsd. Both the schema and dtd reference need to be substituted so they use local paths. I specify the schema the parser should use and have created an entityResolver to change the dtd reference.
When this runs as a standalone app from eclipse the file parses and validates without a problem. When deployed to the app server the process seems to be unable read the contents of the dtd. Its not that it cannot find the file (no FileNotFoundException is thrown but this can be created if I delete the dtd) rather it seems to find no declared elements.
Initial thought was that the code didn’t have access to read the dtd from its location on disk, to check I moved the dtd to within the deployed war and reference as a resource. The problem still persists.
Code Snippet:
boolean isValid = false;
try {
// Create and configure factory
SAXParserFactory factory = SAXParserFactoryImpl.newInstance();
factory.setValidating(true);
factory.setNamespaceAware(true);
// To be notified of validation errors in the XML document,
// add a custom error handler to the document builder
PIMSFeedFileValidationHandler handler
= new PIMSFeedFileValidationHandler();
// Create and Configure Parser
SAXParser parser = factory.newSAXParser();
parser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
parser.setProperty(NAMESPACE_PROPERTY_KEY, getSchemaFilePath());
// Set reader with entityResolver for dtd
XMLReader xmlReader = parser.getXMLReader();
xmlReader.setEntityResolver(new SAXEntityResolver(this.dtdPath));
// convert file to URL, as it is a remote file
URL url = super.getFile().toURL();
// Open an input stream and parse
InputStream is = url.openStream();
xmlReader.setErrorHandler(handler);
xmlReader.parse(new InputSource(is));
is.close();
// get the result of parsing the document by checking the
// errorhandler's isValid property
isValid = handler.isValid();
if (!isValid) {
LOGGER.warn(handler.getMessage());
LOGGER.debug("XML file is valid XML? " + isValid);
} catch (ParserConfigurationException e) {
LOGGER.error("Error parsing file", e);
} catch (SAXException e) {
LOGGER.error("Error parsing file", e);
} catch (IOException e) {
throw new FeedException(e);
return isValid;
See stack trace below for a little more info.
2005-01-28 10:24:09,217 [DEBUG] [file] - Attempting validation of file 'cw501205.wa1.xml' with schema at 'C:/pims-feeds/hansard/schema/hansard-v1-9.xsd'
2005-01-28 10:24:09,217 [DEBUG] [file] - Entity Resolver is using DTD path file:C:/Vignette/runtime_services/8.1/install/common/nodemanager/
VgnVCMServer/stage/pims-hansard/pims-hansard.war/WEB-INF/classes/com/morse/pims/cms/feed/sax/ISO-Entities.dtd
2005-01-28 10:24:09,227 [DEBUG] [file] - Creating InputSource at: file:C:/Vignette/runtime_services/8.1/install/common/nodemanager/VgnVCMServer/stage/pims-hansard/pims-hansard.war/WEB-INF/classes/com/morse/pims/cms/feed/sax/ISO-Entities.dtd
2005-01-28 10:24:09,718 [WARN ] [file] - org.xml.sax.SAXParseException: Element type "Hansard" must be declared.
org.xml.sax.SAXParseException: Element type "Session" must be declared.
org.xml.sax.SAXParseException: Element type "DailyRecord" must be declared.
org.xml.sax.SAXParseException: Element type "Volume" must be declared.
org.xml.sax.SAXParseException: Element type "Written" must be declared.
org.xml.sax.SAXParseException: Element type "WrittenHeading" must be declared.
org.xml.sax.SAXParseException: Element type "Introduction" must be declared.
… continues for all the elements in the doc
2005-01-28 10:24:10,519 [DEBUG] [file] - XML file is valid XML? false
2005-01-28 10:24:10,519 [WARN ] [file] - Daily Part file 'cw501205.wa1.xml' was not valid XML and was not processed.
Has anybody seen this behavior before with weblogic and if so how have you resolved the issue.
Thanks in Advance
AdamHi David,
I have checked the ejb-jar.xml file and there is no duplicate values in it and the other things is that the same application is been deployed on OAS 10G and websphere and its working fine. In the forum someone has replied to a similar problem that there is bug in Weblogic 10.3 and its CR no 376292. I am not sure about it, does anyone any information about it.
Thanks and Regards
Deepak Dani -
Problem parsing XML with schema when extracted from a jar file
I am having a problem parsing XML with a schema, both of which are extracted from a jar file. I am using using ZipFile to get InputStream objects for the appropriate ZipEntry objects in the jar file. My XML is encrypted so I decrypt it to a temporary file. I am then attempting to parse the temporary file with the schema using DocumentBuilder.parse.
I get the following exception:
org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element '<root element name>'
This was all working OK before I jarred everything (i.e. when I was using standalone files, rather than InputStreams retrieved from a jar).
I have output the retrieved XML to a file and compared it with my original source and they are identical.
I am baffled because the nature of the exception suggests that the schema has been read and parsed correctly but the XML file is not parsing against the schema.
Any suggestions?
The code is as follows:
public void open(File input) throws IOException, CSLXMLException {
InputStream schema = ZipFileHandler.getResourceAsStream("<jar file name>", "<schema resource name>");
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;
try {
factory.setNamespaceAware(true);
factory.setValidating(true);
factory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
factory.setAttribute(JAXP_SCHEMA_SOURCE, schema);
builder = factory.newDocumentBuilder();
builder.setErrorHandler(new CSLXMLParseHandler());
} catch (Exception builderException) {
throw new CSLXMLException("Error setting up SAX: " + builderException.toString());
Document document = null;
try {
document = builder.parse(input);
} catch (SAXException parseException) {
throw new CSLXMLException(parseException.toString());
}I was originally using getSystemResource, which worked fine until I jarred the application. The problem appears to be that resources returned from a jar file cannot be used in the same way as resources returned directly from the file system. You have to use the ZipFile class (or its JarFile subclass) to locate the ZipEntry in the jar file and then use ZipFile.getInputStream(ZipEntry) to convert this to an InputStream. I have seen example code where an InputStream is used for the JAXP_SCHEMA_SOURCE attribute but, for some reason, this did not work with the InputStream returned by ZipFile.getInputStream. Like you, I have also seen examples that use a URL but they appear to be URL's that point to a file not URL's that point to an entry in a jar file.
Maybe there is another way around this but writing to a file works and I set use File.deleteOnExit() to ensure things are tidied afterwards.
Maybe you are looking for
-
Table for Customer and vendor open balance on a key date
Dear All, Can anyone please let me know Table for Customer and vendor open balance on a key date. We are developing one customized report. I have checked with the below table : Customer-KNC1, KNC3,BSID, BSAD Vendor-LFC1, LFC3, BSIK, BSAK. But these a
-
Blue Screen of Death and USB malfunctions on HP Envy running Windows 7
Hello. I have an HP Envy 14 notebook PC. It's running Microsoft Windows 7 Home Premium 64-bit, version 6.1.7601. When I run it, I eventually starts getting an error message from the right of the desktop toolbar telling me that a USB device I plugged
-
Viewing form in Preview Mode Failed. Error: Table not found [131-183]
Hi, I have created a user form in screen painter in SBODemo. Created UDT, UDF & Registered UDO through my SDK code. Everything works fine. But when i run my addon on any other DB, and open my custom form it gives an error : Table Not Found. I have ch
-
Issue with playing music in itunes
I recently just got iTunes on my new HP Vista laptop. When I used an external harddrive to move my music from my other computer to the laptop all was fine. When i put the songs and albums up in itunes and tried to play it, it would not play. The butt
-
Calculating Grand Total based on the section totals
Hi, I have a webi report with a section. Outside the section block I have a grand total block. I have a section on Shop Names. At the total level I calculate calls per hour average. So at the end of each sections the total would look like Shop 1 Shop