Inserting a node in XML and retaining the doc type

Hi All,
I want to insert one new node in an XML. Using the following code I can do that. But the problem is if the XML has doc type declaration then its giving me problem. After inserting the node the transformer is removing my doc type declaration from the XML. I have to retain the doc type definition (including entity declaration) as it is in the original XML file.
The following is the code that I'm using.
Document vDoc = null;
try {
// Contruct the DOM document
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
vDoc = builder.newDocument();
Node vFormNode = vDoc.createElement("Form");
vDoc.appendChild(vFormNode);
// Convert into a String the DOM document
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
DOMSource source = new DOMSource(vDoc);
StringWriter sw = new StringWriter();
StreamResult result = new StreamResult(sw);
transformer.transform(source, result);
catch (Exception e) {
System.out.println("Error: " + e.getMessage());
}The doc type def. in the original file is some thing like this.
<!DOCTYPE article SYSTEM "someurl/TFJA.dtd"[
<!ENTITY T0001 SYSTEM ".\BTN_A_000112809_O_XML_IMAGES\BTN_A_000112809_O_T0001.gif" NDATA GIF>
<!ENTITY F0001 SYSTEM ".\BTN_A_000112809_O_XML_IMAGES\BTN_A_000112809_O_F0001g.gif" NDATA GIF>
<!ENTITY F0002 SYSTEM ".\BTN_A_000112809_O_XML_IMAGES\BTN_A_000112809_O_F0002g.jpg" NDATA JPEG>
]>I know that I can set up the doc type definition in the new XML using the following properties of the transformer.
transformer.setOutputProperty( OutputKeys.DOCTYPE_SYSTEM,"article" );
transformer.setOutputProperty( OutputKeys.DOCTYPE_PUBLIC,"my DTD def");
I cannot hard code the DTD def. as it can vary from one XML to another. Using doc.getDocType() I can get the doctype of the original XML. But is it is not returning the complete def. including entities declaration. Its giving me "someurl/TFJA.dtd".
Is there any way to retain the complete doc type in the original XML file? I don't have much experience in XML and this issue is eating my head.. Also do I have to modify the DTD to accommodate the new tags added in order to make it a valid XML?
Any help and sample code would be highly appreciated.

Hi,
I also had similar requirement and when searching i came across this post. Later i found the solution for this. Instead of hardcoding the doctype you can get it from Document as follows..Snippet from the code i used..
DocumentType doctype = document.getDoctype();
if(doctype != null) {
               String id = doctype.getSystemId();
               if(id == null || id.length() == 0)
                    return;
               transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, id);
               id = doctype.getPublicId();
               if(id == null || id.length() == 0)
                    return;
               transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, id);
Hope this helps.
Regards,
Deepak

Similar Messages

  • Ive just got a new iPhone4 and I am trying to get the App's ie games from my iPhone3 onto the 4 and retain the same levels that I have reached on the 3, The Apps have gone onto the 4 but its making me re-start everything from level 1?

    Ive just got a new iPhone4 and I am trying to get the App's ie games from my iPhone3 onto the 4 and retain the same levels that I have reached on the 3,
    The Apps have gone onto the 4 but its making me re-start everything from level 1?
    Ive paid $$ for the games and then more $$ within the games via iTunes for in game purchases and desperatly want the games on the 4 with the levels that I have reached on the 3!
    Can anyone help!! Please!!!! My Smurfs and Animals are starving Hahahaha

    Mate, it's good to hear that you have gotten the iPhone 4 but sorry to burst your bubbles. Not all games can have the "saved" data ported over.
    Normally when you save a game in iPhone, the memory used is in the flash memory of the device. Those that can be ported over, reason is due to the data being saved over the air and when you logged in on a new device, it recognises you via the userID.
    Maybe you can try to backup your iPhone 3, and restore the file onto your iPhone 4. Not too sure if that would brick your phone though.

  • Can I use BOTH IE & FF and retain the shortcuts to both to use at will?

    Can I use BOTH IE & FF and retain the shortcuts to both to use at will? I can download FF ok and use for a day or so along with IE, but after that I start to get messages from Windows saying IE is not my default browser and do I want to make it the default. If I answer no, many links in my windows mail and other links in the windows system don't work...I get a message that the file can't be found . If I answer yes, the FF shortcuts disappear and can't bring up the FF from the FF folder, I get a msg that the FF folder is corrupt!

    Hi, aparently we're a problem while you installed firefox. try to uninstall and reinstall firefox again,
    after you do that, open firefox and go to Tools>options>Advanced>General, and see that it have to be an option at last that sez "always check to see if firefox is the default browser on startup" uncheck that option.,
    Then go to IE, go to tools>internet options>programs>and clic on "Make Default".
    With this you make that IE the default browser.
    Bye

  • How to edit bitmap which is imported in flash using xml and save the edited bitmap back to xml in flash.

    hi all
    It would be appreciated if any one let me know how to edit
    bitmap which is imported in flash using xml and save the edited
    bitmap back to xml in flash.
    Is it posible to save the bitmap data in flash?
    thanks in advance

    Yes you can... but like I said before you need to upload the
    data from the changes you make to a server.
    In terms of the solution... its unlikely that you'll find one
    specifically for your needs. You will have to learn whatever you
    don't know how already and maybe adapt some existing examples to
    your needs.
    To change the visual state of a movie clip... you just do all
    the regular things that you want to do to it using flash... scale,
    rotation, drawing API , textfields etc in actionscript. If you
    don't know how to how to do that stuff, then you need to learn that
    first. That's basic actionscript.
    You can capture the visual state of a movieclip using the
    BitmapData class. That includes a loaded jpeg. You can also
    manipulate bimatp data using the same class. You should read up on
    that if you don't know how to use it or check out the examples
    below for uploading info.
    For uploading to the server:
    Here's an as2 solution that took 15 secs to find using
    google:
    http://www.quasimondo.com/archives/000645.php
    If you're using as3, google search for "jpeg encoder as3" and
    look through that info. There are also historical answers in the
    forums here related to this type of thing that might help as
    well.

  • How can I archive photos in iPhoto to a hard drive and retain the Album folders and the Events?

    How can I archive photos in iPhoto to a hard drive and retain the Album folders and the Events?  I tried to Export the Albums but just transferred the files individually.

    If you want to maintain the iPhoto organisation then back up the iPhoto Library.
    If you want to export to the Finder, well you need to create a folder for the contents of an Album and expot to that.
    If you have an older version of iPhoto: Apps like iPhoto2Disk or PhotoShare will help you export to a Folder tree matching your Events. This feature is built in to iPhoto 11.
    This User Tip
    https://discussions.apple.com/docs/DOC-4921
    has details of the options in the Export dialogue.

  • How do I convert a powerpoint document to a pdf and retain the notes?

    How do I convert a powerpoint document to a pdf and retain the notes?

    One possibility is to print the slides+notes, choosing "save as PDF" in the print dialog instead of sending it to a printer.

  • Search for a tag in xml and modify the content

    Hi,
    I am quite new to using xml db and i want to know how to search a xml, modify a tag value inside xml and replace the content in xml.
    Please help me to find a solution for this.
    Regards,
    Sprightee

    Hi,
    First important thing : give your database version (SELECT * FROM v$version).
    Please also provide some sample data :
    - a typical XML document you're working with (or abridged version)
    - explain what change(s) you want to do, or give expected output
    - if you're using a table to store the XML (which is preferred), give the DDL

  • Is it possible to import photos from a disk and retain the same order?

    Is i possible to import photos from a disk and retain the same order they appear on the disk?  When I import them, the come out in random order.

    When first imported the photos will be sorted in the Event chronologically. On the disk they well be sorted by the Finder and that's usually alphanumerically by file name. So select the photos in the event and type Commnad+N.  That will create a new album at the left with the photos in it. Then go to the View ➙ Sort Photo menu and select "By Title".  That should give you the same order as you view the photos on the disk via the Finder.
    OT

  • How do I restore to factory setting AND retain the tunes and apps on the phone or get them synched?

    I'm getting the message "itunes cannot read the contents of the iphone" and asking me to restore to factory settings when attaching to PC. I have songs downloaded from itunes on my PC, and songs and apps downloaded to the iPhone from iTunes too. How do I restore to factory setting AND retain the tunes and apps on the phone or get them synched? The iPhone is working fine
    iPhone4 v4.2.1 (8C148) (can't update this till above sorted)
    iTunes 10.2.2.12
    Basically, if there is some way of downloading a 2nd copy of tunes/apps already purchased I can resolve my issue, but I don't know if this can be done. Ican't find a FAQ on this. Thanks in advance

    See  Erase your device  Here  >  http://support.apple.com/kb/HT4137
    Go to Settings > General > Reset > Erase all content and settings
    Also... See the wjosten post here...
    https://discussions.apple.com/message/20294697

  • How can one convert a picture to 1080 pixels in height at 72 dpi and retain the aspect ratio?

    How can one convert a picture to 1080 pixels in height at 72 dpi and retain the aspect ratio?

    The ppi has nothing to do with this. It will stay at whatever it is.
    Go to image>resize>resize image, turn ON Resample image and enter 1080 for the height, making sure to leave constrain proportions turned on. Don't mess with the ppi setting.
    If the image is set to another ppi setting, then after you're done with the above, go back into that window, turn OFF resample image, and set the ppi to 72. PPI only affects the inc/cm measurement.

  • I have model series KX TG7641 /w 5 phones.... My questions:  1. Can the directory of phone numbers with in my iPhone be transferred to the Panasonic and retain the individual number designations; i.e., "home-moblie-work-etc"?  2. Can I use the manual sele

    I have model series KX TG7641 /w 5 phones....
    My questions:
    1. Can the directory of phone numbers with in my iPhone be transferred to the Panasonic and retain the individual number designations; i.e., "home-moblie-work-etc"?
    2. Can I use the manual select on the Panasonic to selectively transfer numbers from my iPhone?

    Basic troubleshooting from the User's Guide is reset, restart, restore (first from backup then as new).  Has any of this been tried?
    FYI, there are no viruses that affect iOS unless the device has been hacked or jailbroken, in which case they cannot be discussed here.

  • While using a drop-down menu i.e. File, edit, image, or even when saving as and choosing the file type; the list appears and I am able to highlight what i want but cannot click on anything.

    While using a drop-down menu i.e. File, edit, image, or even when saving as and choosing the file type; the list appears and I am able to highlight what i want but cannot click on anything. This is becoming incredibly frustrating. It happens at random time and a restart of the computer is all that helps, then with out any notice it starts to do this again.  Mac Book Pro i7 2.2 16 GB 1333 Ram, (2) 450GB SSD both internal to machine. At this point I am losing file because I am unable to save in the file type I need. Does anyone out there know how to solve this issue?
    Thanks
    phil

    I haven't been unify photoshop much in the past month, but I did try your suggestion and it seemed to work for a while. Today when i went to save a document the same thing happened: click on file>save at this point I can not click on save even though it is highlighted. Tryed to use command s that brings up the save dialogue box, but when I try to change file type I again cannot select it from the drop down menu.

  • My folders take forever to open and then the docs within take a long time for the icon to pop up. the same thing with moving itmes from the desktop to a folder, and also emptying the trashh

    my folders take forever to open and then the docs within take a long time for the icon to pop up. the same thing with moving itmes from the desktop to a folder, and also emptying the trashh

    Don't know if that would be a failing hard drive, but it may be that you are out of available space. How much hard drive space do you have available? Please highlight the Macintosh HD icon and then press Command and I for a get info window. Once open, please copy and post the following:
    Capacity:
    Used:
    Available:
    Mac OS requires a minimum of 10 - 15% of total hard drive space available and empty at all times in order to operate properly.

  • I uploaded and edited my RAW image, clicked 'Save As', and changed the file type from .psed to .jpg.

    I edited my raw image in Photoshop CS6, selected 'Save As', and changed the file type from .psed to .jpg. I also selected 12 and large file when the window popped up, concluding my 'saving as'. My computer does not recognize the file type and won't open them. Can someone help me? Thanks!

    When naming files, stick to the letters of the ENGLISH alphabet, numbers and underscores.  Do not use illegal characters like apostrophes, commas, asterisks, ampersands, hatch or pound signs, diacritics or accented characters, slashes, etc.
    While the period (dot) is not an illegal character per se, your file names should have only one period and that should always be followed by the file type extension.
    EDITED typo: se
    Message was edited by: station_two

  • Drop Down for Selecting the doc type while uploading?

    Hi all,
    Is it possible to create some document type in KM so that we can select the doc type and  upload the file to specific folder.
    What I mean from Doc type is like Doc for Meetings, Doc for activity report.
    Is it possible using standard KM features? Urgent help needed pls reply.
    Pls send the document regarding this to [email protected]

    Hi Karan,
    I'm not sure if I have understood your issue correctly, but let me try:
    1. You want to upload documents to KM
    2. Uploading them, you want to categorize them in some way, so that they can be identified as docs for meetings, docs for unit XYZ, etc..
    3. After upload, you want each doc to end up in a folder according to its category
    If this is what you want, try the following:
    1. Create a custom resource property called "category" or something similiar.
    2. You may define your possible values for that property. This makes it a drop down box containing the possible values in property view. (You can see property view when uploadinga document)
    3. Mark the property as searchable
    4. Create a taxonomy using TREX searching your repository for the given values of your custom property
    Now you can upload documents, fill the custom property, and some minutes later TREX will create a link to the document in the specified 'category folder'.
    If you need some more detailed assistance, please come back.
    HTH,
    Carsten

Maybe you are looking for

  • How to not show path in address bar?

    how do you not show the full path of the file in the adress bar? eg: www.adobe.com/forums/forum.asp instead having it show www.adobe.com/forums I have heard you rename the main page in the folder to index but never really seams to work for me any clu

  • Moved cd player to diff.shelf w/o removing discs,now door won't open,table won't turn,light flashes

    Relocated without removing discs from large CD player,now door won't open, table won't turn and the light inside in center of table just flashes. Any suggestions as to can I fix this?

  • [SOLVED] Makepkg, install dependencies from AUR.

    Is it possible for makepkg to install the dependencies from AUR with makepkg -si? Last edited by lemanski6 (2012-09-20 18:05:38)

  • Immediate Excise utilization

    Presently Scrap sale is being done thru SAP. Excise invoices are also being created from the system. As per business requirement want to post excise utilization of scrap invoices same day. These should not appear for monthly utilization. Would the "I

  • UCM error which retrieving values

    Hello All, I am using jdev 11.1.1.6 I am trying to display in a iterator few values from UCM. The iterator is binded with backing bean, In backing bean the values are populated.. Iterator should display list of values for each doc.. Some files on UCM