Update xml string values.

Hi,
I'm on 11.2.0.2 and got table with nclob column which stores long xml string .
{code}
"<?xml version="1.0" encoding="UTF-8"?>
<?fuego version="6.5.2" build="101272"?>
<set>
<configuration name="TEST Database" type="SQL" subtype="DDORACLE">
  <property name="jdbc.pool.idle_timeout" value="5"/>
  <property name="jdbc.pool.entry.max" value="10"/>
  <property name="oracle.dateEqualsTimestamp" value="false"/>
  <property name="jdbc.schema" value="user1"/>
  <property name="jdbc.host" value="hostname"/>
  <property name="user" value="user1"/>
  <property name="jdbc.port" value="1521"/>
  <property name="jdbc.pool.min" value="0"/>
  <property name="jdbc.pool.maxopencursors" value="50"/>
  <property name="oracle.sid" value="dbsid"/>
  <property name="password" value="user101"/>
  <property name="jdbc.xa" value="false"/>
  <property name="jdbc.pool.max" value="10"/>
</configuration>
<configuration name="TEST Database2" type="SQL" subtype="DDORACLE">
  <property name="jdbc.pool.idle_timeout" value="5"/>
  <property name="jdbc.pool.entry.max" value="10"/>
  <property name="oracle.dateEqualsTimestamp" value="false"/>
  <property name="jdbc.schema" value="user2"/>
  <property name="jdbc.host" value="hostname"/>
  <property name="user" value="user2"/>
  <property name="jdbc.port" value="1521"/>
  <property name="jdbc.pool.min" value="0"/>
  <property name="jdbc.pool.maxopencursors" value="50"/>
  <property name="oracle.sid" value="dbsid2"/>
  <property name="password" value="user201"/>
  <property name="jdbc.xa" value="false"/>
  <property name="jdbc.pool.max" value="10"/>
</configuration>
</set>
{code}
My goal is to update password value in such way that it equals to value from jdbc.schema value  <property name="jdbc.schema" value="user2"/>   so in this case user2 || '01'
<property name="password" value="user201"/>   <-- that is my goal .
Regards
Greg

Hi,
You can find a few methods here : How To : Update XML nodes with values from the same document | Odie's Oracle Blog
They're not all applicable to your version and settings though.
Here's the first one applied to your case :
declare
  v_xmldoc   xmltype;
begin
  select xmlparse(document to_clob(t.xmldoc))
  into v_xmldoc
  from my_nclob_table t
  where t.id = 1;
  for r in (
    select idx, schema_name
    from my_nclob_table t
       , xmltable(
           '/set/configuration'
           passing v_xmldoc
           columns idx         for ordinality
                 , schema_name varchar2(30) path 'property[@name="jdbc.schema"]/@value'
  loop
    select updatexml(
             v_xmldoc
           , '/set/configuration['||to_char(r.idx)||']/property[@name="password"]/@value'
           , r.schema_name || '01'
    into v_xmldoc
    from dual ;
  end loop;
  update my_nclob_table t
  set t.xmldoc = to_nclob(xmlserialize(document v_xmldoc indent))
  where t.id = 1;
end;
Here's another one, using DOM :
declare
  doc   clob;
  p        dbms_xmlparser.Parser;
  domdoc   dbms_xmldom.DOMDocument;
  docnode  dbms_xmldom.DOMNode;
  conf_list      dbms_xmldom.DOMNodeList;
  conf_node      dbms_xmldom.DOMNode;
  password_node  dbms_xmldom.DOMNode;
  schema_name     varchar2(30);
  password_value  varchar2(256);
begin
  select to_clob(xmldoc)
  into doc
  from my_nclob_table
  where id = 1 ;
  p := dbms_xmlparser.newParser;
  dbms_xmlparser.parseClob(p, doc);
  domdoc := dbms_xmlparser.getDocument(p);
  dbms_xmlparser.freeParser(p);
  docnode := dbms_xmldom.makeNode(domdoc);
  conf_list := dbms_xslprocessor.selectNodes(docnode, '/set/configuration');
  for i in 0 .. dbms_xmldom.getLength(conf_list) - 1 loop
    conf_node := dbms_xmldom.item(conf_list, i);
    dbms_xslprocessor.valueOf(conf_node, 'property[@name="jdbc.schema"]/@value', schema_name);
    password_node := dbms_xslprocessor.selectSingleNode(conf_node, 'property[@name="password"]/@value');
    dbms_xmldom.setNodeValue(password_node, schema_name || '01');
  end loop;
  dbms_xmldom.writeToClob(domdoc, doc);
  dbms_xmldom.freeDocument(domdoc);
  update my_nclob_table t
  set t.xmldoc = to_nclob(doc)
  where t.id = 1;
end;
Message was edited by: odie_63 - added DOM example

Similar Messages

  • How to update a string value located on the main VI

    Hello
    I would like, from a subVI, to update a string value located in the main VI (using References). I was trying to find examples on NI web page but it´s impossible to download them (for more than one month : Error, File Not Found), do everyone has got the same problem?
    Thanks for your answer
    Nicolas

    Hi,
    this is from LV help file:
    Complete the following steps to create a subVI that includes a control reference directly from a Property Node.
    1.On the block diagram, right-click the front panel object terminal for which you want a control reference and select Create»Property Node from the shortcut menu to create a Property Node implicitly linked to the object. You can have multiple Property Nodes for multiple front panel objects.
    2.Use the Positioning tool to select the new Property Node and select Edit»Create SubVI from menu. LabVIEW automatically creates a control reference to the control on the block diagram of the main VI, creates a subVI that contains a control refnum wired to a Property Node, and wires the control reference on the main VI to the
    control refnum input terminal of the new subVI.
    Note: Select several Property Nodes at once to create a subVI with multiple control refnums and Property Nodes.
    3.Double-click the subVI to open it. Modify the Property Node and other elements of the subVI as you do in any other VI.
    4. If you want to change values of control then select "Value" property in Property node.
    I've attached the examples.
    Good luck.
    Oleg Chutko.
    Attachments:
    Ref.zip ‏11 KB

  • Error after transforming xml string

    I have an XML string that I have to parse and update (transformer)
              String ji = "<book><person><first>p</first><last>m</last><age>22</age></person><person><first>b</first><last>g</last><age>46</age></person><person><first>s</first><last>j</last><age>40</age></person></book>";
              ByteArrayInputStream str = new ByteArrayInputStream(ji.getBytes());
                   DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
                   DocumentBuilder docBuilder = documentBuilderFactory.newDocumentBuilder();
                   Document doc = docBuilder.parse(str);
                   doc.getDocumentElement().normalize();
                   str.reset();
                   ByteArrayOutputStream bos = new ByteArrayOutputStream();
                   NodeList listOfPersons = doc.getElementsByTagName("person");
                             int total = listOfPersons.getLength();
                             for(int i = 0; i < total; i++)
                                  Node firstpersonnode = listOfPersons.item(i);
                                  if(firstpersonnode.getNodeType() == Node.ELEMENT_NODE)
                                       Element firstPersonElement = (Element)firstpersonnode;
                                       NodeList firstNameList = firstPersonElement.getElementsByTagName("first");
                                       Element firstNameElement = (Element)firstNameList.item(0);
                                       NodeList textFNList = firstNameElement.getChildNodes();
                                       Text t = (Text) textFNList.item(0);
                                       String p = t.toString();
                                       System.out.println("First Name : " +p);
                                       t.setData("sdasdsa");
                                       //String q = t.toString();
                                       //response.write("First Name : " +q);
                                       NodeList lastNameList = firstPersonElement.getElementsByTagName("last");
                                       Element lastNameElement = (Element)lastNameList.item(0);
                                       NodeList textLNList = lastNameElement.getChildNodes();
                                       System.out.println("Last Name : " + ((Node)textLNList.item(0)).getNodeValue().trim());
                                       NodeList ageList = firstPersonElement.getElementsByTagName("age");
                                       Element ageElement = (Element)ageList.item(0);
                                       NodeList textAgeList = ageElement.getChildNodes();
                                       System.out.println("Age : " + ((Node)textAgeList.item(0)).getNodeValue().trim());
    I then write the ByteArrayOutputStream to an OutputStream becoz I need it in that format for the Transformer.
    oos = bos;
    str.reset();
    Source source = new DOMSource(doc);
    Result res = new StreamResult(oos);
    Transformer x = TransformerFactory.newInstance().newTransformer();
    x.transform(source,res);
    System.out.println("now the string is = "+oos.toString());
    Which Transforms it:
    Now my output is the Old XML string + some xml declaration + the Updated XML string.
    First Name : p
    Last Name : m
    Age : 22
    First Name : b
    Last Name : g
    Age : 46
    First Name : s
    Last Name : j
    Age : 40
    now the string is = <book><person><first>p</first><last>m</last><age>22</age></person><person><first>b</first><last>g</last><age>46</age></person><person><first>s</first><last>j</last><age>40</age></person></book><?xml version="1.0" encoding="utf-8"?>
    <book><person><first>sdasdsa</first><last>m</last><age>22</age></person><person><first>sdasdsa</first><last>g</last><age>46</age></person><person><first>sdasdsa</first><last>j</last><age>40</age></person></book>
    I only need to update the string

    Clap... here is the compilable code complete:
    Tried to make it shorter...:
    public class TestXML {
         public static void main(String[] args) {
              String ji = "<book><person><first>p</first><last>m</last><age>22</age></person><person><first>b</first><last>g</last><age>46</age></person><person><first>s</first><last>j</last><age>40</age></person></book>";
              ByteArrayInputStream str = new ByteArrayInputStream(ji.getBytes());
              ByteArrayOutputStream os=null;
              OutputStream oos = null;
              try
                   DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
                   DocumentBuilder docBuilder =  documentBuilderFactory.newDocumentBuilder();
                   Document doc = docBuilder.parse(str);
                   doc.getDocumentElement().normalize();
                   str.reset();
                   ByteArrayOutputStream bos = new ByteArrayOutputStream();
                   NodeList listOfPersons = doc.getElementsByTagName("person");
                             int total = listOfPersons.getLength();
                             for(int i = 0; i < total; i++)
                                  Node firstpersonnode = listOfPersons.item(i);
                                  if(firstpersonnode.getNodeType() == Node.ELEMENT_NODE)
                                       Element firstPersonElement =  (Element)firstpersonnode;
                                       NodeList firstNameList = firstPersonElement.getElementsByTagName("first");
                                       Element firstNameElement = (Element)firstNameList.item(0);
                                       NodeList textFNList = firstNameElement.getChildNodes();
                                       Text t = (Text) textFNList.item(0);
                                       String p = t.toString();
                                       System.out.println("First Name : " +p);
                                       t.setData("sdasdsa");
                                                                     NodeList lastNameList = firstPersonElement.getElementsByTagName("last");
                                       Element lastNameElement = (Element)lastNameList.item(0);
                                       NodeList textLNList = lastNameElement.getChildNodes();
                                       System.out.println("Last Name : " + ((Node)textLNList.item(0)).getNodeValue().trim());
                                       NodeList ageList = firstPersonElement.getElementsByTagName("age");
                                       Element ageElement = (Element)ageList.item(0);
                                       NodeList textAgeList = ageElement.getChildNodes();
                                       System.out.println("Age : " +   ((Node)textAgeList.item(0)).getNodeValue().trim());
                   byte b;
                   while ((b =(byte) str.read()) != -1) {
                        bos.write(b);
                   oos = bos;
                                            str.reset();
                             Source source = new DOMSource(doc);
                             Result res = new StreamResult(oos);
                             Transformer x =  TransformerFactory.newInstance().newTransformer();
                             x.transform(source,res);
                             System.out.println("now the string is = "+oos.toString());
         catch(Exception e){System.out.println(e);}
    }The o/p is as I mentioned in my first post
    Message was edited by:
    PremPrem
    Message was edited by:
    PremPrem

  • Error transforming XML string

    I have an XML string that I have to parse and update (transformer)
              String ji = "<book><person><first>p</first><last>m</last><age>22</age></person><person><first>b</first><last>g</last><age>46</age></person><person><first>s</first><last>j</last><age>40</age></person></book>";
              ByteArrayInputStream str = new ByteArrayInputStream(ji.getBytes());
                   DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
                   DocumentBuilder docBuilder =  documentBuilderFactory.newDocumentBuilder();
                   Document doc = docBuilder.parse(str);
                   doc.getDocumentElement().normalize();
                   str.reset();
                   ByteArrayOutputStream bos = new ByteArrayOutputStream();
                   NodeList listOfPersons = doc.getElementsByTagName("person");
                             int total = listOfPersons.getLength();
                             for(int i = 0; i < total; i++)
                                  Node firstpersonnode = listOfPersons.item(i);
                                  if(firstpersonnode.getNodeType() == Node.ELEMENT_NODE)
                                       Element firstPersonElement =  (Element)firstpersonnode;
                                       NodeList firstNameList = firstPersonElement.getElementsByTagName("first");
                                       Element firstNameElement = (Element)firstNameList.item(0);
                                       NodeList textFNList = firstNameElement.getChildNodes();
                                       Text t = (Text) textFNList.item(0);
                                       String p = t.toString();
                                       System.out.println("First Name : " +p);
                                       t.setData("sdasdsa");
                                       //String q = t.toString();
                                       //response.write("First Name : " +q);
                                       NodeList lastNameList = firstPersonElement.getElementsByTagName("last");
                                       Element lastNameElement = (Element)lastNameList.item(0);
                                       NodeList textLNList = lastNameElement.getChildNodes();
                                       System.out.println("Last Name : " + ((Node)textLNList.item(0)).getNodeValue().trim());
                                       NodeList ageList = firstPersonElement.getElementsByTagName("age");
                                       Element ageElement = (Element)ageList.item(0);
                                       NodeList textAgeList = ageElement.getChildNodes();
                                       System.out.println("Age : " +   ((Node)textAgeList.item(0)).getNodeValue().trim());
                             }I then write the ByteArrayOutputStream to an OutputStream becoz I need it in that format for the Transformer.
    oos = bos;
    str.reset();
                             Source source = new DOMSource(doc);
                             Result res = new StreamResult(oos);
                             Transformer x = TransformerFactory.newInstance().newTransformer();
                             x.transform(source,res);
                             System.out.println("now the string is = "+oos.toString());
    Which Transforms it:
    Now my output is the Old XML string + some xml declaration + the Updated XML string.
    First Name : p
    Last Name : m
    Age : 22
    First Name : b
    Last Name : g
    Age : 46
    First Name : s
    Last Name : j
    Age : 40
    now the string is = <book><person><first>p</first><last>m</last><age>22</age></person><person><first>b</first><last>g</last><age>46</age></person><person><first>s</first><last>j</last><age>40</age></person></book><?xml version="1.0" encoding="utf-8"?>
    <book><person><first>sdasdsa</first><last>m</last><age>22</age></person><person><first>sdasdsa</first><last>g</last><age>46</age></person><person><first>sdasdsa</first><last>j</last><age>40</age></person></book>I only need to update the string

    I have an XML string that I have to parse and update (transformer)
              String ji = "<book><person><first>p</first><last>m</last><age>22</age></person><person><first>b</first><last>g</last><age>46</age></person><person><first>s</first><last>j</last><age>40</age></person></book>";
              ByteArrayInputStream str = new ByteArrayInputStream(ji.getBytes());
                   DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
                   DocumentBuilder docBuilder =  documentBuilderFactory.newDocumentBuilder();
                   Document doc = docBuilder.parse(str);
                   doc.getDocumentElement().normalize();
                   str.reset();
                   ByteArrayOutputStream bos = new ByteArrayOutputStream();
                   NodeList listOfPersons = doc.getElementsByTagName("person");
                             int total = listOfPersons.getLength();
                             for(int i = 0; i < total; i++)
                                  Node firstpersonnode = listOfPersons.item(i);
                                  if(firstpersonnode.getNodeType() == Node.ELEMENT_NODE)
                                       Element firstPersonElement =  (Element)firstpersonnode;
                                       NodeList firstNameList = firstPersonElement.getElementsByTagName("first");
                                       Element firstNameElement = (Element)firstNameList.item(0);
                                       NodeList textFNList = firstNameElement.getChildNodes();
                                       Text t = (Text) textFNList.item(0);
                                       String p = t.toString();
                                       System.out.println("First Name : " +p);
                                       t.setData("sdasdsa");
                                       //String q = t.toString();
                                       //response.write("First Name : " +q);
                                       NodeList lastNameList = firstPersonElement.getElementsByTagName("last");
                                       Element lastNameElement = (Element)lastNameList.item(0);
                                       NodeList textLNList = lastNameElement.getChildNodes();
                                       System.out.println("Last Name : " + ((Node)textLNList.item(0)).getNodeValue().trim());
                                       NodeList ageList = firstPersonElement.getElementsByTagName("age");
                                       Element ageElement = (Element)ageList.item(0);
                                       NodeList textAgeList = ageElement.getChildNodes();
                                       System.out.println("Age : " +   ((Node)textAgeList.item(0)).getNodeValue().trim());
                             }I then write the ByteArrayOutputStream to an OutputStream becoz I need it in that format for the Transformer.
    oos = bos;
    str.reset();
                             Source source = new DOMSource(doc);
                             Result res = new StreamResult(oos);
                             Transformer x = TransformerFactory.newInstance().newTransformer();
                             x.transform(source,res);
                             System.out.println("now the string is = "+oos.toString());
    Which Transforms it:
    Now my output is the Old XML string + some xml declaration + the Updated XML string.
    First Name : p
    Last Name : m
    Age : 22
    First Name : b
    Last Name : g
    Age : 46
    First Name : s
    Last Name : j
    Age : 40
    now the string is = <book><person><first>p</first><last>m</last><age>22</age></person><person><first>b</first><last>g</last><age>46</age></person><person><first>s</first><last>j</last><age>40</age></person></book><?xml version="1.0" encoding="utf-8"?>
    <book><person><first>sdasdsa</first><last>m</last><age>22</age></person><person><first>sdasdsa</first><last>g</last><age>46</age></person><person><first>sdasdsa</first><last>j</last><age>40</age></person></book>I only need to update the string

  • How to update/change the value of elements in an xml file?

    Hi Everyone,
    Could any one of u tell me how to update the value of elements in an XML file, using java? The reason is i want to use an XML file as a data source (i.e. more or less like a database), without using any RDBMS, for simple applications such as to read a record and update the record. By the way, my XML file will have only one record, such as the current weather information, with fields such as temperature, humdity etc. for 1 city only.
    Thanks in advance.

    Here is a solution how to check a particular value or element name in an xml and update the changes e to an xml.
    Sample.xml
    <URLConstructor>
    <application name="cp_outage">
    <resource>hello</resource>
    <value>val</value>
    </application>
    <application name="cp_outage">
    <resource>hello</resource>
    <value>val</value>
    </application>
    </URLConstructor>
    XMLWriter.java
    package com;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import org.jdom.Document;
    import org.jdom.Element;
    import org.jdom.JDOMException;
    import org.jdom.input.DOMBuilder;
    import org.jdom.output.XMLOutputter;
    // used for printing
    import org.apache.xml.serialize.XMLSerializer;
    import org.jdom.output.XMLOutputter;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.OutputStream;
    import java.util.Iterator;
    import java.util.List;
    class XMLWriter{
    public void update(File fileName)
    try {
              DOMBuilder domBuilder=new DOMBuilder();
              Document doc=domBuilder.build(fileName);
              Element element=doc.getRootElement();
              getChildren(element);
              writeToXML(doc,fileName);
              getChildren(element);
    } catch (Exception e) {
    e.printStackTrace();
         * @param doc
         private void writeToXML(Document document,File filePath)
                   XMLOutputter xmloutputter = new XMLOutputter();
                        try
                             FileOutputStream fileOutputStream = new FileOutputStream(filePath);
                             xmloutputter.output(document, fileOutputStream);
                             fileOutputStream.close();
                        catch (FileNotFoundException e)
                             e.printStackTrace();
                        catch (IOException e)
                             e.printStackTrace();
         public void getChildren(Element element)
                        if(!element.hasChildren())
                             return;
                        List childrenList = element.getChildren();
                        Iterator itr=childrenList.iterator();
                        while(itr.hasNext())
                             Element childElement=(Element) itr.next();
                             if(childElement.hasChildren())
                                       getChildren(childElement);
    //                                   System.out.println("Name "+childElement.getName());
    //                                   System.out.println("Value "+childElement.getText());
                                       if(childElement.getText().equals("hello") || (childElement.getName().equals("resource")))
                                            updateInfo(childElement,"New_Resource","AddedText");
         * @param childElement
         * @param string
         * @param string2
         private void updateInfo(Element element, String elementName, String value)
              element.setName(elementName);
              element.setText(value);          
    static public void main(String[] args)
    XMLWriter xmlWriter=new XMLWriter();
    xmlWriter.update(new File("c:/sample.xml"));
    After execution the file will be changed to
    <URLConstructor>
    <application name="cp_outage">
    <New_Resource>AddedText</New_Resource>
    <value>val</value>
    </application>
    <application name="cp_outage">
    <New_Resource>AddedText</New_Resource>
    <value>val</value>
    </application>
    </URLConstructor>
    Regards,
    Maheswar

  • Updating an oracle table with data from an xml string

    Hi - I need help with the following problem:
    We have a table in the database with a field of xml type. We are going to take each string that gets inserted into the xml type field in the 'xml table' and parse the data into another oracle table with corresponding fields for every element.
    once the record gets inserted into the 'real table' the user might want to update this record they will then insert another record into the 'xml table' indicating an update(with a flag) and then we need to update the 'real table' with the updated values that have been sent in.
    The problem that I am having is that I do not know how to create this update statement that will tell me which fields of the table need to be updated.(only the fields that need to be updated will be in the xml string in the 'xml table').
    Please help me with this - ASAP!

    Are you wanting to upload the file through an Oracle Form or just upload a file? If it isn't via forms, then you should probably post your question here: {forum:id=732}
    You also should post the version of Forms, Database, etc...
    As far as uploading files via a text file, I personally like to use Oracle External Tables even in Forms. You can Google that and there is plenty of information. If you search this forum, then you will see lots of people use UTL_FILE in forms, but you can Google that also for more information.

  • How to get string value from xml in JSF??

    In JSF How to get string value from xml, .ini and properties file. I want to get string value from xml or text to JSF

    Just use the appropriate API's for that. There are enough API's out which can read/parse/write XML, ini and properties files. E.g. JAXP or DOM4J for xml files, INI4J for ini files and Sun's own java.util.Properties for propertiesfiles.
    JSF supports properties files as message bundle and resource bundle so that you can use them for error messages and/or localization.

  • Parsing an xml string into id-value pair format

    Hi,
    I am new in oracle BPEL.
    My requirement is that I need to parse an xml string containing tag name and coressponding value into an 'id -value' pair.
    For example-
    The input xml format is -
    <employee>
    <empid>12345</empid>
    <name>xyz</name>
    <city>London</city>
    </employee>
    The required xml format is-
    <employee>
    <item id="empid" value="12345"/>
    <item id="name" value="xyz"/>
    <item id="city" value="London"/>
    </employee>
    Please let me know if there is a work-around for this.
    Thanks

    Something like this (have not tested):
    <xsl:for-each select="//employee">
    <employee>
    <xsl:for-each select="./*">
    <item>
    <xsl:attribute name="id">
    <xsl:value-of select="name()"/>
    </xsl:attribute>
    <xsl:attribute name="value">
    <xsl:value-of select="text()"/>
    </xsl:attribute>
    </item>
    </xsl:for-each>
    </employee>
    </xsl:for-each>

  • Getting null value while parsing "XML String" with  encoding WINDOWS-1252.

    Hi,
    when I am converting the Follwoing "xml string " to Document, I am getting the "null" as a document value.
        String strXML =  "<?xml version="1.0" encoding="WINDOWS-1252"?>
                              <category name="SearchByAttributes" value="Search By Attributes">
                                <item name="ORDER_LINE_ID" description="Application Search Attributes" >
                                   <attribute name="Sequence" value="0001"/>
                                 </item>
                                </category>"      
    My "xml string" has the encoding vaule: WINDOWS-1252.
    I am using the following code to convert the "xml string" to Document. I am getting the Document values as a "null" while converting the above "string xml"
            String strXML = //my above string xml.
            DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
            docBuilderFactory.setIgnoringElementContentWhitespace(true);
            docBuilder = docBuilderFactory.newDocumentBuilder();
            doc = docBuilder.parse(new InputSource(new StringReader(strXML)));              
            System.out.println("doc value.."+doc)//I am getting null value for "doc".
    Can anyone help me to resolve the issue.

    Thagelapally wrote:
    I am coverting the below "XML string" to Document, once it is converted I am reading that Document,which have an "attribue" Element in.
      String strXML = "<?xml version="1.0" encoding="WINDOWS-1252"?>
    <category name="SearchByAttributes" value="Search By Attributes">
    <item name="ORDER_LINE_ID" description="Application Search Attributes" >
    <attribute name="Sequence" value="0001"/>
    </item>
    </category>" I am using the above code to read the Document. When run the code in "OC4J Server" and using Jdeveloper as an editor,I am able to perfectly read the "attribute" element in the document with out any problem.Println statement printing as I expected.
    System.out.println("Element Name..."+listOfAtt.getNodeName());
    //getting Element Name as...."attribute"(as expected)
    System.out.println("Element Attibrute list....."+elementAtt);
    //getting Element Attribute list as an...."oracle.xml.parser.v2.XMLAttrList@afe"But when run the same code(reading the same Document) in Tomcat and Eclipse,println satatement not printing as i expected.
    System.out.println("Element Name..."+listOfAtt.getNodeName());
    //getting Element Name as...."#text"(I am expecting output value "attribute" but it is printing "#text" which i don't know)
    System.out.println("Element Attibrute list....."+elementAtt);
    //getting Element Attribute list as an...."null"(I am expecting output value object reference but it is printing "null"
    (without the rest of the code, i'm guessing that) most likely you are grabbing the first child node of the item element. however, you are not accounting for some text nodes that are most likely in that list, like the whitespace between the item element and the attribute element. please go read some tutorials on xml, there are thousands of them out there, and they will answer all you initial questions much more efficiently than posting each step to the forums.

  • Update xml to replace value

    I have seen good example on how to use updateXML to update the value as the one below,
    but no luck on search on how to replace from one value to another.
    Does anyone have example on how to replace value using updateXML?
    Thanks,
    Luan
    insert into XML_CLOB values ( xmltype(
    '<student id="211">
    <personal idPer="2561">
    <firstName>John</firstName>
    <middleName>Michael</middleName>
    <lastName>Scott</lastName>
    <birthday>15-11-1984</birthday>
    <address>8600 Beverly Blvd.</address>
    <city>Los Angeles, CA.</city>
    <country>USA</country>
    </personal>
    <personal idPer="2561">
    <firstName>John</firstName>
    <middleName>Michael</middleName>
    <lastName>Scott</lastName>
    <birthday>15-11-1984</birthday>
    <address>8600 Beverly Blvd.</address>
    <city>Los Angeles, CA.</city>
    <country>USA</country>
    </personal>
    <personal idPer="2221">
    <firstName>John</firstName>
    <middleName>Michael</middleName>
    <lastName>Scott</lastName>
    <birthday>15-11-1984</birthday>
    <address>8600 Beverly Blvd.</address>
    <city>Los Angeles, CA.</city>
    <country>USA</country>
    </personal>
    </student>'));
    prompt 'select object_value from xml_clob';
    select object_value from xml_clob;
    prompt 'update XML_CLOBset object_value = updateXML( object_value,/student/personal/city/text(),New York City)where existsNode(object_value,/student[@id="211"]) = 1';
    update XML_CLOB
    set object_value = updateXML
    object_value,
    '/student/personal/city/text()',
    'New York City'
    where existsNode(object_value,'/student[@id="211"]') = 1;

    Sure, I meant to find/replace. In the real world example,
    I have an order with many items, but one item has typo missing a digit.
    I wanted to find that item and replace with new correct value in the xml.
    Order: 1234
    item: 9000292
    item: 9020777
    item: 9003833
    Let's say my third item "9003833" is not correct and I wanted to replace with new item "9003844". Hope that clear!
    here is an example that I am working with:
    I would like to replace firstName = "Luan" with "The World is Great" in my example below, and I want to replace only when it finds firstName = "Luan".
    drop table xml_clob
    create table xml_clob of xmltype;
    insert into XML_CLOB values ( xmltype(
    '<student id="211">
    <personal>
    <idPer>2561</idPer>
    <firstName>John</firstName>
    <middleName>Michael</middleName>
    <lastName>Scott</lastName>
    <birthday>15-11-1984</birthday>
    <address>8600 Beverly Blvd.</address>
    <city>Los Angeles, CA.</city>
    <country>USA</country>
    </personal>
    <personal>
    <idPer>2221</idPer>
    <firstName>Luan</firstName>
    <middleName>M</middleName>
    <lastName>Nguyen</lastName>
    <birthday>06-01-1977</birthday>
    <address>2100 Pine Street.</address>
    <city>Los Angeles, CA.</city>
    <country>USA</country>
    </personal>
    </student>'));
    select * from xml_clob
    -- This update statement does not correct. It didn't update the firstName value. I created a new "personal" tag and remove the previous "personal". I wanted to find("Luan") and replace("The World is Great").
    UPDATE xml_clob
    set object_value =
    UPDATEXML(object_value,
    '/student/personal[firstName="Luan"]/text()','The World is Great')
    -- Thanks,
    -- Luan

  • [svn:osmf:] 15983: Updating VideoQoSPluginMetadataSynthesizer to create comma separated string values for all of the available keys .

    Revision: 15983
    Revision: 15983
    Author:   [email protected]
    Date:     2010-05-10 04:47:46 -0700 (Mon, 10 May 2010)
    Log Message:
    Updating VideoQoSPluginMetadataSynthesizer to create comma separated string values for all of the available keys.
    Modified Paths:
        osmf/trunk/apps/samples/plugins/VideoQoSPlugin/src/org/osmf/qos/VideoQoSPluginMetadataSyn thesizer.as

    Rob:
    "but the sad thing is, that managers will most likely respond with a "This used to be fast in MSSQL, but now it isn't any more in Oracle. Oracle is so slow ...""
    On the bright side, it sounds like most of the database calls are implemented as stored procedures, so there is an opportunity to do it right (in Oracle terms) in the stored procedures.
    I did a similar conversion a while back, converting bad SQLServer procedures to good Oracle procedures. Everyone said "Oracle is much faster that SQLServer"
    John

  • [svn:fx-trunk] 20696: update build. properties values that are used for flex-sdk-description.xml.

    Revision: 20696
    Revision: 20696
    Author:   [email protected]
    Date:     2011-03-08 14:09:49 -0800 (Tue, 08 Mar 2011)
    Log Message:
    update build.properties values that are used for flex-sdk-description.xml. release.version = 4.5.1 release = Superhero
    QE notes: no
    Doc notes: no
    Bugs: no
    Reviewer: lauren
    Tests run: no
    Is noteworthy for integration: most likely FB will have to be aware of this
    Modified Paths:
        flex/sdk/trunk/build.properties

    Thats good news.

  • Update XML data stored in CLOB Column

    Hi All,
    i am new to Oracle and new to SQL
    i am trying to update XML data stored in CLOB cloumn,data is stored with the follwoing format
    <attrs><attr name="name"><string>Schade</string></attr></attrs>
    i am using the following query for updating the value
    UPDATE PRODUCT p SET ATTRIBUTES_nl_nl=UPDATEXML(XMLTYPE.createXML(ATTRIBUTES_nl_nl),'/attrs/attr[@name="name"]/string/text()','Schade').getClobVal() WHERE p.sku='000000000000040576_200911-5010057'
    this query is working fine but it changing the data to the following format
    <attrs><attr name="name">Schade</attr></attrs>
    some how it is ommiting the <string> tag from it, i am unable to figure it out whats the reason.
    any help in this regard will b e much appriciated
    Thanks in Advance
    -Umesh

    Hi,
    You should have created your own thread for this, and included database version.
    This works for me on 11.2.0.2 and 10.2.0.5 :
    SQL> create table t_org ( xml_clob clob );
    Table created
    SQL>
    SQL> insert into t_org
      2  values(
      3  '<Message>
      4  <Entity>
      5  <ASSIGNMENT>
      6  <OAVendorLocation> </OAVendorLocation>
      7  <Vendorid>1</Vendorid>
      8  </ASSIGNMENT>
      9  </Entity>
    10  </Message>'
    11  );
    1 row inserted
    SQL> commit;
    Commit complete
    SQL> select '*' ||
      2         extractvalue(xmltype(xml_clob),'/Message/Entity/ASSIGNMENT/OAVendorLocation')
      3         || '*' as result
      4  from t_org;
    RESULT
    SQL> update t_org set xml_clob =
      2  updatexml(xmltype(xml_clob),
      3  '/Message/Entity/ASSIGNMENT/OAVendorLocation/text()','LONDON').getClobVal()
      4  ;
    1 row updated
    SQL> select '*' ||
      2         extractvalue(xmltype(xml_clob),'/Message/Entity/ASSIGNMENT/OAVendorLocation')
      3         || '*' as result
      4  from t_org;
    RESULT
    *LONDON*
    Does the OAVendorLocation really have a whitespace value?
    If not then it's expected behaviour, you're trying to update a text() node that doesn't exist. In this case, the solution is to use appendChildXML to create the text() node, or update the whole element.
    Is it your real document? Do you actually have some namespaces?

  • How to update xml file

    hai ....this is anitha.
    iam having some problem regarding the updation of the xml file. i can update the Node Values, its Attributes, its Childnodes etc.. successfully, but only once. first time it is working fine. but when again iam trying to update other nodes, the previously updated values r lost.. iam sending the code also.
    pls give the reply asp.
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.NamedNodeMap;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    import org.w3c.dom.DOMException;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.FileInputStream;
    import javax.servlet.http.*;
    import java.util.ArrayList;
    import java.util.Iterator;
    //import javax.servlet.http.HttpSession;
    public class empXml
         String xmlFilePath="";
         File xmlFile=null;
         FileWriter fout=null;
         Element emp;
         Element empName;
         Element empDesig;
         Element empDiv;
         //Element newNode;
    public void createXml(ArrayList arr)throws IOException, DOMException
         try
              for(Iterator itr=arr.iterator();itr.hasNext();)
              System.out.println(itr.next());
              //System.out.println((String)(itr.next()));
              xmlFile=new File("D:\\Tomcat 4.0\\webapps\\news\\jsp\\employee.xml");
              System.out.println(" Employees Information ");
                        fout = new FileWriter(xmlFile);     
                        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                        DocumentBuilder docBuilder = dbf.newDocumentBuilder();
                        Document doc = docBuilder.getDOMImplementation().
                        createDocument("", "employee", null);
                        Element root = doc.getDocumentElement();
                        emp = doc.createElement("emp");
                        empName = doc.createElement("empname");
                             empName.appendChild(doc.createTextNode(arr.get(0).toString()));
                             emp.appendChild(empName);
                        empDesig = doc.createElement("empdesig");
                             empDesig.appendChild(doc.createTextNode(arr.get(1).toString()));
                             emp.appendChild(empDesig);
                        empDiv = doc.createElement("empdiv");
                             empDiv.appendChild(doc.createTextNode(arr.get(2).toString()));
                             emp.appendChild(empDiv);
                        root.appendChild(emp);           
              DomTreeBuilder.printDomTree(doc,fout); // Builds The Dom Tree
              System.out.println("Employees XML File is Successfully Generated");
         }catch (Exception e)
         System.err.println("Error while Generating file"+ e.getMessage());
         finally
         fout.close();
    }//end of createXml
    }//end of class createNewsXml
    class DomTreeBuilder
    public static void printDomTree(Node node,FileWriter fout) throws IOException
              int type = node.getNodeType();
              switch (type)
              // print the document element
              case Node.DOCUMENT_NODE:
                   fout.write("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
                   printDomTree(((Document)node).getDocumentElement(),fout);
                   break;
              // print element and any attributes
              case Node.ELEMENT_NODE:
                   fout.write("<");
                   fout.write(node.getNodeName());
                   if (node.hasAttributes())
                        NamedNodeMap attrs = node.getAttributes();
                        for (int i = 0; i < attrs.getLength(); i++)
                        printDomTree(attrs.item(i),fout);
                   fout.write(">");
              if (node.hasChildNodes())
                        NodeList children = node.getChildNodes();
                        for (int i = 0; i < children.getLength(); i++)
                        printDomTree(children.item(i),fout);
              break;
              // Print attribute nodes
              case Node.ATTRIBUTE_NODE:
                   fout.write(" " + node.getNodeName() + "=\"");
                   fout.write(node.getNodeValue());
                   if (node.hasChildNodes())
                        NodeList children = node.getChildNodes();
                        for (int i = 0; i < children.getLength(); i++)
                        printDomTree(children.item(i),fout);
                   fout.write("\"");
              break;
              // handle entity reference nodes
              case Node.ENTITY_REFERENCE_NODE:
                   fout.write("&");
                   fout.write(node.getNodeName());
                   fout.write(";");
                   break;
              // print cdata sections
              case Node.CDATA_SECTION_NODE:
                   fout.write("<![CDATA[");
                   fout.write(node.getNodeValue());
                   fout.write("]]>");
                   break;
              // print text
              case Node.TEXT_NODE:
                   fout.write(node.getNodeValue());
                   break;
              // print comment
              case Node.COMMENT_NODE:
                   fout.write("<!--");
                   fout.write(node.getNodeValue());
                   fout.write("-->");
                   break;
              // print processing instruction
              case Node.PROCESSING_INSTRUCTION_NODE:
                   fout.write("<?");
                   fout.write(node.getNodeName());
                   String data = node.getNodeValue();
                   fout.write(" ");
                   fout.write(data);
                   fout.write("?>");
                   break;
         } // end of Switch
         if (type == Node.ELEMENT_NODE)
                   fout.write("</");
                   fout.write(node.getNodeName());
                   fout.write('>');
    } // printDomTree(Node)
    } // End of DomBuilder Class
    waiting for the reply soon.
    thanks and regards,
    anitha

    Hi,
    There was no problem in this code. When I executed it worked well, anyway I changed slightly because to add more than one elements. I posted the entire code here:
    Regards
    Baskar
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.NamedNodeMap;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    import org.w3c.dom.DOMException;
    import java.io.File;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.StringTokenizer;
    public class empXml {
         String xmlFilePath = "";
         File xmlFile = null;
         FileWriter fout = null;
         Element emp;
         Element empName;
         Element empDesig;
         Element empDiv;
         // Element newNode;
         public static void main(String[] args) {
              try {
                   empXml x = new empXml();
                   ArrayList ar = new ArrayList();
                   ar.add("baskar,SE,Hitachi");
                   ar.add("krish,SE,Hitachi");
                   ar.add("preet,SE,Hitachi");
                   ar.add("Jan,SE,Hitachi");
                   ar.add("Sam,SE,Hitachi");
                   x.createXml(ar);
              } catch (Exception e) {
                   e.printStackTrace();
         public void createXml(ArrayList arr) throws IOException, DOMException {
              String empl[] = new String[arr.size()];
              arr.toArray(empl);
              try {
                   Iterator itr = arr.iterator();
                   xmlFile = new File("employee.xml");
                   System.out.println(" Employees Information ");
                   fout = new FileWriter(xmlFile);
                   DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                   DocumentBuilder docBuilder = dbf.newDocumentBuilder();
                   Document doc = docBuilder.getDOMImplementation().createDocument("",
                             "employee", null);
                   Element root = doc.getDocumentElement();
                   for (int i = 0; i < empl.length; i++) {
                        StringTokenizer st = new StringTokenizer(empl, ",");
                        emp = doc.createElement("emp");
                        empName = doc.createElement("empname");
                        empName.appendChild(doc.createTextNode(st.nextToken()));
                        emp.appendChild(empName);
                        empDesig = doc.createElement("empdesig");
                        empDesig.appendChild(doc.createTextNode(st.nextToken()));
                        emp.appendChild(empDesig);
                        empDiv = doc.createElement("empdiv");
                        empDiv.appendChild(doc.createTextNode(st.nextToken()));
                        emp.appendChild(empDiv);
                        root.appendChild(emp);
                   DomTreeBuilder.printDomTree(doc, fout); // Builds The Dom Tree
                   System.out.println("Employees XML File is Successfully Generated");
              } catch (Exception e) {
                   e.printStackTrace();
              } finally {
                   fout.close();
         }// end of createXml
    }// end of class createNewsXml
    class DomTreeBuilder {
         public static void printDomTree(Node node, FileWriter fout)
                   throws IOException {
              int type = node.getNodeType();
              switch (type) {
              // print the document element
              case Node.DOCUMENT_NODE: {
                   fout.write("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
                   printDomTree(((Document) node).getDocumentElement(), fout);
                   break;
              // print element and any attributes
              case Node.ELEMENT_NODE: {
                   fout.write("<");
                   fout.write(node.getNodeName());
                   if (node.hasAttributes()) {
                        NamedNodeMap attrs = node.getAttributes();
                        for (int i = 0; i < attrs.getLength(); i++)
                             printDomTree(attrs.item(i), fout);
                   fout.write(">");
                   if (node.hasChildNodes()) {
                        NodeList children = node.getChildNodes();
                        for (int i = 0; i < children.getLength(); i++)
                             printDomTree(children.item(i), fout);
                   break;
              // Print attribute nodes
              case Node.ATTRIBUTE_NODE: {
                   fout.write(" " + node.getNodeName() + "=\"");
                   fout.write(node.getNodeValue());
                   if (node.hasChildNodes()) {
                        NodeList children = node.getChildNodes();
                        for (int i = 0; i < children.getLength(); i++)
                             printDomTree(children.item(i), fout);
                   fout.write("\"");
                   break;
              // handle entity reference nodes
              case Node.ENTITY_REFERENCE_NODE: {
                   fout.write("&");
                   fout.write(node.getNodeName());
                   fout.write(";");
                   break;
              // print cdata sections
              case Node.CDATA_SECTION_NODE: {
                   fout.write("<![CDATA[");
                   fout.write(node.getNodeValue());
                   fout.write("]]>");
                   break;
              // print text
              case Node.TEXT_NODE: {
                   fout.write(node.getNodeValue());
                   break;
              // print comment
              case Node.COMMENT_NODE: {
                   fout.write("<!--");
                   fout.write(node.getNodeValue());
                   fout.write("-->");
                   break;
              // print processing instruction
              case Node.PROCESSING_INSTRUCTION_NODE: {
                   fout.write("<?");
                   fout.write(node.getNodeName());
                   String data = node.getNodeValue();
                        fout.write(" ");
                        fout.write(data);
                   fout.write("?>");
                   break;
              } // end of Switch
              if (type == Node.ELEMENT_NODE) {
                   fout.write("</");
                   fout.write(node.getNodeName());
                   fout.write('>');
         } // printDomTree(Node)
    } // End of DomBuilder Class

  • HOw to update XML file residing in DAM by component JSP in run-time?

    i have made a component which reads xml file residing in DAM.
    Content Author can fill some values in dialog of this component, as soon as author provide the values,i have to update these values in XML file and component reloadsby reading the updated xml file.
    i am trying to achieve this by making object of XML file and giving it's path., but i ma unable to access the XML file.
    Can anyone help me out to how to update XML file by component JSP in run-time?

    Now the changed data must be exported back into the XML file, meaning that the content of certain elements must be updated. How can this be done with XSLT?
    XSLT approach:  check these online tutorial
    http://www.xml.com/pub/a/2000/08/02/xslt/index.html
    http://www.xml.com/pub/a/2000/06/07/transforming/index.html
    ABAP approach:
    for example you have the xml (original) in a string called say xml_out .
    data: l_xml  type ref to cl_xml_document ,
            node type ref to if_ixml_node  .
    create object l_xml.
    call method l_xml->parse_string
      exporting
        stream = xml_out.
    node = l_xml->find_node(
        name   = 'IDENTITY'
       ROOT   = ROOT
    l_xml->set_attribute(
        name    = 'Name'
        value   = 'Charles'
        node    = node
    (the above example reads the element IDENTITY and sets attribute name/value to the same)
    like wise you can add new elements starting from IDENTITY using various methods available in class CL_XML_DOCUMENT
    so how do I access the XML file in order to update it?
    you have already read this XML into a ABAP variable right?
    Sorry couldnt understand your whole process, why do you need to read local XML file?
    Raja

Maybe you are looking for

  • ITunes crashing when trying to delete a playlist

    Hi all, Just got a new MacBook Pro 15" that I migrated all of my stuff from my old 15" MacBook Pro from mid-2007 to, not by direct connection but by Time Machine. iTunes is generally being uncooperative and it is consistently crashing in two ways: #1

  • Can only print in Black and White

    Since installing Mavericks have had to reinstall HP inkjet 960c driver. It now works but with only basic options in Print Dialogue box. ONLY PRINTS IN BLACK AND WHITE. Printer features option only has dpi options.

  • [network] SkipStone (a lightweight browser)

    PKGBUILD: # Contributor: Shahar Weiss <[email protected]> pkgname=skipstone pkgver=0.9.3 pkgrel=1 pkgdesc="SkipStone is a Gtk+ Web Browser that embeds Mozilla's rendering component Gecko. It aims to be light and fast with few dependencies." url="http

  • Can't adjust input level when using usb microphone

    Hey guys, I'm very familiar with this version of Garageband, and just started using a Blue Snowball USB mic. When I plug it in and set the drivers accordingly, the input volume slider is greyed out, making it inaccessible. Is there a trick to being a

  • Usb connection printer, router, two computers on LAN?

    I recently got a TP-Link WDR4300 (N750) router with two usb jacks. I have a HP OfficeJet 5610 printer's usb output plugged into the router usb jack. On the network I have an Imac 10.4.11 and a Macbook 10.5.xx. The Imac recognizes the printer and will