Alteration of the content of an XML node in java

Hi all

I change the contents of an XML node using java, using the method of setTextContent() a node.

Sometimes I also add child nodes of a node. In this case, when I add the child nodes of a given node, when I print the xml data, I see the added nodes.

for example:

Initial XML:

< a > < / a >
< b > < / b >
< c > < / c >


For my project requirement, based on certain conditions, I do 'a' 'b', 'c' as children nodes nodes. I reached this output.


The problem is

FINAL XML:

< a > < b > < / b > < c > < / c > < / a >


I get the nodes children in the same line as above. But the power required should be as below.


REQUIRED XML

< a >
< b > < / b >
< c > < / c >
< /a >

I also used the Doc.normalize () function. But still, it helps strength.

Kindly help me in this regard.

Thank you
Sabarisri. N

Hello

You can try to transform the result as below:

Transformer transformer = TransformerFactory.newInstance () .newTransformer ();
transformer.setOutputProperty (OutputKeys.INDENT, 'yes');

initialize the StreamResult with the object of the file to save to file
StreamResult result = new StreamResult (new StringWriter());

DOMSource source = new DOMSource (doc); Here, the doc is you XML document.
transform. Transform (source, result);

String xmlString = result.getWriter (m:System.NET.SocketAddress.ToString ());
System.out.println (xmlString);

Thank you best regards &,.
Nilesh Sahni (www.infocepts.com)

Published by: Nilesh on August 30, 2011 12:31

Tags: Oracle Development

Similar Questions

  • How to pass the content of an xml element in the text frame in inDesign Script

    var XMLFile = File.openDialog ("select XML Files... ») ;

    var doc = app.activeDocument;

    If (!) App.Documents.Length)

    {alert ("ERROR: Document not opened");}

    return;

    }

    doc.importXML (XMLFile);

    var firstFigureNode = doc.xmlElements [0] .xmlElements [1] .xmlElements [0];

    var lableNode = firstFigureNode.xmlElements [0];

    var lableNodeText = lableNode.contents;

    myFrame var = doc.textFrames.add ({geometricBounds: [-13, 13, 3, -3]});

    lableNodeText.move (LocationOptions.AFTER, myFrame.texts [0]);

    ========================================================

    My requirement is: == > > move the content of an xml element in the text by inDesign Script block, but XML InDesign file Structure should not be change & data in the XML Structure should remain as it was before...

    I tried to code above, but it does not work...

    Please can someone help me in solving this problem...

    It does not work correctly...

    It moves firstFigureNode in myFrame...

    firstFigureNode.placeXML (myFrame);

    ===>> For Apple Script try below Code ===>>

    myFrame markup using firstFigureNode

  • I'm new in indesign scripting, please tell me how to write a script to get the contents of an XML element and then sort all the content

    I'm new in indesign scripting, please tell me how to write a script to get the contents of an XML element and then sort all the content

    Hello

    Can the code below is useful for you, but I do not know how to sort.

    Change the tag based on your employment application.

  • How to browse the hyphen to a xml nodes?

    Hello

    I have a xml structure as follows,

    " < = xmlns:fo fo:root ' http://www.w3.org/1999/XSL/format "xmlns:ucreate =" " http://www.XMPie.com/ucreate ">

    < fo:layout - master-set >

    < fo:simple - page-master >

    < / fo:simple - page-master >

    < / fo:layout - master-set >

    < / fo:root >

    Now, I need through this structure. It is not possible in the usual way as xml.fo:layout - master-set. Flex here give a compilation error. On research, I found that I could browse to fo:layout - master-defined through the namespace. As follows,

    var foNm:Namespace = xml.namespace ("TF");

    var childNode:XMLList = xml.foNm: ['layout-master-set'];

    After the execution, childNode contains the correct list which is in page-master-set.

    However, I have to cross to the simple-page-master node. I tried to do it in a similar way.

    var childNode:XMLList = xml.foNm: ["simple-page-master"];

    But in this case childNode comes empty. How can I do this?

    Please guide.

    Hello

    I solved this problem. Simply as follows:

    var foNm:Namespace = xlim.namespace ("TF");

    var node: XMLList = xlim.foNm: ['layout-master-set'];

    for each (var cNode:XML in the node)

    {

    var childNode:XMLList = cNode.foNm: ["simple-page-master"];

    }

    Thank you!

  • Create text online the content of a xml tag frame?

    Hello! I have a pretty big document created from an XML file, and I would like to convert a series of my XML tags to the anchor text blocks, so I can hang them on the left edge of the lines they appear in.

    My XML file is converted into a

    > root

    > Chapter

    > para

    > id

    1

    > verse

    text

    > id

    > verse

    etc... See extract file here http://1drv.ms/1dX6lYO

    So far, I have the following, which gets me an array containing all the elements ID.

    var myDocument = app.activeDocument;
    var myXMLidElement = myDocument.xmlElements.itemByName("book").xmlElements.itemByName("c").xmlElements.itemByName("p").xmlElements.itemByName("id");
    var myXMLidText= (myXMLidElement.contents);
    var myXMLidLength = myXMLidText.length;
    for (var i = 0; i < myXMLidLength; i++) {  //loop to go through
        //alert (myXMLidText[i]);
        myDocument.select(myXMLidText[0]);  //this gives me an error saying expected data type needs to be array. Can someone explain? Where do I find info on the select command?
        myDocument.selection[0].insertionPoints[0].textFrames.add(myXMLidText[0]); //haven't managed to get to this line yet, but I want it to create an inline text frame at the point of the selected text and set the frame's contents to be my XML Id Text
    

    I guess I want and then delete all the text in my id too, but that's not important.

    Some other random excerpts, I could use?

    myInlineFrame.contents = "myXMLidText";
    

    Guidance on the creation of the inline frames and the logic of loop? I'm an old hand with InDesign, but new to scripting, so be gentle.

    Try this,

    var myDocument = app.activeDocument;
    var root = myDocument.xmlElements[0];
    var myXMLidElement = root.evaluateXPathExpression("//book/c/p/id");
    for (var i = 0; i < myXMLidElement.length; i++)
    {
        myDocument.select(myXMLidElement[i]);
        var myTextframe = myXMLidElement[i].placeIntoInlineFrame(["1p","1p"]);
    }
    
  • Creating instances of the class customized for XML nodes

    Hi guys,.

    I'm trying to load an external XML document in my application and create an instance of a custom class for each node in the XML file based on the value of some of their elements. Instances created later will end by in a DataGrid by the way. The problem I have is there seems to be several ways to make small parts of it and I have no idea how do them all gel. Initially, I use HTTPService to load the XML file, but I've seen people just use a XML object. Then, after that, I put the XML loaded to an ArrayCollection collection initially, but others used XMLList or XMLListCollection. I have no idea of what is the best way to do it.

    Finally, when I created all of these instances by looping through XML and their creation how I'll make them bindable to the DataGrid? I guess I'll have to group together them somehow...

    Any help would be greatly appreciated. Thank you

    Create a class customized for your 'point' of dataGrid dataProvider objects
    * Use HttpService to get the XML code.
    * use an e4x expression for the child nodes of the xml in an XMLList: myXML.children () or myXML.myNodes;
    * use a for loop on the XMLList
    * inside of the loop, create a new instance of the custom class
    * Of the [i] myXMLList, obtain all necessary attribute values and assign them to the appropriate properties in the instance of the custom class.
    * always inside the loop, use myArrayCollection.addItem (mycustomClass) to add the element to the collection of the dataProvider ArrayCollection.

    Tracy

  • iOS: problem with loading the content of an xml file placed on a server

    So, I have an app that loads a few small things (pictures and text) of a xml/php file on the server. Everything works fine on both android and in the flash debugger, but when I install the ipa file on my iPhone my IOErrorEvent displays an error message. When the xml file and example photos come with the app (they are not on the server, but in the ipa file) everything works perfectly. There is something about iOS that prevents me to load all the data from the server, it seems. There must be a way around it.

    I would be grateful for advice.

    Kind regards

    Array must be table.

  • Extract the contents of an XML string in offline mode

    HI gentlemen,

    Could you help me solve this problem? I had a string of Java (see below) read in a smart German eHealth card. I have to extract the tag values and put them in local variables for further processing in my Java module. How to move forward without connecting to a database, it is enough to analyze the source - the string variable? Note that the lines are separated by only 0x0A.
    <?xml version="1.0" encoding="ISO-8859-15" standalone="yes"?>
    <UC_PersoenlicheVersichertendatenXML CDM_VERSION="5.1.0" xmlns="http://ws.gematik.de/fa/vsds/UC_PersoenlicheVersichertendatenXML/v5.1">
        <Versicherter>
            <Versicherten_ID>X110101627</Versicherten_ID>
            <Person>
                <Geburtsdatum>19840717</Geburtsdatum>
                <Vorname>Johanna</Vorname>
                <Nachname>Düsterbehn</Nachname>
                <Geschlecht>W</Geschlecht>
                <StrassenAdresse>
                    <Postleitzahl>93055</Postleitzahl>
                    <Ort>Regensburg</Ort>
                    <Land>
                        <Wohnsitzlaendercode>D</Wohnsitzlaendercode>
                    </Land>
                    <Strasse>Sulzfeldstraße</Strasse>
                    <Hausnummer>7</Hausnummer>
                </StrassenAdresse>
            </Person>
        </Versicherter>
    </UC_PersoenlicheVersichertendatenXML>
    Thank you very much for your help,
    sincere friendships of

    Miklós HERBOLY
    java.lang.NoClassDefFoundError: XpathSampleClass (wrong name: XPathSampleClass)
    

    If you use my code sample in extenso, the class is named 'XPathSampleClass' (capital P), and of course the .class file must have the same name.

  • When I receive a message with an attached large xml file, I have to wait long until Thunderbird shows and displays the contents of the file. How to avoid this problem.

    Attachments such as Word or Excel files are shown only as attachments in a bar at the bottom of the message entering without rendering of such content. But Thunderbird always try to read the contents of an xml file in order to show ALL he's happy. If the file is large, it takes a lot of time, so the Thunderbirds crashes usually on, so I have to restart.

    I would like to be able to make some adjustments to prevent display of the contents of the xml files attached in incoming messages. Thank you.

    View (alt + V) menu > display the inline attachment

  • The value of the XML node

    I'm going after Yahoo Weather and try to get the value of an XML node

    So after I take the node

    item_buildNode.ToString () = < lastBuildDate > Tuesday, December 26, 2006 12:51 pm CST < / lastBuildDate >

    So I know that I have the appropriate node

    But I want just the value without the tags

    If I try to item_buildNode... nodeValue, which returns a null value

    Can I just the value? If so, how?


    Thank you
    Mathias

    Well, too bad. I have search the Forum better.

    It's item_buildNode.firstChild.nodeValue

  • XML nodes that contain dashes

    So, I try to remove the content of an xml document that looks like this:

    < xts:sports - content - value >
    < sports-content >
    < sporting event - >
    team <>
    < / team >
    < / event >
    </sport/content >
    < / xts:sports - content - value >

    and the problem I have is that when I try to refer to xmlroot.sports - happy coldfusion throws an error that says sport is not a child xmlroot element.
    I think that it is reading as LESS content xmlroot.sports.

    How can I get around this so that he sees the child node as sports content?

    I tried xmlroot.xmlchildren ['sports content"]

    but who made a mistake by saying:
    The "sport-content" value cannot be converted to a number

    How can I reference this child node by its name?

    works like a charm thanks!

  • How to change content/type application/xml, text/xml?

    Hi gurus B2B.
    Now that I've worked on the transfer of files. Now, I tried to post the same document on an HTTP URL.
    I see in the headers that the
    Content-Type = application/XML
    However, I need the Content-Type text/XML

    Where can I get it changed?

    Published by: user773213 on April 8, 2009 04:48

    If you use AQ together the content as part of QA header type (add below in the enqueue.properties).

    actionName = CONTENTTYPE:text / xml;

    concerning
    Nebot

  • How to get the value of a literal XML node content in BPEL 2.0?

    Hello!

    I have a problem creating A Expression in the distribution of the XML literal one activity, I would like to help me...

    Well, I have the same activity in the 1.0 version of BPEL and is now different is BPEL 2.0,.

    I have a Web Service < WSEjecutaComandos > when having a function of controls remote that connects,

    Entries of my Web Service: "int numEquipo, String [] comandos, int numCta, int publicar, int, String date version"

    The second argument is an array of string type...

    Now in my BPEL process, I do is the following assignment:

    ************************************************************

    < assign the name = "AssignCreaPath" >

    < copy >

    < from >

    < literal >

    " < fnCRexecElement xmlns =" http://Servicios/ ">

    < numEquipo > 2 < / numEquipo >

    < comandos >mkdir etl/entries/mmkis /< / comandos >

    < numCuenta > 1 < / numCuenta >

    < publicar > 0 < / publicar >

    < / fnCRexecElement >

    < / literal >

    < / from >

    < to > $InvokeClear_fnCRexec_InputVariable.parameters < /pour >

    < / copy >

    < copy >

    (< a >concat(ora:getContentAsString($InvokeClear_fnCRexec_InputVariable.parameters/comandos),$inputVariable.payload/client:fecha)< / from >

    < to >$InvokeClear_fnCRexec_InputVariable.parameters/comandos< /pour >

    < / copy >

    < copy >

    < a > $InvokeVersion_fnGetVersionProcesoByFecha_OutputVariable.parameters/version < / from >

    < to > $InvokeClear_fnCRexec_InputVariable.parameters/version < /pour >

    < / copy >

    < copy >

    < a > $inputVariable.payload / client: date < / from >

    < to > $InvokeClear_fnCRexec_InputVariable.parameters/date < /pour >

    < / copy >

    < / assign >

    ***************************************************

    Well the conflict I have is as follows,

    previously defined an entitlement with the XML Fragment copied on the payload to the Web Service (WSEjecutaComandos), input variable

    and the XML code is copied to each of the variables,

    Then him concatenating input values (I noted in red) < comandos > with the value of 'farm' (String), and once again copy Variable < comandos > and has not had any problems

    but now with the new BPEL 2.0, I do the same thing now using literal XML (this good!) but the option to concatenate (that I've noticed in red) and copied to the same variable ( I noticed blue ), I mark the following error message:

    Error1.png

    I should know, I am doing wrong, or you need to to XPath function as the value that they already have the variable < comandos > will concatenate date,

    and is the final value of my entry, my Web Service.

    must be defined as table of values of type < comandos [i] >

    define the following activities before $InvokeClear_fnCRexec_InputVariable.parameters/comandos [1],

    but it seems that this BPEL 2.0 does not respect me in the form of hooks index.

    Thank you...

    See you soon,.

    I found the solution to get the value of an xml element and it concatenated with another variable within a beneficiary.

    is:

    ORA: getNodeValue (ora:getChildElement($InvokeCreaPath_fnCRexec_InputVariable.parameters,2))

    first get the desire here in my tree xml element is position 2 < comandos=""> and then get the value of this node.

    See you soon,.

  • Get all the text values in a XML node

    Suppose I have a XMLList that I'm working my way through and I want to quickly and easily get all the 'text' from the node. In other work strip the < xmtag > all possible markup and attributes and just leave the content.

    There is a simple/fast way to do it?

    < myNode >

    < title > title an event here < /title >

    < host > name and title of the presenter here < / presenter >

    < date startTime = "Somedate" / >

    < desc > <! [CDATA [text here. [[It < b > would < /b > have html or links or something like.]] > < / desc >

    < resources >

    list of < resources > has some resources, downloads, etc. < / res >

    < resources > another site or something like < / res >

    < / resource >

    < / myNode >

    If the xml is your XML instance, after loading is finished:

    trace (XML.descedants("*"). Text());

  • When I try to open firefox I get a window does not respond to 62 s, then the error: ' Script: chrome://browser/content/customizableui/toolbar.xml:216.

    I uninstalled and then reinstalled, same error.

    A script on this page may be busy, or it may have stopped responding. You can stop the script now, open the script in the debugger or let the script.

    Script: chrome://browser/content/customizableui/toolbar.xml:216

    Try to delete a file user.js possible and numbered files prefs-# .js and rename (or delete) the file prefs.js to reset all default prefs, including the defined via user.js and prefs prefs is no longer supported in the current version of Firefox.

    You can also check the problems caused by a corrupt localstore.rdf file.

Maybe you are looking for

  • CTRL + F search tool broken?

    The Find bar (ctrl + f) seems to be broken. I'll get something which lies directly on the page that I can see on the page, but he claims, there is no result found. I tried already many works patches people claim (check if case-sensitive is selected [

  • Problem with Toshiba Store.E Basic 2 TB HDD using Windows XP

    I added my old PC (Pentiun IV 2400 G, teacher of XP sp3), a new Store.e USB 2 TB HARD drive basics, if I connect warm works perfectly, but if I start the PC with the USB port connected, the system does not start, remain indefinitely in the Intel home

  • a610n - fan error of the system after replacing the motherboard

    Hi all I just replaced the motherboard on my system (phone http://h30434.www3.hp.com/t5/Desktop-Hardware/M2N68-LA-Narra-2-Replacement/td-p/3711774) and now I get this error when starting: Fan failure system, PC service to avoid any damage. I thought

  • Satellite U305 S7446 - internal keyboard delivers outdoor work but

    I'm having a problem with my keyboard on my Satellite U305 S7446, that I bought in 2007 in the United States. I live in Ireland. It is rarely used agao and 2 weeks, I discovered that my keyboard has become intermittent and sometimes would not work. T

  • Satellite A60: Is it possible for a boot from USB?

    It is so, seems there is no way to boot on USB or HD satellite (mine is an A60E). Do you have someone have the head or read that the next version of the bios might do?