XPath to Update XML document
Using XPath I can read a particular node of an XML document through JAVA program. However, is it possible to Update the value of the node, just read from XML doc, using XPath expressions ?
That is blatant misinformation. Xpath is used all the time to select nodes from a document. The returned nodes are references to parts of the document, therefore this it should be easy to update any part of it having retrieved the required nodes.
Similar Messages
-
Hi guys, I need again your help.
I have many xml documents and I need create a class that "search" data at this xml documents. What I can do this!?!?
For example, I wanna get the Paul ages in the age.xml document!!!!! I wanna create a method like this:
SearchXmlfile search = new SearchXmlFile();
String result = search.get("/person@age[person@attribute = 'paul']"); //I pass the xpath like parameter
Someone know What I can do this?!!?
Just another question. When I create a transformer I set the Source and Result "Objects" (SAX, DOM or Stream). And where i set the xsl file?!!? I am reading the jwsdp tutorial and I don't understand where I configure the xsl file transformer to the transformer object!!!!
Thanks Again.
Giscard.1. For selecting nodes with an XPath expression parse with the JDom parser and select nodes with the XPath class.
http://www.jdom.org/
2. Set the stylesheet in the Transformer.
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(new File("c:/input.xml"));
TransformerFactory tFactory =
TransformerFactory.newInstance();
StreamSource stylesource = new StreamSource(stylesheet);//Set the Stylesheet
Transformer transformer = tFactory.newTransformer(stylesource);
DOMSource source = new DOMSource(document);
StreamResult result = new StreamResult(System.out);
transformer.transform(source, result); -
After creation of a XML document through DOM is it possible to update the same XML document with new tags
Thanks
Sasankas, it is possible to xmldocument with new tags.for example u need to create a new node of requirement and import that node to required document and use replace to update.
-
Updating XML document using DOM only updates in memory
I am trying to update an element value but it only gets updated in the memory and displayed. It does not physically change the xml document when I look after running the program.
Here is the code I am trying to run :
Please let me know what I am doing wrong.
static private Document findReplace(Document document, String elementName,
String valueToFind, String valueToReplace)
int i;
int k;
NodeList children;
Element docRoot= document.getDocumentElement(); // get root
NodeList elements = docRoot.getElementsByTagName(elementName);
if (elements !=null)
for (i=0;i<elements.getLength(); i++)
if (elements.item(i).hasChildNodes())
children = elements.item(i).getChildNodes();
for(k=0;k<children.getLength(); k++)
if (children.item(k).getNodeType() ==
org.w3c.dom.Node.TEXT_NODE){
if(children.item(k).getNodeValue().equals(valueToFind))
children.item(k).setNodeValue(valueToReplace);
Thanks !Document document;
TransformerFactory tFactory =
TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
DOMSource source = new DOMSource(document);
StreamResult result = new StreamResult(new File
(c:/output/outputXml.xml));
transformer.transform(source, result); -
UCCX XPath on Get XML Document Data Step always returns null
Hello,
Can someone tell whats wrong with my XPath, because it always returns null. I have tried different variations and nothing. I'm using UCCX 7.0
XML
<?xml version="1.0" encoding="utf-8" ?>
<GetManagersResult xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.labdomain.com/">
<ClaimManagersList>
<X_CLAIM_MANAGER>
<ClaimManagerUserName>test</ClaimManagerUserName>
</X_CLAIM_MANAGER>
</ClaimManagersList>
</GetManagersResult>
XPATH
"/descendant::GetManagersResult/child::ClaimManagersList/child::X_CLAIM_MANAGER/child::ClaimManagerUserName"
During debug, this is the value of the xml document when it reaches the Get XML Document Data step:
TEXT[<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<GetManagersResult xmlns=\"http://www.labdomain.com/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\r\n <ClaimManagersList>\r\n <X_CLAIM_MANAGER>\r\n <ClaimManagerUserName>test</ClaimManagerUserName>\r\n </X_CLAIM_MANAGER>\r\n </ClaimManagersList>\r\n</GetManagersResult>]It's your XML namespace in the root element.
First off, I have never seen the CRS Editor play nice when XML namespaces are involved.
Secondly, with your namespace in place, not even a generic xpath expression tester can find your data. See attachements.
I think that if you find a way to either: not send, or remove the namespace from your document, your xpath expression will work.
With Namespaces
Without Namespaces -
Xpath and Get XML Document Data
Good Morning,
I have just recently gotten involved in a project that requires communicating with some web services (axis2). We have existing scripts that handle this already, but they were built when we weren't on axis2 so now the XML output from the web service call is slightly different and i am no longer able to use the same xpath statement in the Get XML Document Data step.
I am receiving either null values or a prefix namespace error. I am new to xpath and have been reading as best i can from http://www.w3schools.com/xpath/ to try and understand how to write my statements to pull out the data i want correctly.
I have read that sometimes the editor has problems if the XML contains namespace declarations, etc.
Below is an example XML output where I'd like to be able to read the value in the ax211:success. My xpath gets prefix namespace errors as it doesn't recognize ax211.
Xpath: /descendant::ns:validateCertificationResponse/child::ns:return/child::ax211:success
Perhaps my xpath statement is just incorrect and wouldn't retrieve what i expect it to....
Any advice is appreciated.
Thanks,
KevinHi,
well, it appears that text() is automatically appended to the XPath query for some reason in UCCX, this is why you actually see the text node within the ax211:success element. This //*[local-name()="success"] select the whole node, not its first child (which is actually the first element, which also happens to be a text).
Anyway,
// - anywhere
* - any node
And within this "everything" you actually search with the condition within the angular brackets.
G. -
Storing and Updating XML-documents in interMedia
Hi,
I have an idea to do the following with the help of interMedia.
We work with 8.1.7 at the moment.
Is this a feasable or not???
1) Receive lots and lotts of XML-messages.
2) Store each one of all these XML-messages in a CLOB (maybe divide the XML-message into a few smaler parts for Read only and for Update)
3) Search these XML-messages.
4) Display the result in a list.
5) Present one of these XML-message in HTML.
6) Manipulate it throug HTML and uppdate the original XML-message in its CLOB.
Is this possible or not!
Please help me in answering this or give me directions to where i can find an answer!
RolandHi,
http://www.dom4j.org/
Hope this helps
Jakub Krecicki -
Clearing contents of a field when updating using an XML document.
When trying to update a document using XML and the DI API, how can you clear the contents of a field in the document? This in particularly is a nvarchar field.
>
Michaela Pfeifer wrote:
> Hi,
>
> we are using the XIF-Adapter to receive business partners from a third party system. The third party system send the data in xml via http.
>
> My question is now. Is there any possibility to do a mapping of the data before processing. As i understand I can use the LSMW to do the mapping when receiving iDoc-Files. Is that also possible for XML?
>
> Thanks
> Michaela
Hi Michael,
I have to migrate third party data in XML format, pls provide me the configuration guide regarding that.
Thanks a lot.
#shobhit(DOT)techy(AT)(gmail).com -
Updating a XML document with a processing instruction
Greetings Guru's
I have a fully functional XML database solution for our new system. The only thing left is for me to update a xml document in the database with a processing instruction to find the style sheet (JAXB strips it out when the XML must go back into the database).
I can update complete nodes and node elements in the xml document using updateXML in a regular update statement, but I do not know how to add the following processing instruction to my documents.
<?xml-stylesheet type="text/xsl" href="/RASWEB/JIT_REPORT.xslt"?>
[pre]
Thanks in advance
DerrickSQL> var xmltext varchar2(4000)
SQL> --
SQL> begin
2 :xmlText := '<Hello>World</Hello>';
3 end;
4 /
PL/SQL procedure successfully completed.
SQL> drop table t
2 /
drop table t
ERROR at line 1:
ORA-00942: table or view does not exist
SQL> create table t of xmltype
2 /
Table created.
SQL> set long 10000
SQL> --
SQL> insert into t values (xmltype(:xmltext))
2 /
1 row created.
SQL> select *
2 from t
3 /
SYS_NC_ROWINFO$
<Hello>World</Hello>
SQL> update t set object_value = updateXML
2 (
3 object_value,
4 '/',
5 xmlconcat
6 (
7 xmlpi("xml-stylesheet",'type="text/xsl" href="/RASWEB/JIT_REPORT.xslt"'),
8 object_value
9 )
10 )
11 /
1 row updated.
SQL> select * from t
2 /
SYS_NC_ROWINFO$
<?xml-stylesheet type="text/xsl" href="/RASWEB/JIT_REPORT.xslt"?>
<Hello>World</Hello>
SQL> -
Hello
I currently have a project where the client has requested to have the ability to update the text fields inside the project at a later date.
This is due to the nature of the content changing rather rapidly, i would like to set this up so the client can manage this them selfs.
What would the best way to do this be?
I'm thinking XML, an external XML sheet were by Captivate imports the text from this XML sheet and then displays it within the specific text fields contained within the captivate output.
This way the client would just update the external XML document(cut and paste the text in) and then the text would be dynamically updated in the published Captivate document.
any help would be amazing !
Thanks in advance
NickHi Lieve
But isn't this thread more about an end user having an ability to change text after the Captivate has been published and delivered? I could see where that might be useful if making changes then publishing to create a new output. But I'm interpreting that the situation here is that a Captivate project has been published and delivered, and some mechanism is desired that allows the recipient to modify an external XML file to influence changes in the already compiled Captivate output.
Cheers... Rick -
Create xml document by xpath in java
as i know, i can navigate existing xml document by xpath in java, i wonder if i can create a xml document framework by xpath in java?
something like:
Document doc = someobject.create(xpath expression);
then i can use DOM to fill the framework?
ThanksPlease refer
http://www.packtpub.com/article/xpath-support-in-oracle-jdeveloper-xdk-11g -
I would like to parse an xml document using xpath, see:
http://www.onjava.com/pub/a/onjava/2005/01/12/xpath.html
however, in the documentation (in the link above), it states that I need J2SE 5.0.
Currently, I have:
$ java -version
java version "1.5.0_11"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_11-b03)
Java HotSpot(TM) Client VM (build 1.5.0_11-b03, mixed mode, sharing)
Does that mean that I really have to install J2SE 5.0 in order to use J2SE 5.0's XPath support? Does anybody know anything about getting started with XPath, and whether I can just use my existing version of Java? I've never used XPath.
For more documentation, one can view:
http://www.w3.org/TR/xpath20/
Thank you.I have copied the code for the xpath tutorial on
http://www.onjava.com/pub/a/onjava/2005/01/12/xpath.html
exactly as it is on the tutorial, and imported the correct jars (I think).
But still my code is giving lots of errors!
Granted its my first shot but anyway here's the code and the errors...
package test;
import org.jdom.xpath.*;
import java.io.*;
import javax.xml.xpath.*;
public class XPath {
public static void main (String [] args){
XPathFactory factory = XPathFactory.newInstance();
XPath xPath=factory.newXPath();
XPathExpression xPathExpression=xPath.compile("/catalog/journal/article[@date='January-2004']/title");
File xmlDocument = new File("/home/myrmen/workspace/Testing/test/catalog.xml");
//FileInputStream fis = new FileInputStream(xmldocument);
InputSource inputSource = new InputSource(new FileInputStream(xmlDocument));
String title = xPathExpression.evaluate(inputSource);
String publisher = xPath.evaluate("/catalog/journal/@publisher", inputSource);
String expression="/catalog/journal/article";
NodeSet nodes = (NodeSet) xPath.evaluate(expression, inputSource, XPathConstants.NODESET);
NodeList nodeList=(NodeList)nodes;
SAXBuilder saxBuilder = new SAXBuilder("org.apache.xerces.parsers.SAXParser");
org.jdom.Document jdomDocument = saxBuilder.build(xmlDocument);
org.jdom.Attribute levelNode = (org.jdom.Attribute)(XPath.selectSingleNode(jdomDocument,"/catalog//journal[@title='JavaTechnology']" + "//article[@date='January-2004']/@level"));
levelNode.setValue("Intermediate");
org.jdom.Element titleNode = (org.jdom.Element) XPath.selectSingleNode( jdomDocument,"/catalog//journal//article[@date='January-2004']/title");
titleNode.setText("Service Oriented Architecture Frameworks");
java.util.List nodeList = XPath.selectNodes(jdomDocument,"/catalog//journal[@title='Java Technology']//article");
Iterator iter=nodeList.iterator();
while(iter.hasNext()) {
org.jdom.Element element = (org.jdom.Element) iter.next();
element.setAttribute("section", "Java Technology");
XPath xpath = XPath.newInstance("/catalog//journal:journal//article/@journal:level");
xpath.addNamespace("journal", "http://www.w3.org/2001/XMLSchema-Instance");
levelNode = (org.jdom.Attribute) xpath.selectSingleNode(jdomDocument);
levelNode.setValue("Advanced");
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Type mismatch: cannot convert from XPath to XPath
The method compile(String) is undefined for the type XPath
InputSource cannot be resolved to a type
InputSource cannot be resolved to a type
NodeSet cannot be resolved to a type
NodeSet cannot be resolved to a type
NodeList cannot be resolved to a type
NodeList cannot be resolved to a type
SAXBuilder cannot be resolved to a type
SAXBuilder cannot be resolved to a type
The method selectSingleNode(Document, String) is undefined for the type XPath
The method selectSingleNode(Document, String) is undefined for the type XPath
Duplicate local variable nodeList
The method selectNodes(Document, String) is undefined for the type XPath
Iterator cannot be resolved to a type
The method newInstance(String) is undefined for the type XPath
The method addNamespace(String, String) is undefined for the type XPath
The method selectSingleNode(Document) is undefined for the type XPath
at test.XPath.main(XPath.java:12) -
Database table updation with XML Document data
import java.io.*;
import java.lang.*;
import java.net.URL;
import java.sql.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import oracle.xml.sql.dml.OracleXMLSave;
import org.w3c.dom.Document;
public class updateXMLData
public static void main( String argv[] ) throws SQLException,Exception
String tabName = "emp";
Connection conn = null;
String xmlString;
Document doc;
URL filename;
try
//init a JDBC connection using Oracle's JDBC Drivers
String host = "maple"; // change,these won't work
String port = "1521";
String sid = "PBSI";
String s1 = "jdbc:oracle:thin:@" + host + ":" + port + ":" + sid;
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
conn = DriverManager.getConnection( s1,"scott","tiger");
// Instructions for updating the database rows from XML Document
OracleXMLSave sav = new OracleXMLSave(conn,tabName);
filename = sav.getURL("pbsiempupd.xml");
sav.setRowTag("EMP");
String[] tempArr = new String[2];
tempArr[0]="EMPNO";
tempArr[1]="ENAME";
sav.setKeyColumnList(tempArr);
sav.setUpdateColumnList(tempArr);
int noRows = sav.updateXML(filename);
System.out.println("No of rows updated : " + noRows);
catch (SQLException se)
System.out.println("An SQL exception has occured ");
System.out.println("The error code is : " + se.getErrorCode());
System.out.println("The SQL State is : " + se.getSQLState());
System.out.println("The message is : " + se.getMessage());
catch (Exception e)
System.out.println("Unknown exception has occured");
System.out.println("The class is : "+ e.getClass());
System.out.println("The message is : "+e.getMessage());
finally
if (conn != null) conn.close();
The input XML Document is given below :- in 'pbsiempupd.xml'
<?xml version="1.0"?>
<ROWSET>
<EMP>
<EMPNO>8888</EMPNO>
<ENAME>RAO THOTAKURA</ENAME>
</EMP>
<EMP>
<EMPNO>9999</EMPNO>
<ENAME>BAVA MANI</ENAME>
</EMP>
<EMP>
<EMPNO>7777</EMPNO>
<ENAME>SRINIVAS M</ENAME>
</EMP>
</ROWSET>
After executing this class with 'java updataXMLData' I'm getting following runtime error message :-
Unknown exception has occured
The class is : class oracle.xml.sql.OracleXMLSQLException
The message is : Exception 'java.sql.SQLException:Missing IN or OUT parameter at index:: 1'
encountered during processing ROW element 0All prior XML row changes were rolled back.
in the XML document.
Please anybody could explain how to solve it.
Thanks
Sambasivarao ThotakuraSee my reply to your other question. thanks.
-
XPath query on multiple namespace XML document
Hi,
I am trying to locate an element in a WordML XML document using XPath.
The structure looks like:
<w:body>
<wx:sect>
<aml:annotation aml:id="0" w:type="Word.Bookmark.Start" w:name="DOC0000966"/>
...So I use the following expression "/wordDocument//body/sect" wich gives me a list with the <w:sect> nodes.
Then I search for "annotation[@type='Word.Bookmark.Start']" starting from each <w:sect> node. This yields the <aml:annotation> elem.
So far so good.
Now I have to handle a second case as well.
<w:body>
<wx:sect>
<w:p>
<aml:annotation aml:id="0" w:type="Word.Bookmark.Start" w:name="DOC0000966"/>
...As you can see the <aml:annotation> is nested inside a <w:p> elem.
My intention was to use the expression "//annotation[@type='Word.Bookmark.Start']"to handle both cases, but this expression does not match neither.
I have tried several different alternatives with expressions and NamingContext implementations, none working.
What am I missing?
Thanks in advance,
Mariano.Hello,
I decided to remove all namespaces and prefixes from the XML document and now the expression works.
I have chaned the following:
DocumentBuilderFactory is now namespace aware (it isn't by default).
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
builderFactory.setNamespaceAware(true);I picked this NamespaceContext implementation from JAXP 1.4 samples and mapped all prefixes and namespaces coming inside the XML.
NamespaceContextImpl ns = new NamespaceContextImpl();
ns.bindPrefixToNamespaceURI("aml", "http://schemas.microsoft.com/aml/2001/core");
ns.bindPrefixToNamespaceURI("dt", "uuid:C2F41010-65B3-11d1-A29F-00AA00C1488");
ns.bindPrefixToNamespaceURI("o", "urn:schemas-microsoft-com:office:office");
ns.bindPrefixToNamespaceURI("sl", "http://schemas.microsoft.com/schemaLibrary/2003/core");
ns.bindPrefixToNamespaceURI("v", "urn:schemas-microsoft-com:vml");
ns.bindPrefixToNamespaceURI("w", "http://schemas.microsoft.com/office/word/2003/wordml");
ns.bindPrefixToNamespaceURI("w10", "urn:schemas-microsoft-com:office:word");
ns.bindPrefixToNamespaceURI("wx", "http://schemas.microsoft.com/office/word/2003/auxHint");
XPathFactory xpathFactory = XPathFactory.newInstance();
XPath xpath = xpathFactory.newXPath();
xpath.setNamespaceContext(ns);Finally, I prefixed all elements in xpath expressions.
"//aml:annotation[@w:type='Word.Bookmark.Start']"Happier now,
Mariano. -
Validate and update a XML document with rules
Hi,
In my project work, I am thinking about using oracle rules BRMS (business rule management system) to validate certain rules on xml document.
Since I am new to the oracle rules, I want to know the feasibility of doing this with oracle rules.
I have a specific question...
I have XML documents that are in different schema versions. these schema are fixed but can add them in future as well.
I have two things to do:
1. transform a given XML document (in a one version) to another version
2. Validate the new XML document against the rules defined in the oracle business rules.
1.I can do the 1st task using XSLT transformation. But there is one challenge. Assume that there are new tags are added in the target schema compared to the source schema of the XML document.
If there are optional tags to be added, I want to know if oracle rules can be used for that. Because I want to make these things done without changing the code (java) or the application internals.
2. I have few questions on the 2nd issue. They are:
a) can I create rules in oracle BRMS based on target schemas. (or to all of them. If so, what needs to be done if I add a new schema in future. How to update the rules?)
b) is it possible to group the rules created above in oracle BRMS.
Lets say
R1, R2 rules are created against schema1 (version 1)
R3, R4, R5 rules are created against schema2 (version 2)
R6, R7 rules are created against schema3(version 3)
Can I create group R1, R2 and R6 rules in to a one group (G1) and R1, R2 and R7 rules in to another group (G2).
What are the APIs available in oracle BRMS to retrieve above defined groups at run time? (because business user can define any rules, ad group them at run time)
Once I have the groups, How can I validate a XML document against a group created above? What are the APIs available for this.
c) is it possible to add/update/delete tags to a XML document based on rules in oracle BRMS? if so, how?
appreciate your valuable feedback on this..Hi Hareendra,
I think you should post your question in this other forum:
Forum Home » SOA & Process Management » SOA Suite
Oracle Business Rules is a component used in SOA Suite
Regards!
Jorge
Maybe you are looking for
-
Closed port for torrent with no iptables.rules
I have a home system with internet connection over a router. Firewall in the router seems to be disabled. I had installed guarddog and selected all the protocols that I need. There is no iptables in deamons line of rc.conf nor there is any iptables.r
-
How to delete multiple contacts
How to delete multiple contacts?
-
Problems with a Wacom Cintiq tablet after upgrade to Yosemite
I have a 15-in MacBook Pro Late-2013 Retina with 2.6GHz i7 Processor, 16GB RAM. I recently upgraded to Yosemite, 10.10.2, and then reinstalled my drivers for my Wacom Cintiq 12WX Tablet. Now, startup takes 10-15 seconds longer than before - not a h
-
Function module to get the configuration of Individual objects
Hi all, Is there is any std function module to get the data of individual object configuration. In table COM_TA_R3_ID, I can able to get the PRODUCT_GUID (for material and serial number) and I dont know how to get the configuration of the product by
-
How to clean the inside of the MagSafe port? It is dirty.
How to clean the inside of the MagSafe port? It is dirty.