Ignoring whitespaces without DTD validation

Hi!
I've been having some problems parsing an XML file with DOM, because I get text Nodes for each "new line" symbol in the file, and I want these to be ignored, so I tried to put the "setIgnoringElementContentWhitespace" of the DocumentBuilderFactory to true.
The problem is that this property requires the parser to be in validating mode, and I don't have the DTD of the xml file... so I'd like it to be non validating.
Can it be done?

Ok, then... a DTD is needed to make the parser know when the whitespaces are ignorable, isn't it?
I wrote a simple DTD and by-passed the problem. It works know.
Thx for reading

Similar Messages

  • Xerces2 does not report ignorable whitespace with schemas

    I use JDK 1.3 with the Summer 02 XML pack, i. e. JAXP 1.2_01, but I also tried the current Xerces2 2.2.0.
    When I parse XML files and validate them against a schema (using SAX; namespaceAware, validation and schemaValidation all set to TRUE of course), parsing and validation work all right except for whitespace being reported via characters() instead of ignorableWhitespace(). I heard of similar problems from someone who uses DOM, so the problem apparently does not lie in SAX.
    I did a lot of searching on the topic, and it's not one of the common things like "you have to supply a grammar" or "you have to switch on validation". Xerces2 documentation says the parser has to be able to recognize ignorable whitespace as such. Thing is, when I supply a DTD instead of a schema, everything works fine.
    My XML schema is pretty complex, so I took one from w3schools.com for testing:
    The schema:
    <?xml version="1.0"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://www.w3schools.com"
    xmlns="http://www.w3schools.com" elementFormDefault="qualified">
    <xs:element name="note">
         <xs:complexType>
              <xs:sequence>
                   <xs:element name="to" type="xs:string"/>
                   <xs:element name="from" type="xs:string"/>
                   <xs:element name="heading" type="xs:string"/>
                   <xs:element name="body" type="xs:string"/>
              </xs:sequence>
         </xs:complexType>
    </xs:element>
    </xs:schema>The DTD:
    <!ELEMENT note (to, from, heading, body)>
    <!ELEMENT to (#PCDATA)>
    <!ELEMENT from (#PCDATA)>
    <!ELEMENT heading (#PCDATA)>
    <!ELEMENT body (#PCDATA)>The XML:
    <?xml version="1.0" encoding="UTF-8"?>
    <note xmlns="http://www.w3schools.com"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.w3schools.com note.xsd">
         <to>Koch</to>
         <from>Heckler</from>
         <heading>Reminder</heading>
         <body>Lunch at 12!</body>
    </note>This is the XML with the reference to the schema. Validates fine, but reports the tabs and line feeds as characters. When I change the XML to reference the DTD, I get my characters() calls. Since I suspected my code, I also tried all that with the DocumentTracer sample program supplied with Xerces2. Same behaviour, no ignorableWhitespace() calls when using schema.
    So what is it? Is there a special way to mark up whitespace in XML schema? I don't think so. By now I suspect Xerces2 to be responsible for the problem. I'm not too experienced on the subject, but AFAIK XML schema is fairly new, and so is Xerces2. Just wanted to ask around befor stirring trouble at Apache...

    Did you guys ever find a solution for this problem.
    I didn't have this problem with DTD's.
    Also, I noticed that when parsing using SAX parser, resolveentity callback used to get fired even if the validation was set to false( in case of DTD's).
    But don't see that happening when using XSD's.
    Thanks

  • Weblogic 9.2 JDk 1.5 DTD Validation

    Hi
    We are using xerces parser and doing DTD Validation .
    We want to have all the DTD present in the local directory
    C:/temp( as reading from the WAR is a performance hit)
    When we try to run with Weblogic 8.1 ( with JDK1.4 and JDK1.5 ) the xml is being parsed properly and validated with DTD without any errors
    But when we are trying to Validate the DTD with Weblogic 9.2 and JDK 1.5 it gives the error
    C:/temp/a.dtd not found even though the DTD is present in that location .
    Is there a settiing in Weblogic 9.2 which needs to be set for it to read local file system files?
    Thanks
    Sachin

    weblogic 9.2 uses jdk 1.5_04 if i recall correctly.

  • Disabling dtd validation

    I know it sounds odd.. but I need my appserver to run offline. basically I am creating a stand alone server and application installation that one of our marketing guys can take on the road on a laptop and demo to people where there is no internet.
    you know.. localhost style ;-)
    One problem.. when there is no internet, DTD validation for sun and oracle wesite DTDs all fail. Removing all dtd references or making them local would take as long as it would take me to write a script to do it... I am hoping there is just a setting in the application server that I can set to disable dtd validation. The whole app is done being developed.. I don't need my xml validated anymore! I need to be able to run without the intarwebnets!
    please help!

    Haven't worked with this but possibly this method of "deactivation" is not valid in 11gR2? Have you cross checked that with Oracle support?

  • Ignoring whitespace

    Hi,
    I am using Xerces to parse xml input streams and I am having trouble ignoring the whitespaces..... There is no DTD attached to the XML I recieve so I can't use the setIgnoringElementContentWhitespace().....
    What can I do????

    Anyway, who says you have to put them in there?
    Whitespace is only useful for people trying to read
    the document, so if you are doing program-to-program
    communication (which is what XML is really for
    anyway) then don't put in the unnecessary whitespace.The other "side" of the program is already up and running for a long time, and it wasn't implemented by me, I can't change their code....
    (which is what XML is really for anyway)That's exactly what I ment, this usage pattern is so common, why not give the possibility to ignore whitespaces with no DTD, even if it means "breaking the rules"?
    Well..... Never mind, thanks for your comments though.....
    Uri.

  • View data in client B from client A in the same SID without a valid logon?

    Hi Folks
    We are planning on upgrading our 4.6C system to ERP 6.0, and are initialy considering having two clients in the same sandbox SID.  One would be for the developers to perform code remediation checks (client A), and one would contain a copy of production data for performing testing of functionality over live data (client B).
    Would it be possible to view data in client B from client A in the same system without a valid logon to client B or RFC connection to client B from client A?   For example via the use on an ABAP program to SQL the database?
    I know one can use transactions like SM30/SM31 to view, compare, and adjust data between clients, but this requires an RFC connection and valid logon to the target client.
    Regards
    Kevin.

    Hi Kevin.
    >
    Kevin McLatchie wrote:
    > Would it be possible to view data in client B from client A in the same system without a valid logon to client B or RFC connection to client B from client A?   For example via the use on an ABAP program to
    Short answer: yes.
    If someone has the right to write and execute ABAP reports on the system he is able to access the data of all clients. So I don't think that this setup is advisable. Don't mix development and production data in one system.
    Best regards,
    Jan

  • Ejb-jar.xml DTD validation error?

    I am attempting to deploy a JAR on App Server 8 PE. The application does not contain any EJBs but I understand that the ejb-jar.xml descriptor is still needed. I am running the app server on Windows XP.
    My issue is as follows:
    I understand that the root element for the ejb-jar.xml file (<ejb-jar>) is required. Since I have no EJBs, I should be able to leave this root element blank (as I have in previoius successful deployments to earlier versions of Sun App Server). When I attempt to deploy, I receive the following DTD Validation error via the admin console:
    The content of element type "ejb-jar" is incomplete, it must match "(description?,display-name?,small-icon?,large-icon?,enterprise-beans,relationships?,assembly-descriptor?,ejb-client-jar?)".
    Am I missing something?
    My ejb-jar.xml file looks like:
    <!DOCTYPE ejb-jar PUBLIC
         "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"
         "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
    <ejb-jar>
    </ejb-jar>
    Many thanks in advance to any assistance...

    I am attempting to deploy a JAR on App Server 8 PE.
    The application does not contain any EJBs but I
    I understand that the ejb-jar.xml descriptor is still
    needed. I am running the app server on Windows XP.
    My issue is as follows:
    I understand that the root element for the
    ejb-jar.xml file (<ejb-jar>) is required. Since I
    have no EJBs, I should be able to leave this root
    element blank (as I have in previoius successful
    deployments to earlier versions of Sun App Server).
    When I attempt to deploy, I receive the following
    g DTD Validation error via the admin console:
    The content of element type "ejb-jar" is incomplete,
    it must match
    "(description?,display-name?,small-icon?,large-icon?,e
    nterprise-beans,relationships?,assembly-descriptor?,ej
    b-client-jar?)".
    Am I missing something?
    My ejb-jar.xml file looks like:
    <!DOCTYPE ejb-jar PUBLIC
    "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans
    s 2.0//EN"
         "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
    <ejb-jar>
    </ejb-jar>
    Many thanks in advance to any assistance...I hav tried this and it is working
    <?xml version="1.0" encoding="UTF-8" ?>
    <ejb-jar
    xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
    http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd"
    version="2.1">

  • DOM Parser Configuration...how to switch off DTD validation?

    Hi all,
    I am developing some implementation code in Java using JBuilder2005, in which DOM3 parser is also being utilised. Now the question is how to switch off DTD validation (seems its default mode is 'on') so that no validation will be carried out at all even DTD declaration statement is presented in an input XML document?
    Many thanks in advance
    Frank

    First of all, thank you so much for responding, DrClap. =)
    setValidating(false) of the DocumentBuilderFactory instance, factory, does not work as expected; it still stubbornly try to seek the external DTD file and fires 'IOException' error in case of no such a DTD.
    To follow up the EntityResolver approach, I searched online for almost the whole afternoon but still could not figure out how to do it exactly. In particular, I found http://www.jdom.org/docs/faq.html#a0350, which tells a way doing it, but I got 'StringBufferInputStream is deprecated' error. Then I changed to
    new InputStream(new ByteArrayInputStream("".getBytes()))adapted from http://forum.java.sun.com/thread.jspa?threadID=572919&messageID=2842185. But another error occurs: 'java.io.InputStream is abstract; cannot be instantiated'. Furthermore, I have looked at many docs(tutorials, APIs...) on parser configuration, usage of EntityResolver/setEntityResolver()...but they turned out not helpful. Could you please give out more details on how to do this using EntityResolver?? Many many thanks...

  • How to disable XML´s DTD validation in Weblogic10?

    Hello folks, we are trying to upgrade our server to Weblogic10, but it´s XML parser is validating XML´s DTD and ´cause we are behind a firewall we receive a error like:
    Tried all: ´6´ address, but could not connect over HTTP to server: 'www.w3.org', port: '80'
    Does anyone here known how to disable DTD validation in WL10?
    Regards,
    lottalava

    Well you can create non validating parser programatically .
    http://edocs.bea.com/wls/docs100/xml/programming.html#wp1069856
    i.e.
    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setValidating(false);
    Hope this helps.

  • Code Review Tool - Ignore Whitespace

    When I view the comparison in the code review tool ignore whitespace is on by default. The problem is that it doesn't ignore all whitespace. For example, a method's parameters prior to the change had a space between the start and end of the parameter definition
    but after changes the auto format of visual studio is different by removing the spaces (different user preference).The code review tool see's this as a difference. Why is that? 
    Before:
    public class test
    public TestMethod( string testString )
    After
    public class test
    public TestMethod(string testString)
    This is very frustrating because the very nice visual difference bar to the right of the code comparison becomes useless in these situations. 

    Hi Zpittman,
    What is you said ‘Code Review Tool’?
    I assume that you meant the Code Review feature in TFS. I tried it in Visual Studio 2013 with update 4 and TFS 2013 with Update 4, the whitespace was detected and the code review see it as a difference.
    If you don’t get the same result with me using VS and TFS, please upgrade your VS and TFS to the latest update.
    If the issue still exists, please
    reset your VS settings through Tools->Import and Export settings->Reset all
    settings->…. and repair your VS.
    If code review tool is a third-party tool or a third-party VS/TFS add-in, the official support of this tool can be a better place to resolve your issue.
    If I misunderstood anything, please feel free to come back.
    Thanks,
    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.

  • Message Mapping - Turn Off dtd validation

    Hi,
    I would like to know how to turn off dtd validation in a message map.
    The source message type is based on dtd. When testing, I get the following error
    java.io.IOException: Failed to load resource from the context classloader of the current thread! Loading from classloader was caused by: java.io.FileNotFoundException: D:\usr\sap\XYZ\DVEBMGS01\j2ee\cluster\server0\abc.dtd (The system cannot find the file specified)
    I understand that the map requires the dtd to be present in the application folder. But, can I change some setting not to look up this file.
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE MessageContainer SYSTEM "abc.dtd">

    Sorry Arvind. Not able to understand your question.
    The problem we are facing is, when the input xml file contains DocType declaration with reference to a dtd, we get an error stating the dtd is not found in the j2ee application folder.
    It works fine if the dtd is saved in the location. Also, it works fine if the DocType declaration is removed from the xml file. However, we are exploring an option where declaration is used but dtd is not available.
    Is there any way to achieve this?
    Thanks!

  • Text Align ignores whitespaces

    Hi.
    I have a problem with text align in text field.
    Let's say that I have a text field with htmlText:
    "Text example          "
    - when I set align for this text field like this:
    var _format:TextFormat = new TextFormat();
    _format.align= TextFormatAlign.CENTER;
    text_field.setTextFormat(_format);
    - it ignores whitespaces at the end of the line.
    Same thing for TextFormatAlign.RIGHT.
    Can I change this behavior using new text layout framework?

    I don't think you can. TLF ignores trailing spaces when aligning text as well. And the decisions for where a glyph appears on a line are in the Player - not our actionscript code - so there isn't a way to override this in TLF.

  • Turn off DTD validation

    I am using the Xerces DOMParser that ships with WebLogic 6.0 (sp1). Does
    anyone know how to turn of DTD validation when parsing a file?
    Thanks in advance.

    in SAX it's the setFeature() method. I assume there's something similar for
    DOM because the Xerces DOM "parser" sits on top of SAX
    "Tony Hardee" <[email protected]> wrote in message
    news:[email protected]..
    I am using the Xerces DOMParser that ships with WebLogic 6.0 (sp1). Does
    anyone know how to turn of DTD validation when parsing a file?
    Thanks in advance.

  • TextField Align ignores whitespaces

    Hi.
    I have a problem with text align in text field.
    Let's say that I have a text field with htmlText:
    "Text example          "
    - when I set align for this text field like this:
    var _format:TextFormat = new TextFormat();
    _format.align= TextFormatAlign.CENTER;
    text_field.setTextFormat(_format);
    - it ignores whitespaces. Same thing for TextFormatAlign.RIGHT.
    How can I change this behavior?
    Thanks.

    I have a post card application where user can type some text in multiline text field. After that I have pdf output.
    The problem is that if user creates text area and then sets align RIGHT/CENTER flash doesn't take care about spaces after last character in particular line. And because of this pdf output looks differently.
    I've tried to change condenseWhite property - no luck.

  • Removing ignorable whitespace from DOM document

    Dear all,
    I am trying to read in an XML document that contains a lot of ignorable whitespace between elements. I am using the DOM model to parse and read in the file. Is there an easy way to tell the parser to ignore all ignorable whitespace characters in text nodes? Or do I have to write a routine to pre-process the DOM document?
    (xml:space="default" is set in the root element)
    Thanks a lot in advance!
    Netwundi

    I agree DrClap with your assertion. However, having read normalize(), it does seem quirky. According to the Javadocs for Node:
    public void normalize()
    Puts all Text nodes in the full depth of the sub-tree underneath this Node, including attribute nodes, into a "normal" form where only structure (e.g., elements, comments, processing instructions, CDATA sections, and entity references) separates Text nodes, i.e., there are neither adjacent Text nodes nor empty Text nodes. This can be used to ensure that the DOM view of a document is the same as if it were saved and re-loaded, and is useful when operations (such as XPointer lookups) that depend on a particular document tree structure are to be used.In cases where the document contains CDATASections, the normalize operation alone may not be sufficient, since XPointers do not differentiate between Text nodes and CDATASection nodes.- Saish

Maybe you are looking for