Xerces Interview Questions & Answers

  1. Question 1. I Have Written A Schema And I Want To Use Xerces To Validate It. How Do I Do This?

    Answer :

    The best way to solve this problem is to write a simple, valid instance document and use one of the sample programs that accompanies Xerces (such as sax.SAXCount or dom.DOMCount) to validate the instance document. While validating the instance document, Xerces will simultaneously validate the corresponding schema. We hope to introduce functionality to permit schemas to be validated independently of instance documents in Xerces2.

  2. Question 2. How Do I Use Bugzilla To Report Bugs?

    Answer :

    • Please report bugs against the newest release.
    • If doubt exists whether the behaviour in question is a bug or a feature, please post a message to the xerces-j-user list for clarification.
    • To help to eliminate duplicate bug reports, before reporting a bug, you should first query the bugzilla database to see whether the bug has already been reported (and perhaps fixed). Then, checkout code from SVN, and build Xerces-J locally to verify that a bug still exists.
  3. Perl Scripting Interview Questions

  4. Question 3. I Have Used The Domparser To Convert An Xml Document Into A Dom Tree. Then I Made Some Changes To The Dom Tree. How Do I Make Sure The Document Still Conforms To My (schema Or Dtd)?

    Answer :

    DOM revalidation is not supported by Xerces 1. Ken Rawlings has been trying to build a revalidating DOMParser based on code which was dropped from Xerces because it was no longer being maintained. The current code is at:http://www.vervet.com/~krawling/RevalidatingDOMParser.java. We hope that Xerces 2 will include this capability.

  5. Question 4. I Have A (dtd Or Schema) That I Will Use To Validate Many Xml Documents. How Can I Avoid Having To Recompile It Every Time I Want To Validate A New Document?

    Answer :

    Xerces 1 does not currently support grammar caching. We expect that Xerces 2 will support this functionality. Some users have reported success by registering an EntityResolver which handles reading the grammar from the disk and storing it in an efficient way (usually a byteArray), then passing the parser a reader for the efficiently-stored structure. While this does not avoid recompiling the grammar for each instance document, it does avoid disk accesses.

  6. Perl Scripting Tutorial

  7. Question 5. What Are The New Features?

    Answer :

    Here are some of the new features in Xerces-J:

    • Additional support for W3C XML Schema Language.
    • DOS filenames no longer work.
  8. XML Interview Questions

  9. Question 6. How Do I Turn On Validation?

    Answer :

    You can turn validation on and off via methods available on the SAX2 XMLFilter interface. While only the SAXParser implements the XMLFilterinterface, the methods required for turning on validation are available to both parser classes, DOM and SAX. 

    The code snippet below shows how to turn validation on — assume that parser is an instance of either org.apache.xerces.parsers.SAXParser ororg.apache.xerces.parsers.DOMParser. 

    parser.setFeature(“http://xml.org/sax/features/validation”, true);

    IMPORTANT!Simply turning on validation will not make Xerces actually report the errors that it detects. For this, you need to implement theorg.xml.sax.ErrorHandler interface and register your implementation with the parser using the setErrorHandler method.

  10. Question 7. What International Encodings Are Supported By Xerces-j?

    Answer :

    In general, the parser supports all IANA encodings and aliases (seehttp://www.iana.org/assignments/character-sets) that have clear mappings to Java encodings (see here for details).

    Some of the more common encodings are:

    • UTF-8
    • UTF-16 Big Endian, UTF-16 Little Endian
    • IBM-1208
    • ISO Latin-1 (ISO-8859-1)
    • ISO Latin-2 (ISO-8859-2) [Bosnian, Croatian, Czech, Hungarian, Polish, Romanian, Serbian (in Latin transcription), Serbocroatian, Slovak, Slovenian, Upper and Lower Sorbian]
    • ISO Latin-3 (ISO-8859-3) [Maltese, Esperanto]
    • ISO Latin-4 (ISO-8859-4)
    • ISO Latin Cyrillic (ISO-8859-5)
    • ISO Latin Arabic (ISO-8859-6)
    • ISO Latin Greek (ISO-8859-7)
    • ISO Latin Hebrew (ISO-8859-8)
    • ISO Latin-5 (ISO-8859-9) [Turkish]
    • Extended Unix Code, packed for Japanese (euc-jp, eucjis)
    • Japanese Shift JIS (shift-jis)
    • Chinese (big5)
    • Chinese for PRC (mixed 1/2 byte) (gb2312)
    • Japanese ISO-2022-JP (iso-2022-jp)
    • Cyrllic (koi8-r)
    • Extended Unix Code, packed for Korean (euc-kr)
    • Russian Unix, Cyrillic (koi8-r)
    • Windows Thai (cp874)
    • Latin 1 Windows (cp1252)
    • cp858
    • EBCDIC encodings:
      o EBCDIC US (ebcdic-cp-us)
      o EBCDIC Canada (ebcdic-cp-ca)
      o EBCDIC Netherland (ebcdic-cp-nl)
      o EBCDIC Denmark (ebcdic-cp-dk)
      o EBCDIC Norway (ebcdic-cp-no)
      o EBCDIC Finland (ebcdic-cp-fi)
      o EBCDIC Sweden (ebcdic-cp-se)
      o EBCDIC Italy (ebcdic-cp-it)
      o EBCDIC Spain, Latin America (ebcdic-cp-es)
      o EBCDIC Great Britain (ebcdic-cp-gb)
      o EBCDIC France (ebcdic-cp-fr)
      o EBCDIC Hebrew (ebcdic-cp-he)
      o EBCDIC Switzerland (ebcdic-cp-ch)
      o EBCDIC Roece (ebcdic-cp-roece)
      o EBCDIC Yugoslavia (ebcdic-cp-yu)
      o EBCDIC Iceland (ebcdic-cp-is)
      o EBCDIC Urdu (ebcdic-cp-ar2)
      o Latin 0 EBCDIC
      o EBCDIC Arabic (ebcdic-cp-ar1)
  11. XML Tutorial
    Core Java Interview Questions

  12. Question 8. How Do I Find Out Which Xerces Version I Am Using?

    Answer :

    To find out the release version of Xerces, execute the following: java org.apache.xerces.impl.Version.

  13. Question 9. What Happened To Xerces.jar?

    Answer :

    In order to take advantage of the fact that this parser is very often used in conjunction with other XML technologies, such as XSLT processors, which also rely on standard API’s like DOM and SAX, xerces.jar was split into two jarfiles:

    • xml-apis.jar contains the DOM level 3, SAX 2.0.2 and the JAXP 1.4 APIs;
    • xercesImpl.jar contains the implementation of these API’s as well as the XNI API.
  14. Java Interview Questions

  15. Question 10. How Can I Use Jaxp 1.4 On Jdk 1.4 And Above?

    Answer :

    Use the Endorsed Standards Override Mechanism to specify xml-apis.jar and xercesImpl.jar. This will override the version of JAXP in the JDK. A more complete description is available here.

    The following methods do not work:

    • Using the CLASSPATH environment variable or using -classpath to place the new classes in the classpath.
    • Using the -jar option to explicitly execute the classes inside the new jar files.
  16. Core Java Tutorial

  17. Question 11. Why Do I Get A Classcastexception When I Use Xerces And Websphere Application Server?

    Answer :

    Xerces uses the ObjectFactory class to load some classes dynamically, e.g. the parser configuration. The ObjectFactory finds the specified implementation class by querying the system property, reading META-INF/services/factoryId file or using a fallback classname. After the implementation is found, the ObjectFactory tries to load the file using the context classloader and if it is null, the ObjectFactory uses the system classloader.

    If you run Xerces in an environment, such as WebSphere® Application Server, that has multiple classloaders you may get ClassCastExceptions thrown from Xerces because different classloaders might get involved in loading Xerces classes. For example, ClassCastExceptions may occur when utility EAR classes that use Xerces load Xerces classes from WAR modules.

    We suggest you read the “Avoiding ClassCastExceptions…” article which explains a workaround for this problem. Also you might want to read the “J2EE Class Loading Demystified” article that explains how multiple classloaders work in WebSphere Application Server.

  18. Java Design Patterns Interview Questions

  19. Question 12. What Should I Be Using Instead Of Xerces’ Xml, Html Or Xhtml Serializers?

    Answer :

    As of the 2.9.0 release Xerces-J began sharing a common serialization codebase with Xalan and now includes serializer.jar with its distribution for DOM Level 3 serialization support. The entire org.apache.xml.serialize package was deprecated in Xerces 2.9.0. The HTML and XHTML serializers were previously deprecated in the Xerces 2.6.2 release. You can find more details about the rationale for this decision here in the archives.

    If you want to achieve interoperability and avoid using deprecated APIs, you should not be using Xerces serialization code directly. Instead, the JAXP Transformer API should be used to serialize HTML, XHTML, and SAX. The DOM Level 3 Load and Save API (or JAXP Transformer API) should be used to serialize DOM.

  20. Perl Scripting Interview Questions

  21. Question 13. How Do I Turn On Dtd Validation?

    Answer :

    You can turn validation on and off via methods available on the SAX2 XMLReaderinterface. While only the SAXParser implements the XMLReader interface, the methods required for turning on validation are available to both parser classes, DOM and SAX. 

    The code snippet below shows how to turn validation on — assume that parser is an instance of either org.apache.xerces.parsers.SAXParser ororg.apache.xerces.parsers.DOMParser. 

    parser.setFeature(“http://xml.org/sax/features/validation”, true);

  22. Java Tutorial

  23. Question 14. Why Is The Parser Unable To Access Schema Documents Or External Entities Available On The Internet?

    Answer :

    The parser may not be able to access various external entities or schema documents (imported, included etc…) available on the Internet, such as the Schema for Schemas “http://www.w3.org/2001/XMLSchema.xsd” or the schema defining xml:base, xml:lang attributes etc… “http://www.w3.org/2001/xml.xsd” or any other external entity available on the Internet. There are various reasons one could experience such a problem. 

    One of the reasons could be that your proxy settings do not allow the parser to make URL connections through a proxy server. To solve this problem, before parsing a document, the application must set the two system properties: “http.proxyHost” and “http.proxyPort”. Another reason could be due to strict firewall settings that do not allow any URL connection to be made to the outside web. The problem may also be caused by a server that is offline or inaccessible on the network, preventing documents hosted by the server from being accessed.

  24. Question 15. What Jdk Level Is Required For Xerces?

    Answer :

    As of version 2.10.0, Xerces requires JDK 1.3 or later to run and also requires JDK 1.3 or later to build the source code. Starting with the Xerces 2.11.0 release, the XML Schema 1.1 experimental distribution requires JDK 1.4 or later to run and also to build the source code.

  25. Java XML Interview Questions

  26. Question 16. Does Xerces-c++ Support Schema?

    Answer :

    Yes, Xerces-C++ 3.1.4 contains an implementation of the W3C XML Schema Language, a recommendation of the Worldwide Web Consortium available in three parts: XML Schema: Primer and XML Schema: Structures and XML Schema: Datatypes. We consider this implementation complete. 

  27. Java XML Tutorial

  28. Question 17. Does Xerces-c++ Support Xpath?

    Answer :

    Xerces-C++ 3.1.4 provides partial XPath 1 implementation for the purposes of handling XML Schema identity constraints. The same engine is made available through the DOMDocument::evaluate API to let the user perform simple XPath queries involving DOMElement nodes only, with no predicate testing and allowing the “//” operator only as the initial step. For full XPath 1 and 2 support refer to theXQilla and Apache Xalan C++ open source projects.

  29. XMLHttpRequest (XHR) Interview Questions

  30. Question 18. Why Does My Application Crash When Instantiating The Parser?

    Answer :

    In order to work with the Xerces-C++ parser, you have to first initialize the XML subsystem. The most common mistake is to forget this initialization. Before you make any calls to Xerces-C++ APIs, you must call XMLPlatformUtils::Initialize():

  31. XML Interview Questions

  32. Question 19. Is It Ok To Call The Xmlplatformutils::initialize/terminate Pair Of Routines Multiple Times In One Program?

    Answer :

    Yes. Note, however, that the application needs to guarantee that the XMLPlatformUtils::Initialize() and XMLPlatformUtils::Terminate() methods are called from the same thread (usually the initial thread executing main()) or proper synchronization is performed by the application if multiple threads call XMLPlatformUtils::Initialize() and XMLPlatformUtils::Terminate() concurrently.

    If you are calling XMLPlatformUtils::Initialize() a number of times, and then follow with XMLPlatformUtils::Terminate() the same number of times, only the first XMLPlatformUtils::Initialize() will do the initialization, and only the last XMLPlatformUtils::Terminate() will clean up the memory. The other calls are ignored.

  33. Apache ZooKeeper Tutorial

  34. Question 20. Why Does My Application Crash After Calling Xmlplatformutils::terminate()?

    Answer :

    Please make sure the XMLPlatformUtils::Terminate() is the last Xerces-C++ function to be called in your program. NO explicit nor implicit Xerces-C++ destructor (those local data that are destructed when going out of scope) should be called after XMLPlatformUtils::Terminate().

  35. Apache ZooKeeper Interview Questions

  36. Question 21. Is Xerces-c++ Thread-safe?

    Answer :

    The answer is yes if you observe the following rules for using Xerces-C++ in a multi-threaded environment:

    Within an address space, an instance of the parser may be used without restriction from a single thread, or an instance of the parser can be accessed from multiple threads, provided the application guarantees that only one thread has entered a method of the parser at any one time.

    When two or more parser instances exist in a process, the instances can be used concurrently, without external synchronization. That is, in an application containing two parsers and two threads, one parser can be running within the first thread concurrently with the second parser running within the second thread.

    The same rules apply to Xerces-C++ DOM documents. Multiple document instances may be concurrently accessed from different threads, but any given document instance can only be accessed by one thread at a time.

    The application also needs to guarantee that the XMLPlatformUtils::Initialize() and XMLPlatformUtils::Terminate() methods are called from the same thread (usually the initial thread executing main()) or proper synchronization is performed by the application if multiple threads call XMLPlatformUtils::Initialize() and XMLPlatformUtils::Terminate() concurrently.

  37. Question 22. I Am Seeing Memory Leaks In Xerces-c++. Are They Real?

    Answer :

    The Xerces-C++ library allocates and caches some commonly reused items. The storage for these may be reported as memory leaks by some heap analysis tools; to avoid the problem, call the function XMLPlatformUtils::Terminate() before your application exits. This will free all memory that was being held by the library.

    For most applications, the use of Terminate() is optional. The system will recover all memory when the application process shuts down. The exception to this is the use of Xerces-C++ from DLLs that will be repeatedly loaded and unloaded from within the same process. To avoid memory leaks with this kind of use, Terminate() must be called before unloading the Xerces-C++ library

    To ensure all the memory held by the parser are freed, the number of XMLPlatformUtils::Terminate() calls should match the number of XMLPlatformUtils::Initialize() calls.

    If you have built Xerces-C++ with dependency on ICU then you may want to call the u_cleanup() ICU function to clean up ICU static data. Refer to the ICU documentation for details.

  38. Apache Xerces Tutorial

  39. Question 23. Is There A Function That Creates An Xml File From A Dtd (obviously With The Values Missing, A Skeleton)?

    Answer :

    No, there is no such functionality.

  40. Advanced C++ Interview Questions

  41. Question 24. Can I Use Xerces-c++ To Perform “write Validation”? That Is, Having An Appropriate Grammar And Being Able To Add Elements To The Dom Whilst Validating Against The Grammar?

    Answer :

    No, there is no such functionality.

    The best you can do for now is to create the DOM document, write it back as XML and re-parse it with validation turned on.

  42. Core Java Interview Questions

  43. Question 25. Is There A Facility In Xerces-c++ To Validate The Data Contained In A Dom Tree? That Is, Without Saving And Re-parsing The Source Document?

    Answer :

    No, there is no such functionality. The best you can do for now is to create the DOM document, write it back as XML and re-parse it with validation turned on.

  44. ebXML Tutorial

  45. Question 26. How To Write Out A Dom Tree Into A String Or An Xml File?

    Answer :

    You can use the DOMLSSerializer::writeToString, or DOMLSSerializer::writeNode to serialize a DOM tree. Please refer to the sample DOMPrint or the API documentation for more details of DOMLSSerializer.

  46. Apache Tomcat Interview Questions

  47. Question 27. Why Doesn’t Domnode::clonenode() Clone The Pointer Assigned To A Domnode Via Domnode::setuserdata()?

    Answer :

    Xerces-C++ supports the DOMNode::userData specified in the DOM level 3 Node interface. As is made clear in the description of the behavior of cloneNode(), userData that has been set on the Node is not cloned. Thus, if the userData is to be copied to the new Node, this copy must be effected manually. Note further that the operation of importNode() is specified similarly.

  48. Java Interview Questions

  49. Question 28. How Are Entity Reference Nodes Handled In Dom?

    Answer :

    If you are using the native DOM classes, the function setCreateEntityReferenceNodes controls how entities appear in the DOM tree. When setCreateEntityReferenceNodes is set to true (the default), an occurrence of an entity reference in the XML document will be represented by a subtree with an EntityReference node at the root whose children represent the entity expansion. Entity expansion will be a DOM tree representing the structure of the entity expansion, not a text node containing the entity expansion as text.

    If setCreateEntityReferenceNodes is false, an entity reference in the XML document is represented by only the nodes that represent the entity expansion. The DOM tree will not contain any entityReference nodes.

  50. XML DOM Tutorial

  51. Question 29. Can I Use Xerces-c++ To Parse Html?

    Answer :

    Yes, but only if the HTML follows the rules given in the XML specification. Most HTML, however, does not follow the XML rules, and will generate XML well-formedness errors.

  52. C and C++ Interview Questions

  53. Question 30. I Keep Getting An Error: “invalid Utf-8 Character”. What’s Wrong?

    Answer :

    Most commonly, the XML encoding = declaration is either incorrect or missing. Without a declaration, XML defaults to the use utf-8 character encoding, which is not compatible with the default text file encoding on most systems.

    The XML declaration should look something like this:

    Make sure to specify the encoding that is actually used by file. The encoding for “plain” text files depends both on the operating system and the locale (country and language) in use.

    Another common source of problems is characters that are not allowed in XML documents, according to the XML spec. Typical disallowed characters are control characters, even if you escape them using the Character Reference form. See the XML specification, sections 2.2 and 4.1 for details. If the parser is generating an Invalid character (Unicode: 0x???) error, it is very likely that there’s a character in there that you can’t see. You can generally use a UNIX command like “od -hc” to find it.

  54. Question 31. What Encodings Are Supported By Xerces-c++?

    Answer :

    Xerces-C++ has intrinsic support for ASCII, UTF-8, UTF-16 (Big/Small Endian), UCS4 (Big/Small Endian), EBCDIC code pages IBM037, IBM1047 and IBM1140 encodings, ISO-8859-1 (aka Latin1) and Windows-1252. This means that it can always parse input XML files in these above mentioned encodings.

    Furthermore, if you build Xerces-C++ with the International Components for Unicode (ICU) as a transcoder then the list of supported encodings extends to over 100 different encodings that are supported by ICU. In particular, all the encodings registered with the Internet Assigned Numbers Authority (IANA) are supported in this configuration.

  55. XML-RPC Tutorial

  56. Question 32. What Character Encoding Should I Use When Creating Xml Documents?

    Answer :

    The best choice in most cases is either utf-8 or utf-16. Advantages of these encodings include:

    • The best portability. These encodings are more widely supported by XML processors than any others, meaning that your documents will have the best possible chance of being read correctly, no matter where they end up.
    • Full international character support. Both utf-8 and utf-16 cover the full Unicode character set, which includes all of the characters from all major national, international and industry character sets.
    • Efficient. utf-8 has the smaller storage requirements for documents that are primarily composed of characters from the Latin alphabet. utf-16 is more efficient for encoding Asian languages. But both encodings cover all languages without loss.

    The only drawback of utf-8 or utf-16 is that they are not the native text file format for most systems, meaning that some text file editors and viewers can not be directly used.

    A second choice of encoding would be any of the others listed in the table above. This works best when the xml encoding is the same as the default system encoding on the machine where the XML document is being prepared, because the document will then display correctly as a plain text file. For UNIX systems in countries speaking Western European languages, the encoding will usually be iso-8859-1.

    A word of caution for Windows users: The default character set on Windows systems is windows-1252, not iso-8859-1. While Xerces-C++ does recognize this Windows encoding, it is a poor choice for portable XML data because it is not widely recognized by other XML processing tools. If you are using a Windows-based editing tool to generate XML, check which character set it generates, and make sure that the resulting XML specifies the correct name in the encoding=”…” declaration.

  57. ebXML Interview Questions

  58. Question 33. Why Does Deleting A Transcoded String Result In Assertion On Windows?

    Answer :

    Both your application program and the Xerces-C++ DLL must use the same DLL version of the runtime library. If either statically links to the runtime library, this problem will still occur.

    For a Visual Studio build the runtime library setting MUST be “Multithreaded DLL” for release builds and “Debug Multithreaded DLL” for debug builds.

    To bypass such problem, instead of calling operator delete[] directly, you can use the provided function XMLString::release to delete any string that was allocated by the parser. This will ensure the string is allocated and deleted by the same DLL and such assertion problem should be resolved.

  59. Java Design Patterns Interview Questions

  60. Question 34. How Do I Transcode To/from Something Besides The Local Code Page?

    Answer :

    XMLString::transcode() will transcode from XMLCh to the local code page, and other APIs which take a char* assume that the source text is in the local code page. If this is not true, you must transcode the text yourself. You can do this using local transcoding support on your OS, such as Iconv on Unix or IBM’s ICU package. However, if your transcoding needs are simple, you can achieve better portability by using the Xerces-C++ parser’s transcoder wrappers. You get a transcoder like this:

    • Call XMLPlatformUtils::fgTransServer->MakeNewTranscoderFor() and provide the name of the encoding you wish to create a transcoder for. This will return a transcoder to you, which you own and must delete when you are through with it. NOTE: You must provide a maximum block size that you will pass to the transcoder at one time, and you must pass blocks of characters of this count or smaller when you do your transcoding. The reason for this is that this is really an internal API and is used by the parser itself to do transcoding. The parser always does transcoding in known block sizes, and this allows transcoders to be much more efficient for internal use since it knows the max size it will ever have to deal with and can set itself up for that internally. In general, you should stick to block sizes in the 4 to 64K range.
    • The returned transcoder is something derived from XMLTranscoder, so they are all returned to you via that interface.
    • This object is really just a wrapper around the underlying transcoding system actually in use by your version of Xerces-C++, and does whatever is necessary to handle differences between the XMLCh representation and the representation used by that underlying transcoding system.
    • The transcoder object has two primary APIs, transcodeFrom() and transcodeTo(). These transcode between the XMLCh format and the encoding you indicated.
    • These APIs will transcode as much of the source data as will fit into the outgoing buffer you provide. They will tell you how much of the source they ate and how much of the target they filled. You can use this information to continue the process until all source is consumed.
    • char* data is always dealt with in terms of bytes, and XMLCh data is always dealt with in terms of characters. Don’t mix up which you are dealing with or you will not get the correct results, since many encodings don’t have a one to one relationship of characters to bytes.
    • When transcoding from XMLCh to the target encoding, the transcodeTo() method provides an ‘unrepresentable flag’ parameter, which tells the transcoder how to deal with an XMLCh code point that cannot be converted legally to the target encoding, which can easily happen since XMLCh is Unicode and can represent thousands of code points. The options are to use a default replacement character (which the underlying transcoding service will choose, and which is guaranteed to be legal for the target encoding), or to throw an exception.
  61. Question 35. Why Does The Parser Still Try To Locate The Dtd Even Validation Is Turned Off And How To Ignore External Dtd Reference?

    Answer :

    When DTD is referenced, the parser will try to read it, because DTDs can provide a lot more information than just validation. It defines entities and notations, external unparsed entities, default attributes, character entities, etc. Therefore the parser will always try to read it if present, even if validation is turned off.

    To ignore external DTDs completely you can callsetLoadExternalDTD(false) (orsetFeature(XMLUni::fgXercesLoadExternalDTD, false)to disable the loading of external DTD. The parser will then ignore any external DTD completely if the validationScheme is set to Val_Never.

    Note: This flag is ignored if the validationScheme is set to Val_Always or Val_Auto.

  62. Question 36. Why Does The Xml Data Generated By The Domlsserializer Does Not Match My Original Xml Input?

    Answer :

    If you parse an xml document using XercesDOMParser or DOMLSParser and pass such DOMNode to DOMLSSerializer for serialization, you may not get something that is exactly the same as the original XML data. The parser may have done normalization, end of line conversion, or has expanded the entity reference as per the XML 1.0 specification, 4.4 XML Processor Treatment of Entities and References. From DOMLSSerializer perspective, it does not know what the original string was, all it sees is a processed DOMNode generated by the parser. But since the DOMLSSerializer is supposed to generate something that is parsable if sent back to the parser, it will not print the DOMNode node value as is. The DOMLSSerializer may do some “touch up” to the output data for it to be parsable.

  63. Java XML Interview Questions

  64. Question 37. Why Does My Application Crash When Deleting The Parser After Releasing A Document?

    Answer :

    In most cases, the parser handles deleting documents when the parser gets deleted. However, if an application needs to release a document, it shall adopt the document before releasing it, so that the parser knows that the ownership of this particular document is transfered to the application and will not try to delete it once the parser gets deleted.

  65. Question 38. Which Version Of Swing Is Required?

    Answer :

    This release uses Swing 1.1 (JFC 1.1). Swing is only used by the sample programs and is not required by the parser itself.

  66. Question 39. How Do I Recompile The Source Files?

    Answer :

    To build Xerces-J on Windows, you need a copy of Cygnus’s Cygwin. Once Cygwin is installed, you need to set two environment variables. Edit the batch file BuildAll.bat to set these variables. Execute BuildAll.bat, and then set your classpath to point to the src and samples directories in the Xerces-J distribution. You can then go to the top of the Xerces-J tree and type ‘make’.

    To build Xerces-J Java on UNIX, you need to set an environment variable. Edit the shell script BuildAll to set this variables. Execute BuildAll, and then set your classpath to point to the src and samples directories in the Xerces-J distribution. You can then go to the top of the Xerces-J tree and type ‘make’.

  67. Question 40. How Do I Regenerate The Api Documentation?

    Answer :

    To regenerate the api documentation, you need to set up your environment to build Xerces-J. Instead of typing ‘make’, you type ‘make apidocs’.

  68. XMLHttpRequest (XHR) Interview Questions

  69. Question 41. How Do I Import Xerces-j Into Visual Age For Java?

    Answer :

    • Why does VisualAge for Java 2.0 report problems when I import the Xerces-J parser? 

    The current version of the Xerces-J parser uses Swing 1.1, while VisualAge for Java 2.0 comes with Swing 1.0.2. The free update for the Professional version of VisualAge for Java 2.0 installs Swing 1.0.3. The most important difference between Swing 1.0.2 – 1.0.3 and 1.1 is the Java package was changed from com.sun.java.swing.* to javax.swing.*. 

    To fix the errors, you must download the Java Foundation Classes 1.1 with Swing 1.1 from Sun’s Java home page and import the “swingall.jar” file into VisualAge for Java 2.0.

    Refer to the VisualAge for Java 2.0 documentation for information about how to import a JAR file into the repository and add that code to your workspace.

    • Are there any other tips for importing the Xerces-J parser into VisualAge for Java 2.0? 

    The most useful tip applies to any updated code that you import into the VisualAge for Java 2.0 product. Before updating code, do the following: 

    1. version the old code 
    2. delete it from your workspace 
    3. import the new code 

    Deleting code from your workspace does not actually delete the code permanently — the versioned code is moved to the repository where it can be retrieved later. Be aware, though, that removing code from your workspace will cause problems with all of the other classes that use that code. VisualAge for Java 2.0 will flag them as errors but this situation is temporary. When you import the new code, the errors found when deleting the old code will be fixed. 

    If you are unsure as to how to perform any of these steps, refer to the VisualAge for Java 2.0 documentation.

  70. Question 42. How Do I Control The Various Parser Options?

    Answer :

    For this release, all of the parser control API’s have been switched over to the SAX2 Configurable interface. This provide a uniform and extensible mechanism for setting and querying parser options. Here are guides to the set of available features and properties.

  71. Apache ZooKeeper Interview Questions

  72. Question 43. How Do Handle Errors?

    Answer :

    When you create a parser instance, the default error handler does nothing. This means that your program will fail silently when it encounters an error. You should register an error handler with the parser by supplying a class which implements the org.xml.sax.ErrorHandler interface. This is true regardless of whether your parser is a DOM based or SAX based parser.

  73. Question 44. How Can I Control The Way That Entities Are Represented In The Dom?

    Answer :

    When this feature is set to true (the default), an occurance of an entity reference in the XML document will be represented by a subtree with an EntityReference node at the root whose children represent the entity expansion.

    If the property is false, an entity reference in the XML document is represented by only the nodes that represent the entity expansion.

    In either case, the entity expansion will be a DOM tree representing the structure of the entity expansion, not a text node containing the entity expansion as text.

  74. Question 45. How Do I Associate My Own Data With A Node In The Dom Tree?

    Answer :

    The class org.apache.xerces.dom.NodeImpl provides a void setUserData(Object o) and an Object getUserData() method that you can use to attach any object to a node in the DOM tree.

    Beware that you should try and remove references to your data on nodes you no longer use (by calling setUserData(null), or these nodes will not be garbage collected until the whole document is.

  75. Question 46. How Do I More Efficiently Parse Several Documents Sharing A Common Dtd?

    Answer :

    DTDs are not currently cached by the parser. The common DTD, since it is specified in each XML document, will be re-parsed once for each document.

    However, there are things that you can do now, to make the process of reading DTD’s more efficient:

    • keep your DTD and DTD references local
    • use internal DTD subsets, if possible
    • load files from server to local client before parsing
    • Cache document files into a local client cache. You should do an HTTP header request to check whether the document has changed, before accessing it over the network.
    • Do not reference an external DTD or internal DTD subset at all. In this case, no DTD will be read.
    • Use a custom EntityResolver and keep common DTDs in a memory buffer.
  76. Question 47. What Should I Be Aware Of When Using Various Sax Parsers?

    Answer :

    There are a couple of points to note when using the various SAX parsers:

    The SAX API has detailed specifications on how documents are parsed and entities are resolved, so little migration effort required. The only change is the construction of the SAX parser. See the following examples for construction details.

  77. Question 48. I Get An Error When I Access Ebcdic Xml Files, What Is Happening?

    Answer :

    If an XML document/file is not UTF-8, then you MUST specify the encoding. When transcoding a UTF8 document to EBCDIC, remember to change this:


    to something like this: 

  78. Question 49. I Get An Error On The Eof Character (0x1a) — What Is Happening?

    Answer :

    You are probably using the LPEX editor, which automatically inserts an End-of-file character (0x1A) at the end of your XML document (other editors might do this as well). Unfortunately, the EOF character (0x1A) is an illegal character according to the XML specification, and Xerces-J correctly generates an error.

  79. Question 50. Why Does My Application Give Unresolved Linking Errors?

    Answer :

    Please check the following:

    1. Verify that you have specified the appropriate option and library path in the linker command line
    2. If you’re using the binary build of Xerces-C++, make sure that the CPU architecture, OS, and compiler are the same as the ones used to build the application. Different OS and compiler versions might cause unresolved linking problems or compilation errors. If the versions are different, rebuild the Xerces-C++ library on your system before building your application.
    3. If you are using Microsoft Visual Studio 2003 (7.1), 2005 (8.0), or 2008 (9.0), check that the “Treat wchar_t as a built-in type” option has been set to the same value as used to build Xerces-C++. The binary distribution for Visual Studio 7.1 is built with this option turned off. The binary distributions for Visual Studio 8.0 and 9.0 are built with this option turned on.
  80. Question 51. Why My Document Is Valid On Some Platform While Invalid On Others?

    Answer :

    The parser relies on the system call, strtod(), to parse a string representation of a double/float data. In the case of no invalid characters found, the strtod() returns a double/float value if it is representable on that platform, or raises ERANGE to indicate either underflow or underflow occurs. And the parser assigns zero to the said data if underflow is found.

    The threshold, where the strtod() decides if an underflow occurs, varies on platforms. On Windows, it is roughly the order of e-308, on Linux, e-325, and on AIX, HP-UX and Solaris, e-324.

    So in an instance document, a data of value 1.0e-310 from a type with minExclusive 0, is considered invalid on windows (since it is converted to 0 and therefore violates the minExclusive constraint), but valid on other Unix platforms (since it remains the original value).