How to create a Document object from a string.

If I use the following code, the input String cannot contain "\n", otherwise, it generates errors.
in the following code, inputXMLString is a String object that has xml content.
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(new InputSource(new StringReader(inputXMLString)));          How can I create a Document object from a string with "\n" in the string?
Thanks.

If I use the following code, the input String cannot
contain "\n", otherwise, it generates errors.That's going to be a huge surprise to thousands of people who process XML containing newline characters every day without errors.
Perhaps your newline characters are in the middle of element names, or something else that causes your XML to be not well-formed. I'm just guessing here, though, because you didn't say what errors you were getting.

Similar Messages

  • How can I create a Document object from a text file (myFile.txt)

    Hi everybody:
    Thank you for reading this message.
    I am trying to find a method to convert a text file ( I have it in a File object) to a Document object.
    I read the Java API but it is strange, I do not know if I have to create an AbstractDocument, it is really strange for me.
    Any comment is welcome,
    Regards,
    JB

    Document is an interface, and AbstractDocument is abstract, so you
    can't create either of those directly. Assuming you are dealing with a
    a plain text file, you could do something like
    // Not catching any exceptions that get thrown
    File file = /* file you already have */
    String eol = System.getProperty( "line.separator" );
    int eolLen = eol.length();
    FileReader reader = new FileReader( file );
    BufferedReader buffer = new BufferedReader( reader );
    PlainDocument doc = new PlainDocument();
    for ( String line = buffer.readLine() ; line != null ; line = buffer.readLine() ) {
        int len = doc.getLength();
        if ( len > 0 ) {
            doc.insertString( len, eol, null );
            len += eolLen;
        doc.insertString( len, line, null );
    }and now you have a document.
    : jay

  • How to create a Image object from action script

    I need to set the back ground of charting dynamically, thus I need to create Image from a png/gif files. I have wrritten following code, but doesn't work.
    public function addBackground():void
        var cbg:ChartBackground=new ChartBackground();
        var bgs:Array=new Array();
        bgs.push(cbg);
        lineChart.backgroundElements=bgs;     
    package arubaUI
        import mx.controls.Image;
        [Embed(source="../assets/chart_16.png")]   
        public class ChartBackground extends Image
    Does any one knows how to do that?
    Thanks!

    I put the code like and got compile error:
    public class ArubaLinePanel extends Panel
      private var lineChart:LineChart;
      private var lineData:ArrayCollection=new ArrayCollection( [
                { Month: "Jan", Profit: 2000, Expenses: 1500, Amount: 450 },
                { Month: "Feb", Profit: 1000, Expenses: 200, Amount: 600 },
                { Month: "Mar", Profit: 1500, Expenses: 500, Amount: 300 },
                { Month: "Apr", Profit: 1800, Expenses: 1200, Amount: 900 },
                { Month: "May", Profit: 2400, Expenses: 575, Amount: 500 } ]);
      public function ArubaLinePanel()
            super();           
            lineChart=new LineChart();
            lineChart.dataProvider=lineData;
            lineChart.showDataTips=true;
            var axisX:CategoryAxis=new CategoryAxis()
            axisX.categoryField="Month";
            lineChart.horizontalAxis=axisX;
            var seriesArray:Array = new Array();
            var ls:LineSeries=new LineSeries();
            ls.yField="Profit";
            ls.displayName="Profit";
            seriesArray.push(ls);
            lineChart.series=seriesArray;
            this.addChild(lineChart);
            var legend:Legend=new Legend();
            legend.dataProvider=lineChart;
            this.addChild(legend);       
            addBackground();
    public function addBackground():void
        var cbg:ChartBackground=new ChartBackground();
        var bgs:Array=new Array();
        bgs.push(cbg);
        lineChart.backgroundElements=bgs;     
    Another method I tried:
    package arubaUI
        import mx.controls.Image;
        [Embed(source="../assets/chart_16.png")]   
        public class ChartBackground extends Image
    There is no compile error, but image is not show on screen,
    Thanks!
    April

  • How to make a class object  from a string representation of the same

    i have the name of a class whose object i want to make in the form of a string i.e. String s="S1"; i get this name after some prosessing. so what i want to do is to create an object of S1 which is actually one class that i have implemented.plz hlp. it is urgent.thnx in advance.

    reflection api...
    see java.lang.Class. Read the api docs.
    mostly, u need to do the following:
    Class myClass = Class.forName(s1);
    Object x = myClass.newInstance();
    reg
    s giri

  • How to create a Document Set in SharePoint 2013 using JavaScript Client Side Object Model (JSOM)?

    Hi,
    The requirement is to create ""Document Sets in Bulk" using JSOM. I am using the following posts:-
    http://blogs.msdn.com/b/mittals/archive/2013/04/03/how-to-create-a-document-set-in-sharepoint-2013-using-javascript-client-side-object-model-jsom.aspx
    http://social.msdn.microsoft.com/Forums/sharepoint/en-US/1904cddb-850c-4425-8205-998bfaad07d7/create-document-set-using-ecma-script
    But, when I am executing the code, I am getting error "Cannot read property 'DocumentSet' of undefined "..Please find
    below my code. I am using Content editor web part and attached my JS file with that :-
    <div>
    <label>Enter the DocumentSet Name <input type="text" id="txtGetDocumentSetName" name="DocumentSetname"/> </label> </br>
    <input type="button" id="btncreate" name="bcreateDocumentSet" value="Create Document Set" onclick="javascript:CreateDocumentSet()"/>
    </div>
    <script type="text/javascript" src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js"> </script>
    <script type="text/javascript">
       SP.SOD.executeFunc('sp.js','SP.ClientContext','SP.DocumentSet','SP.DocumentManagement.js',CreateDocumentSet);
    // This function is called on click of the “Create Document Set” button. 
    var ctx;
    var parentFolder;
    var newDocSetName;
    var docsetContentType;
    function CreateDocumentSet() {
        alert("In ClientContext");
        var ctx = SP.ClientContext.get_current(); 
        newDocSetName = $('#txtGetDocumentSetName').val(); 
        var docSetContentTypeID = "0x0120D520";
        alert("docSetContentTypeID:=" + docSetContentTypeID);
        var web = ctx.get_web(); 
        var list = web.get_lists().getByTitle('Current Documents'); 
        ctx.load(list);
        alert("List Loaded !!");
        parentFolder = list.get_rootFolder(); 
        ctx.load(parentFolder);
        docsetContentType = web.get_contentTypes().getById(docSetContentTypeID); 
        ctx.load(docsetContentType);
        alert("docsetContentType Loaded !!");
        ctx.executeQueryAsync(onRequestSuccess, onRequestFail);
    function onRequestSuccess() {       
        alert("In Success");
        SP.DocumentSet.DocumentSet.create(ctx, parentFolder, newDocSetName, docsetContentType.get_id());
        alert('Document Set creation successful');
    // This function runs if the executeQueryAsync call fails.
    function onRequestFail(sender, args) {
        alert("Document Set creation failed" + + args.get_message());
    Please help !!
    Vipul Jain

    Hello,
    I have already tried your solution, however in that case I get the error - "UncaughtSys.ArgumentNullException: Sys.ArgumentNullException:
    Value cannot be null.Parameter name: context"...
    Also, I tried removing SP.SOD.executeFunc
    from my code, but no success :(
    Kindly suggest !!!
    Vipul Jain

  • How to create a document folder using ListData.svc

    Hi All,
    I've recently been put on a project where I need to use the REST services (ListData.svc) to retrieve and add documents to the document library. It all has been smooth sailing until I hit the point where I want to save a document in a path that doesn't exist.
    I get an error if I try to save a file where the folder structure doesn't exist. I then went about it a different way trying to create the folder structure first. This also didn't work and I get an error message saying that the entity type is marked with the
    MediaEntry attribute but no save stream was set for the entity. Not too sure what set for the save stream if I'm just adding a folder.
    So my question is can a file be added to a folder structure that doesn't exist where it automatically creates the folders. If not can the service create folders?
    Some sample code I've been using:
    var folder = new SampleDocumentLibraryItem();
    folder.Name = "Sample";
    folder.Title = "Sample";
    folder.ContentType = "Folder";
    folder.Path = "/sample/folder1/folder2";
    spContext.AddToSampleDocumentLibrary(folder);
    spContext.SaveChanges();
    Thanks in advance,
    Damo

    Hi All,
    Finally managed to figure this one out. For anyone who needs source on how to create a document folder. Some sample source is below...
    var folder = new DocumentLibraryItem();
    folder.Name = "Folder Name";
    folder.Title = "Folder Name";
    folder.ContentType = "Folder";
    folder.Path = path;
    spContext.AddtoDocumentLibrary(folder);
    spContext.SetSaveStream(folder, stream, false, folder.ContentType, folder.Path + folder.Name + "|0x0120009BCC19899CEBC6468FF4EEAC7B8CF4F5"
    spContext.SaveChanges();
    So the important differences in the code above. The content type of the object and stream MUST be set to "Folder". I'm not sure why but you still need to set the save stream to be a valid stream even though you're only adding a folder. So just keep the stream
    open and then pass "true" to close it when you actually save the file. The other important element as noted from the URL's in the previous comments is you need to add a "|" + Content Type ID of a folder. You'll be able to get this ID by visiting the rest service
    for an existing document library and view source to see the actual content type id for a folder.
    Thanks everyone for your help,
    Damo

  • Create internet explorer object from process ID

    Hi,
    I want to create a object for open instance of internet explorer and pass username and password to it.
    By using the below command I am getting the process object but how can we create internet explorer object from it so that I can access document elements.
    gps | ? {$_.mainwindowtitle -match 'Service'} | select name, mainwindowtitle
    Thanks
    Prasanna

    Hi Prasanna,
    If you means create IE object and signin automatically with username and password, the script below is for your reference:
    $username = "....."
    $password = "......"
    $ie = New-Object -com InternetExplorer.Application
    $ie.visible=$true
    $ie.navigate("https://login.live.com/")
    while($ie.ReadyState -ne 4) {start-sleep -m 100}
    $ie.document.getElementById("i0116").value= $username
    $ie.document.getElementById("i0118").value = $password
    $ie.document.getElementById("idSIButton9").click()
    start-sleep -m 100
    gps | ? {$_.mainwindowtitle -match 'Microsoft account'} | select name, mainwindowtitle
    The result like:
    If there is anything else regarding this issue, please feel free to post back.
    Best Regards,
    Anna Wang

  • Transporting Change document Object from development to quality

    Hi All,
    I have created a change document object from SCDO for my custom table. Now I want to transport this object from development server to quality server.
    As while creating Objects some enteries are made into standard table CDHDR and CDPOS which is client dependant so how to work this object on another client.
    Do I need to create seperate objects on quality server and then on production server?
    Thanks

    Hi Kiran,
    use transport connection to collect the objects to request, rsa1->transprot connection.
    use infocube as starting point to collect objects, left side choose 'object type', middle frame choose 'infocube' expand 'select objects', locate/search your infocube' and 'transfer', it will go to right side.
    in right up, there are buttons, click 'mode' and choose manual, and grouping 'only necessary objects', and execute, this will collect infocube and required objects like infoobjects, infoarea, etc.
    after that change grouping 'in dataflow before' and execute, this will collect update rules, ods, infosource, transfer rules, datasource assigned etc.
    remember to assign source system, click yellow box with X icon and mark the source system.
    after that use grouping 'in dataflow afterwards' to collect query, web template, role etc.
    take a look transport docs
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/3010ba90-0201-0010-2896-e58547c6757e
    http://help.sap.com/saphelp_nw2004s/helpdata/en/0b/5ee7377a98c17fe10000009b38f842/frameset.htm
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/e883de94-0501-0010-7d95-de5ffa503a86
    http://help.sap.com/saphelp_nw2004s/helpdata/en/b5/1d733b73a8f706e10000000a11402f/frameset.htm
    http://help.sap.com/saphelp_nw2004s/helpdata/en/57/38e1824eb711d182bf0000e829fbfe/frameset.htm
    Re: Transport Organizer---
    transport query (bex objects)
    http://help.sap.com/saphelp_nw2004s/helpdata/en/38/5ee7377a98c17fe10000009b38f842/frameset.htm
    hope this helps.
    (Courtesy AHP from Re: transport)
    Bye
    Dinesh

  • How can you move the objects from one server to another?

    how can you move the objects from one server to another?

    Hi,
    Collecting objects for Transporting
    1. rsa1->transport connection
    2. left panel choose 'object type', middle panel choose 'infocube' and 'select objects'
    3. then choose your infocube and 'transfer'
    4. will go to right panel, choose collection mode 'manual' and grouping only 'necessary objects'
    5. after objects collection finished, create request
    6. If they are $TMP, then change the package.
    7. When you click the Save on the change package, it will prompt for transport. Here you can provide an existing open transport request number, or if you like here itself you can create a new one.
    8. You can check the request in SE09 to confirm.
    Releasing Transport Request  
    Lets say you are transporting from BWD to BWQ
    Step 1: In BWD go to TCode SE10
    Step 2: Find the request and release it (Truck Icon or option can be found by right click on request #)
    Note: First release the child request and then the parent request
    Steps below are to import transport (generally done by basis )
    Step 1: In BWQ go to Tcode STMS
    Step 2: Click on Import queue button
    Step 3: Double Click on the line which says BWQ (or the system into which transport has to be imported)
    Step 4: Click on refresh button
    Step 5: High light the trasnport request and import it (using the truck icon)
    Transport
    http://help.sap.com/saphelp_nw2004s/helpdata/en/b5/1d733b73a8f706e10000000a11402f/frameset.htm
    http://help.sap.com/saphelp_nw70/helpdata/en/0b/5ee7377a98c17fe10000009b38f842/frameset.htm
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/media/uuid/224381ad-0701-0010-dcb5-d74236082bff
    Hope this helps.
    thanks,
    JituK

  • How to create a BufferedImage object using a .png file on harddisk

    For some application of JFreeChart I want to create a BufferedImage object from png file on harddisk.
    Can anybody tell me how to achieve this?
    Thanks in advance.

    See [this thread|http://forum.java.sun.com/thread.jspa?threadID=5144115].

  • How to create a pdf file from multiple images ?

    Dear All,
    I want to create a SINGLE page pdf file from two or more page size images that are combined to make a single page pdf. Again, this question is on pdfs that are made out of several, atleast  two color images and a black-and-white mask for one of them.
    I have such pdf files from an unknown source (the producer is edited out) whereby there are three tiff images, obtained using the well known pdfimages extractor.
    When I want to make a pdf out of tiff or png or other image formats, I right click and tell Adobe Acrobat to make a pdf.
    However, I dont know how I can give a command to select say,  three tif images and specify which is the mask for which and then join  them in a way that I get the pdf from the composite of the two color images and a mask for one of them.
    Please help me out.
    I am a little familiar with the pdf structure skeleton and when necessary, fixed xref tables in one of my favorite editors. A few years ago, I also wrote a bunch of javascripts to make some annotations and needed some automation and used some itext type libraries. However, I need your help in this problem as I am now rusty and forgot some of what I studied to solve my earlier problems. This is a new problem for me. Gentle hints from you would be very nice to help me in this problem. Please specify if necessary what manual and pages to read. in the pdfspec.
    Best Regards
    Disabled Veteran [physically handicapped]

    Hello Again.
    On Fri, May 11, 2012 at 12:20 PM, lrosenth <[email protected]> wrote:
    >
    > Re: How to create a pdf file from multiple images ?
    >
    > created by lrosenth in PDF Language and Specifications - View the full
    > discussion
    > ________________________________
    >
    > No clue who Irving is…
    >
    I was hoping to have your first name so its easy for me to address you.
    > I have no clue what OS platform, programming language, etc. you use so
    > can’t really narrow things down.
    I would gladly mention that I am working on windows platform, preferably XP.
    I can also work on linux for free products that come with it.
    >  Also, as this is an Adobe forum, we only
    > recommend Adobe products – so there may be other options that even my list
    > wouldn’t include.
    But adding other products, for the help of an adobe products user,
    even if it outside adobe, shall add greater prestige to your company
    and give impression of user-centeredness.
    > If you read ISO 32000-1:2008 (aka the PDF standard), you will find the
    > information about Images and Image Masks well described.  I didn’t think I
    > needed to repeat any of that information.
    Well, just add the few pdf stanzas since you are proficient on it and
    I am presently a little rusty as I mentioned. Just asking a little
    extra yard, not even to go an extra mile.
    > And, if you read that same document, you will see that there is NO SUCH
    > THING as a “text only PDF”.   All PDF documents are structured binary files.
    Well, ascii format or uncompressed format that is human readable. I
    know its a binary file, but human readable ascii version of it.
    I hope you can give me some stanza and various other approaches
    possible so I can select or combine things for myself. I see only a
    miniscule number of posts claiming to have written masks in this forum
    and then with no details.
    Regards
    Roger
    Message was edited by: dying veteran
    because the adobe posting system went crazy and truncated all except the first line ... dunno why

  • ADF Faces: RichTable - How to create a RichTable object

    Hi. How to create a RichTable object to put in a JSF page ? I need to make a method that receive a list of name of columns and a list of list of data. This code that I have writing don't work. What's my error?
            public RichTable getADFTable(
            List<String> lstCols, List< List<String> > lstLstData
            RichColumn adfCol = null;
            List<RichColumn> lstRichCols = new ArrayList<RichColumn>();
            int cont = 0;
            for( String col : lstCols ){
                adfCol = new RichColumn();
                adfCol.setDisplayIndex(cont++);
                adfCol.setHeaderText( col );
                adfCol.setMinimumWidth( "60" );
                lstRichCols.add( adfCol );
            int contCols = 0;
            RichOutputText text = null;
            RichTable AdfTab = new RichTable();
            for( List<String> lstData : lstLstData){
                for( String data : lstData ){
                    text = new RichOutputText();
                    text.setValue(data);
                    lstRichCols.get( contCols ).getChildren().add( text );
                    contCols++;
                contCols = 0;
            AdfTab.setRows(this.lstEntit.size());
            cont = 0;
            for( RichColumn col : lstRichCols ){
                AdfTab.getChildren().add( col );
            return AdfTab;
        }

    I was searching for an example and i found it but whit errors, finally i fixed and it works.
    You just have to generate the data from your webservices and "put" into this structure.
    The java file (Bean)
    package view;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    import org.apache.myfaces.trinidad.model.CollectionModel;
    import org.apache.myfaces.trinidad.model.SortableModel;
    public class DynamicTable {
        private SortableModel model;
        private List<String> columnNames;
        public DynamicTable() {
            columnNames = new ArrayList<String>();
            columnNames.add("Col-1");
            columnNames.add("Col-2");
            generateColumnModel();
        public void generateColumnModel() {
            this.model = new SortableModel(createRows(columnNames));
        private List<Map> createRows(List<String> columnNames) {
            int i = 0;
            List<Map> mapListforRows = new ArrayList<Map>();
            for (String name : columnNames) {
                Map newRow = new HashMap();
                mapListforRows.add(newRow);
                for (String col : columnNames) {
                    newRow.put(col, "data");
            return mapListforRows;
        // Get table model
        public CollectionModel getCollectionModel() {
            return model;
        public void setColumnNames(List<String> columnNames) {
            this.columnNames = columnNames;
        public List<String> getColumnNames() {
            return columnNames;
    }The jspx file (page)
               <af:table varStatus="rowStat" summary="table"
                            value="#{pageFlowScope.DynamicTable.collectionModel}"
                            rows="#{pageFlowScope.DynamicTable.collectionModel.rowCount}"
                            rowSelection="none" contentDelivery="immediate"
                            var="row" rendered="true" id="t1">
                    <af:forEach items="#{pageFlowScope.DynamicTable.columnNames}"
                                var="name">
                      <af:column sortable="true" sortProperty="#{name}"
                                 rowHeader="unstyled" headerText="#{name}"
                                 inlineStyle="width:100px;" id="c1">
                        <af:activeOutputText value="#{row[name]}" id="aot1"/>
                      </af:column>
                    </af:forEach>
                  </af:table>

  • How to pass arraylist of object from action class to jsp and display in jsp

    I need to do the following using struts
    I have input jsp, action class and action form associated to that. In the action class I will generate the sql based on the input from jsp page/action form, create a result set. The result set is stored as java objects in a ArrayList object.
    Now I need to pass the arraylist object to another jsp to display. Can I put the ArrayList object in the request object and pass to the success page defined for the action? If this approach is not apprpriate, please let me know correct approach.
    if this method is okay, how can I access the objects from arraylist in jsp and display their property in jsp. This java object is a java bean ( getter and setter methods on it).
    ( need jsp code)
    Can I do like this:
    <% ArrayList objList = (ArrayList)request.getattribute("lookupdata"): %> in jsp
    (***I have done request.setattribute("lookupdata", arraylistobj); in action class. ***)
    Assuming the java object has two properties, can I do the following
    <% for (iint i=0. i<objList.size;I++){ %>
    <td> what should i do here to get the first property of the object </td>
    <td> what should i do here to get the first property of the object </td>
    <% }
    %>
    if this approach is not proper, how can I pass the list of objects and parse in jsp?
    I am not sure what will be the name of the object. I can find out how many are there but i am not sure I can find out the name
    thanks a lot

    Double post:
    http://forum.java.sun.com/thread.jspa?threadID=5233144&tstart=0

  • How to create FI Document in Idoc.....

    Hi Abapers,
    I hve small doubt that
    how to create FI Document in Idoc.....?????s
    I was new to the Idoc creation .......
    can u give me step by step process..............
    Thanks & Regard
    Ravi Sarma

    Hi Rahul,
    As per my understanding you are loking for creating the IDOC per FI document.
    So if in case the multiple rows have retrived from Oracle Join query then Multiple IDOCs to be created. Per row one IDOC.
    You can do this just by changing the Occurance of IDOC
    Export the XSD structure of imported IDOC from IR and modify the occurance of IDOC field as below example
    <xsd:element name="IDOC" type="ZTEST_IDOC.ZIDOC" maxOccurs="unbounded" />
    Then Import the xsd file as external defination and use it directly in mapping.
    It will create the multiple idocs  with mapping Row field of Oracle structure to IDOC field
    Thanks
    Swarup

  • How to create A/R Invoice from draft

    Hi,
              How to create A/R Invoice from documnet draft using DIAPI.
    Thanks,
    P.Suresh Kumar

    Hi Suresh Kumar,
    You may check this as a reference: Re: Problems while saving the tax values in a Draft Document to AP Invoice
    Thanks,
    Gordon

Maybe you are looking for

  • Updated to 6.1.3 and now my iphone wont connect or charge!

    So ive updated my iPhone 4S to 6.1.3 and now i cant charge the phone or connect it to itunes. Its about to die and im not happy. My partners iphone 4 which i havent updated charges and connects fine so its not the USB, wall charger or the PC. Whats 6

  • Extending flash: how do I set default values for filenames

    Hi, I am trying to set default values for filenames <choosefile> and <popupslider>s that will show up when my XMLpanel first loads in my jsfl extension file. It seems that I can only set default values for textbox items. How do I do this for filename

  • BO Universe on BeX Query in Lumira

    Hi All, I have a requirement of accessing a BeX query in Lumira and do visualizations on it. As Lumira is not capable of accessing BeX query directly, I think, I would need to create a universe on InfoCube, for that BeX query, and then consume that u

  • How can I magic move within a mask

    Hvave masked a long mobile image in keynote over a phone graphic and want to magic move the visual down within the mask but does not seem to work and just fades in and out rather than move?

  • Convert MATNR to EAN11

    Need to create a Enhancement spot in Master_Idoc_Create_BOMMAT where I need to write a code to convert MATNR to EAN11 and assign the value to the idoc field of MATNR.The idoc is BOMMAT04. Please advice for suggestions if any. Regards, Vish