How to Add namespace to all elements in a xml document
Hi,
I am trying to read an xml file that does not have any namespace definitions. I have been able to create another schema in which i specify the namespace defination as shown below.
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://TargetNamespace.com/AckPaymentFile_PL" targetNamespace="http://TargetNamespace.com/AckPaymentFile_PL" xmlns:nxsd="http://xmlns.oracle.com/pcbpel/nxsd" nxsd:version="DTD" elementFormDefault="qualified" attributeFormDefault="unqualified">
<include schemaLocation="PM_XML_FILE_ACK_SCHEMA_NO_NAMESPACE.xsd"/>
</xs:schema>
Once i do it, i am able to see the namespace has been assigned to the root element. I am looking for a way to assign the namespace and prefix tag to all elements in the xml document. If i don't i am unable to access any part of the xml document, keep getting please verify if xpath is correct.
Thanks
Sridhar
Hello,
Once you've answered all the above.
If you can run xpath that supports functions against the xml, the expression:
count(//phone)Otherwise, without leaving SQL:
select count(*) from
xmltable('//phone' passing
-- Your XML goes here, could be a table column with type XMLTYPE.
xmltype('<person><phone>123-456-7890</phone><phone>098-765-4321</phone></person>')
columns phone varchar2(24 char) path '/phone'
;
Similar Messages
-
How to Find Number of Given Element in a XML Document
Hello Experts,
I want to know the number of given element in a XML document. For example if we have an employees information as a XML document, can we have how many <phone> element in the XML document?
Thanks in advance.
Regards,
JPHello,
Once you've answered all the above.
If you can run xpath that supports functions against the xml, the expression:
count(//phone)Otherwise, without leaving SQL:
select count(*) from
xmltable('//phone' passing
-- Your XML goes here, could be a table column with type XMLTYPE.
xmltype('<person><phone>123-456-7890</phone><phone>098-765-4321</phone></person>')
columns phone varchar2(24 char) path '/phone'
; -
How to add namespaces before a tag name in XML??
Dear friends:
I have following code, and hope to add namespaces before the tagname such as Company, Location and even any attributes in this xml,
Can you help throw some lights??
Thanks in advance.
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import com.sun.org.apache.xml.internal.serialize.OutputFormat;
import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
import org.w3c.dom.Element;
public class DocWriteDOMStart {
public static void main(String[] av) throws IOException {
DocWriteDOMStart dw = new DocWriteDOMStart();
Document doc = dw.makeDoc();
((org.apache.crimson.tree.XmlDocument)doc).write(System.out);
/** Generate the XML document */
protected Document makeDoc() {
try {
DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance();
DocumentBuilder parser = fact.newDocumentBuilder();
Document doc = parser.newDocument();
Element root = doc.createElement("Company");;
doc.appendChild(root);
Element loc = doc.createElement("Location");
root.appendChild(loc);
Element emp = doc.createElement("Employee");
loc.appendChild(emp);
emp.appendChild(doc.createTextNode("Daniel Bush"));
Element emp2 = doc.createElement("Employee");
loc.appendChild(emp2);
emp2.appendChild(doc.createTextNode("Sandy Moore"));
Element dept = doc.createElement("Department");
Element e = (Element)dept;
e.setAttribute("Nationality", "USA");
e.setAttributeNS("www.yahoo.com", "dept", "http://www.google.com");
//e.setAttributeNodeNS(newAttr);
loc.appendChild(e);
e.appendChild(doc.createTextNode("IT Depart"));
return doc;
} catch (Exception ex) {
System.err.println(ex.getClass());
System.err.println(ex.getMessage());
return null;
}and I got
<?xml version="1.0" encoding="UTF-8"?>
<Company>
<Location>
<Employee>Daniel Bush</Employee>
<Employee>Sandy Moore</Employee>
<Department Nationality="USA" dept="http://www.google.com">IT Depart</Department>
</Location>
</Company>hope to add namespaces before the tagname such as Company, Location and even any attributes such as dept, nationality etc in this xml,
I try but fail.You would have to write code that does that, then. Right now your code writes that part of your XML as elements that aren't in a namespace. I can tell you know there are different methods to write elements that are in a namespace because you used a different method to try to write an attribute that is in a namespace.
-
How to add a new data element for existing table filed(Primary key field)
Hi Experts,
How to add a new data element for existing table field(Primary key field)
For this filed ther is no foreign key relation ships and even check table.
while activating table it is giving message like below.
can you help any one to solve this and wil steps to add new dataelement for existing primary key filed of a table.
Check table (NAMING SPACE/TABLE NAME(EX:/TC/VENDOR)) (username/19.02.10/03:29)
Primary key change not permitted for value table /TC/VENDOR
Check on table /TC/VENDOR resulted in errors
Thanks
RaviHi,
Easiest way is to download the table eg into an Excel table (if possible) or text table. Drop the table from the database. Build your table with the new key field. Build the database table again and fill it.
You can do it also over the database into a new table. Drop the old one. Build the enhanced one and fill it. Afterwards drop your (temporary) table.
Maybe there are other ways, but this works.
Success,
Rob -
Problem in digitally signing a particular element of an XML Document
hi all!!
I was trying to sign a particular element of an XML document using JSR105 (XML Digital Signatures) API.
For which i used +#xpointer(id('idvalue'))+ and +#idvalue+ as the URI for the reference i create as below :
Reference ref = fac.newReference("#xpointer(id('123')) ", fac.newDigestMethod(DigestMethod.SHA1, null), Collections.singletonList(fac.newTransform(Transform.ENVELOPED,(TransformParameterSpec) null)), null, null);
NOTE: Here 123 is the value of the attribute 'id' of the element i wish to sign in the input XML document.
But when i try to digest and sign the the above created reference, i get the following exception (which is strange! atleast for me!)
Exception in thread "main" javax.xml.crypto.dsig.XMLSignatureException: javax.xml.crypto.URIReferenceException: Can't resolve ID: '123' in ''
at com.ibm.xml.crypto.dsig.dom.ReferenceImpl.calculateDigestValue(ReferenceImpl.java:327)
at com.ibm.xml.crypto.dsig.dom.ReferenceImpl.sign(ReferenceImpl.java:237)
at com.ibm.xml.crypto.dsig.dom.XMLSignatureImpl.sign(XMLSignatureImpl.java:158)
at sent.Generate.main(Generate.java:103)
Caused by: javax.xml.crypto.URIReferenceException: Can't resolve ID: '123' in ''
at com.ibm.xml.crypto.dsig.dom.URIDereferencerImpl.dereference(URIDereferencerImpl.java:193)
at com.ibm.xml.crypto.dsig.dom.ReferenceImpl.calculateDigestValue(ReferenceImpl.java:285)
+... 3 more+
javax.xml.crypto.URIReferenceException: Can't resolve ID: '123' in ''
at com.ibm.xml.crypto.dsig.dom.URIDereferencerImpl.dereference(URIDereferencerImpl.java:193)
at com.ibm.xml.crypto.dsig.dom.ReferenceImpl.calculateDigestValue(ReferenceImpl.java:285)
at com.ibm.xml.crypto.dsig.dom.ReferenceImpl.sign(ReferenceImpl.java:237)
at com.ibm.xml.crypto.dsig.dom.XMLSignatureImpl.sign(XMLSignatureImpl.java:158)
at sent.Generate.main(Generate.java:103)
I've given the whole Java code i used to generate the signature and the XML i used below for you to get a clear picture of what i tried...
Any suggestions are very much welcome..
thanks..
ragu
Generate.java
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.xml.crypto.MarshalException;
import javax.xml.crypto.dsig.CanonicalizationMethod;
import javax.xml.crypto.dsig.DigestMethod;
import javax.xml.crypto.dsig.Reference;
import javax.xml.crypto.dsig.SignatureMethod;
import javax.xml.crypto.dsig.SignedInfo;
import javax.xml.crypto.dsig.Transform;
import javax.xml.crypto.dsig.XMLSignature;
import javax.xml.crypto.dsig.XMLSignatureException;
import javax.xml.crypto.dsig.XMLSignatureFactory;
import javax.xml.crypto.dsig.dom.DOMSignContext;
import javax.xml.crypto.dsig.keyinfo.KeyInfo;
import javax.xml.crypto.dsig.keyinfo.KeyInfoFactory;
import javax.xml.crypto.dsig.keyinfo.KeyValue;
import javax.xml.crypto.dsig.spec.C14NMethodParameterSpec;
import javax.xml.crypto.dsig.spec.TransformParameterSpec;
import javax.xml.crypto.dsig.spec.XPathFilterParameterSpec;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
public class Generate {
* @param args
* @throws NoSuchAlgorithmException
* @throws InvalidAlgorithmParameterException
* @throws KeyException
* @throws ParserConfigurationException
* @throws IOException
* @throws SAXException
* @throws FileNotFoundException
* @throws XMLSignatureException
* @throws MarshalException
* @throws TransformerException
public static void main(String[] args) throws NoSuchAlgorithmException,
InvalidAlgorithmParameterException, KeyException,
FileNotFoundException, SAXException, IOException,
ParserConfigurationException, MarshalException,
XMLSignatureException, TransformerException {
java.security.Security
.addProvider(new com.ibm.xml.crypto.IBMXMLCryptoProvider());
XMLSignatureFactory fac = XMLSignatureFactory.getInstance("DOM",
new com.ibm.xml.crypto.IBMXMLCryptoProvider());
//reference generation
//its here where I point the URI to the element i want to digest
Reference ref = fac.newReference("#xpointer(id('123'))", fac.newDigestMethod(DigestMethod.SHA1, null), Collections.singletonList(fac.newTransform(Transform.ENVELOPED,(TransformParameterSpec) null)), null, null);
//signedinfo element generation
SignedInfo si = fac
.newSignedInfo(fac.newCanonicalizationMethod(
CanonicalizationMethod.INCLUSIVE,
(C14NMethodParameterSpec) null), fac
.newSignatureMethod(SignatureMethod.RSA_SHA1, null),
Collections.singletonList(ref));
KeyInfoFactory kif = fac.getKeyInfoFactory();
//Create a DSA KeyPair
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
kpg.initialize(512);
KeyPair kp = kpg.generateKeyPair();
KeyValue kv = kif.newKeyValue(kp.getPublic());
// Create a KeyInfo and add the KeyValue to it
KeyInfo ki = kif.newKeyInfo(Collections.singletonList(kv));
// Instantiate the document to be signed
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
Document doc = dbf.newDocumentBuilder().parse(
new FileInputStream(new File("shippedPedigree.xml")));
// Create a DOMSignContext and specify the DSA PrivateKey and
// location of the resulting XMLSignature's parent element
DOMSignContext dsc = new DOMSignContext(kp.getPrivate(), doc
.getDocumentElement());
//Create the XMLSignature (but don't sign it yet)
XMLSignature signature = fac.newXMLSignature(si, ki);
// Marshal, generate (and sign) the enveloped signature
signature.sign(dsc);
//writing the signed document back to the file
OutputStream os;
os = new FileOutputStream(new File("shippedpedigree.xml"));
TransformerFactory tf = TransformerFactory.newInstance();
Transformer trans = tf.newTransformer();
trans.transform(new DOMSource(doc), new StreamResult(os));
the "shippedPedigree.xml" i used to sign:
<?xml version="1.0" encoding="UTF-8"?>
<ped:pedigree xmlns:ped="urn:epcGlobal:Pedigree:xsd:1" xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ped:shippedPedigree id="123">
<ped:documentInfo>
<ped:serialNumber>2233</ped:serialNumber>
<ped:version>ped:version</ped:version>
</ped:documentInfo>
<ped:signatureInfo>
<ped:signerInfo>
<ped:name>Joe Doe</ped:name>
<ped:title>Manager</ped:title>
<ped:telephone>800-521-6010</ped:telephone>
<ped:email>[email protected]</ped:email>
<ped:url>www.kittinginc.com</ped:url>
</ped:signerInfo>
<ped:signatureDate>2001-12-31T12:00:00</ped:signatureDate>
<ped:signatureMeaning>Certified</ped:signatureMeaning>
</ped:signatureInfo>
<ped:itemInfo>
<ped:lot>123</ped:lot></ped:itemInfo>
</ped:shippedPedigree></ped:pedigree>
------------------------------------------------------------------------Sabarisri N wrote:
Hi All,
my xml is like below.
<ns1:abcd>
<ns2:a>1</ns2:a>
<ns2:b>2</ns2:b>
</ns1:abcd>
If i try retrieving the value of the root element of this xml document,
Node myroot=doc.getDocumentElement();
String result=myroot.getNodeName();
My output is ns1:abcd .. i want only "abcd"...
The parser is returning the correct rootNodeName i.e ns1:abcd. rootNodeName always goes with the given input and returns the root element as is.
>
My xml will not always have same namespaces.. from the incoming xml i should first check, for the namespaces..Please give me some idea.
I guess.. I need some namespace evaluation to be set..
Refer below link it'll give idea of identifying XML-NAMESPACE-PREFIX
http://java.sun.com/developer/Books/xmljava/ch03.pdf
http://download.oracle.com/javaee/1.4/tutorial/doc/JAXPSAX9.html
Please help me in this regard.
Thanks,
Sabarisri. N -
Use DOM to get the element value of XML document?
I can not to use the method getNodeValue to get the element value of XML document. How can I do for it?
For example, for element
<address>125 Smith Avenue</address>
how to get the value "125 Smith Avenue" by using DOM?
ThanksThanks for all of you.
The code indicates that I need to get the node by tag name. If I do not know the distribution of the elements and want to traverse all nodes. If the node contains value, I retrieve the value. How to implement the general case.
For example, my XML file represent a directory hierarchy and looks like
<root>
<usr>
<user>user1
<file>file1</file>
<file>file2</file>
</user>
<user>user2
<file>file1</file>
<file>file2</file>
<file>file3</file>
<file>file4</file>
</user>
</usr>
</root> -
Identify individual elements in repeated elements in an XML document
Hello,
I'd like to identify individual elements in repeated elements in an XML document.
For example a table 'dataXML' which has a column 'sample' (XMLType). If I have an XML document such as,
<ELEMENT>
<PO>
<PONO>100</PONO>
<PONO>200</PONO>
</PO>
</ELEMENT>
I can use //PONO[1] to identify the first "PONO" element (with value 100) and //PONO[2] to identify the second "PONO" element in the document.
If I write this query:
select L.sample.extract('ELEMENT/PO/PONO/text()')).getStringVal()"SAMP"
from dataXML L
I'll receive this result:
SAMP
100200 (the first row)
And if I write this query:
select L.sample.extract('ELEMENT/PO/PONO[1]/text()')).getStringVal()"SAMP"
from dataXML L
I'll receive this result:
SAMP
100 (the first row)
But I'd like the following result:
SAMP
100 (the first row)
200 (the second row).
Could you help me, please?
Thank you very much.
Melissa Lemosyou have to use something like this.
select extractvalue(xmltype_column, '/Name/@attributename')
from table_name
For more details see
XMLDB Developers Guide (Oracle 9i)
Chapter - XPATH and namespace Primer
Table C2 - Location Path Examples Using Abbreviated Syntax.
Page Number 907/1044
Hope this helps. -
Inserting an element into an XML document
I am simply looking insert a new element into an existing XML Document using JDOM. Here is my code so far:
public class UserDocumentWriter {
private SAXBuilder builder;
private Document document;
private File file = new File("/path/to/file/users.xml");
private Element rootElement;
public UserDocumentWriter() {
builder = new SAXBuilder();
try {
document = builder.build(file);
rootElement = document.getRootElement();
} catch (IOException ioe) {
System.err.println("ERROR: Could not build the XML file.");
} catch (JDOMException jde) {
System.err.println("ERROR: " + file.toString() + " is not well-formed.");
public void addContact(String address, String contact) {
List contactList = null;
Element contactListElement;
Element newContactElement = new Element("contact");
newContactElement.setText(contact);
List rootsChildren = rootElement.getChildren();
Iterator iterator = rootsChildren.iterator();
while (iterator.hasNext()) {
Element e = (Element) iterator.next();
if (e.getAttributeValue("address").equals(address)) {
contactListElement = e.getChild("contactlist");
contactListElement.addContent(newContactElement);
writeDocument(document);
public void writeDocument(Document doc) {
try {
XMLOutputter output = new XMLOutputter();
OutputStream out = new FileOutputStream(file);
output.output(doc, out);
} catch (FileNotFoundException ntfe) {
System.err.println("ERROR: Output file not found.");
} catch (IOException ioe) {
System.err.println("Could not output document changes.");
}However, the problem is, the newly added element will always be appended to the end of the last line, resulting in the following:
<contactlist>
<contact>[email protected]</contact><contact>[email protected]</contact></contactlist>Is there anyway in which I can have the newly added element create it's own line for the purpose of tidy XML? Alternatively is there a better methodology to do the above entirely?Your question is not very clear.
Do you want to know How to insert an element into an XML document?
Answer: I can see you already know how to do it. You have added the element using addContent()
or do you want to know How to display the XML in a tidy format?
Answer: to view the XML in a properly formatted style you can you the Format class. A very basic way of viewing the XML would be:
* Prints the Document to the specified file.
* @param doc
* @param filename
* @param formatting
public static void printDocToFile(Document doc, String strFileName,
boolean formatting)
XMLOutputter xmlOut = null;
if (!formatting)
xmlOut = new XMLOutputter();
} else
Format prettyFormat = Format.getPrettyFormat();
prettyFormat.setOmitEncoding(false);
prettyFormat.setOmitDeclaration(false);
xmlOut = new XMLOutputter(prettyFormat);
try
if (doc != null)
FileWriter writer = new java.io.FileWriter(strFileName, true);
xmlOut.output(doc, writer);
writer.flush();
writer.close();
} else
System.out.println("Document is null.");
catch (Exception ex)
System.out.println(ex);
} -
How can i use a xsd while generating my xml document in oracle?
Hi, how can i use a xsd while building my xml document query, so i know the xml was built properly?
Cheers.Hi,
Do you want to validate your xml against xsd?
Read this
validating
There are some bugs also, for example xml is invalid but no errors when calling schemaValidate()
Ants -
How to add namespace prefixes to XMLType created from Object?
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE 11.2.0.3.0 Production
TNS for Linux: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
I'm working with SOAP request creation from Schema derived Types.
Consider the registration of the following annotated schema (I wanted Oracle to create the types for me, but with my own names):
exec dbms_xmlschema.deleteSchema(schemaURL => 'Parameters4.xsd');
declare
v_xsd xmltype := xmltype('<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:oraxdb="http://xmlns.oracle.com/xdb"
xmlns = "http://www.cognera.com"
targetNamespace = "http://www.cognera.com">
<xs:element name="Parameters" oraxdb:SQLName="Parameters" oraxdb:SQLType="Parameters">
<xs:complexType oraxdb:SQLType="Parameters">
<xs:sequence>
<xs:element name="Param1" type="xs:string" oraxdb:SQLName="Param1" oraxdb:SQLType="VARCHAR2" />
<xs:element name="NestedItems" oraxdb:SQLName="NestedItems" oraxdb:SQLType="NestedItemsType">
<xs:complexType oraxdb:SQLType="NestedItemsType">
<xs:sequence>
<xs:element name="NestedItem" type="NestedItemType" oraxdb:SQLName="NestedItem" oraxdb:SQLType="NestedItemType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="NestedItemType" oraxdb:SQLType="NestedItemType">
<xs:sequence>
<xs:element name="nParam1" type="xs:string" oraxdb:SQLName="nParam1" oraxdb:SQLType="VARCHAR2"/>
<xs:element name="nParam2" type="xs:string" oraxdb:SQLName="nParam2" oraxdb:SQLType="VARCHAR2"/>
<xs:element name="nParam3" type="xs:string" oraxdb:SQLName="nParam3" oraxdb:SQLType="VARCHAR2"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
begin
dbms_xmlschema.registerSchema(schemaURL => 'Parameters4.xsd', --this name is local to each ERS schema.
schemaDoc => v_xsd,
local => TRUE,
genTypes => TRUE, --only want the types
genbean => FALSE,
genTables => TRUE, --not sure if I need this
force => TRUE,
owner => user);
end;
Types created were:
CREATE OR REPLACE TYPE "NestedItemType" AS OBJECT ("SYS_XDBPD$" "XDB"."XDB$RAW_LIST_T","nParam1" VARCHAR2(4000 CHAR),"nParam2" VARCHAR2(4000 CHAR),"nParam3" VARCHAR2(4000 CHAR))NOT FINAL INSTANTIABLE
CREATE OR REPLACE TYPE "NestedItemsType" AS OBJECT ("SYS_XDBPD$" "XDB"."XDB$RAW_LIST_T","NestedItem" "NestedItemType")FINAL INSTANTIABLE
CREATE OR REPLACE TYPE "Parameters" AS OBJECT ("SYS_XDBPD$" "XDB"."XDB$RAW_LIST_T","Param1" VARCHAR2(4000 CHAR),"NestedItems" "NestedItemsType")FINAL INSTANTIABLE
I found that in order to build these types using constructors (to avoid PLS-00306: wrong number or types of arguments in call to 'NestedItemType'), that I needed to edit these types (drop the xdb magic):
CREATE OR REPLACE TYPE "NestedItemType" AS OBJECT ("nParam1" VARCHAR2(4000 CHAR),"nParam2" VARCHAR2(4000 CHAR),"nParam3" VARCHAR2(4000 CHAR))FINAL INSTANTIABLE
CREATE OR REPLACE TYPE "NestedItemsType" AS OBJECT ("NestedItem" "NestedItemType")FINAL INSTANTIABLE
CREATE OR REPLACE TYPE "Parameters" AS OBJECT ("Param1" VARCHAR2(4000 CHAR),"NestedItems" "NestedItemsType")FINAL INSTANTIABLE
I read on the forums of a hack to get a namespace added in the output:
CREATE OR REPLACE TYPE "Parameters" AS OBJECT ("@xmlns" VARCHAR2(4000), -- namespace attribute HACK
"Param1" VARCHAR2(4000 CHAR),"NestedItems" "NestedItemsType")FINAL INSTANTIABLE
Putting it all together, I have:
DECLARE
v_Parameters "Parameters";
v_xml xmltype;
v_print_output clob;
begin
v_Parameters := "Parameters"('www.cognera.com',
'hello',
"NestedItemsType"("NestedItemType"('one',
'two',
'three'
v_xml := xmltype(xmlData => v_Parameters);
select xmlserialize(document
xmlquery('declare namespace soap = "http://www.w3.org/2003/05/soap-envelope";
declare namespace cognera = "http://www.cognera.com";
<soap:Envelope>
<soap:Header/>
<soap:Body>
</soap:Body>
</soap:Envelope>
' passing v_xml returning content) as clob
indent size=2
) into v_print_output from dual;
dbms_output.put_line(v_print_output);
end;
This outputs:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header/>
<soap:Body>
<Parameters xmlns="www.cognera.com">
<Param1>hello</Param1>
<NestedItems>
<NestedItem>
<nParam1>one</nParam1>
<nParam2>two</nParam2>
<nParam3>three</nParam3>
</NestedItem>
</NestedItems>
</Parameters>
</soap:Body>
</soap:Envelope>
What I really want is:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:c="www.cognera.com">
<soap:Header/>
<soap:Body>
<c:Parameters>
<c:Param1>hello</c:Param1>
<c:NestedItems>
<c:NestedItem>
<c:nParam1>one</c:nParam1>
<c:nParam2>two</c:nParam2>
<c:nParam3>three</c:nParam3>
</c:NestedItem>
</c:NestedItems>
</c:Parameters>
</soap:Body>
</soap:Envelope>
How do I do this without having to programatically add the namespace using a custom XQuery function?See this similar thread, it should give you some better alternatives than the "@xmlns" hack :
Add Namespaces via XQuery to an XML Instance
For example :
SQL> SELECT XMLSerialize(DOCUMENT
2 XMLTransform(
3 xmltype(
4 "Parameters"('hello', "NestedItemsType"("NestedItemType"('one','two','three')))
5 )
6 , xmlparse(content
7 '<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
8 <xsl:output encoding="UTF-8" indent="yes" method="xml"/>
9 <xsl:param name="ns"/>
10 <xsl:template match="/">
11 <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
12 <soap:Header/>
13 <soap:Body>
14 <xsl:apply-templates select="*"/>
15 </soap:Body>
16 </soap:Envelope>
17 </xsl:template>
18 <xsl:template match="*">
19 <xsl:element name="{local-name()}" namespace="{$ns}">
20 <xsl:apply-templates select="@*|node()"/>
21 </xsl:element>
22 </xsl:template>
23 </xsl:stylesheet>')
24 , q'{ns="'www.cognera.com'"}'
25 )
26 INDENT
27 ) AS "XSLT Output"
28 FROM dual ;
XSLT Output
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header/>
<soap:Body>
<Parameters xmlns="www.cognera.com">
<Param1>hello</Param1>
<NestedItems>
<NestedItem>
<nParam1>one</nParam1>
<nParam2>two</nParam2>
<nParam3>three</nParam3>
</NestedItem>
</NestedItems>
</Parameters>
</soap:Body>
</soap:Envelope>
You can store the stylesheet in the XDB repository or in a table and access it using a DBUriType.
It then provides a concise way to both add the namespace and wrap the payload in the envelope. -
How do I return all elements from a xml doc?
I have a xml document which in my VB code I am saving the elements(ns1:Statute) in a variable
objXmlStatuteNode then adding that variable in to an object
objXmlStatutesDoc.
My code is working but only displaying one element (<ns1:Statute>) even though I have 3 <ns1:Statute>. How do I display all 3 <ns1:Statute>?
Here is my xml document modified version to make it short.
<ns1:Statutes xmlns:ns1="http://crimnet.state.mn.us/mnjustice/statute/messages/4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ns1:Statutes xmlns:ns1="http://crimnet.state.mn.us/mnjustice/statute/messages/4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ns1:Statute>
<StatuteId xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">12875</StatuteId>
<Chapter xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">171</Chapter>
<Section xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">22</Section>
<Subdivision xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">1(7)</Subdivision>
<Year xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">1994</Year>
</ns1:Statute>
<ns1:Statute>
<StatuteId xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">12875</StatuteId>
<Chapter xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">171</Chapter>
<Section xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">22</Section>
<Subdivision xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">1(7)</Subdivision>
<Year xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">1994</Year>
</ns1:Statute>
<ns1:Statute>
<StatuteId xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">12875</StatuteId>
<Chapter xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">171</Chapter>
<Section xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">22</Section>
<Subdivision xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">1(7)</Subdivision>
<Year xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">1994</Year>
</ns1:Statute>
</ns1:Statutes>
Here is my vb code
Public Class GetStatutes
Shared Sub main()
Dim objMessageProcessor As New MessageProcessor
Dim objSchemasCollection As New Msc.Integration.MessageBroker.Library.v4.SchemasCollection
Dim objTransformsCollection As New Msc.Integration.MessageBroker.Library.v4.TransformsCollection
objMessageProcessor.ProcessInputQueue(False, False, objSchemasCollection, objTransformsCollection)
End Sub
'Child class MessageProcessor which inherits from main class GetStatutes
Private Class MessageProcessor
Inherits Msc.Integration.ServiceCatalog.Library.v4.SoapMessageProcessor
Protected Overrides Sub ProcessMessage(ByRef aobjBroker As ServiceCatalog.Library.v4.Broker, ByRef aobjXMLInputSoapEnvelopeDoc As System.Xml.XmlDocument, ByRef aobjInstantiatedObjectsCollection As Microsoft.VisualBasic.Collection, ByRef aobjConsumer As ServiceCatalog.Library.v4.Consumer)
MyBase.ProcessMessage(aobjBroker, aobjXMLInputSoapEnvelopeDoc, aobjInstantiatedObjectsCollection, aobjConsumer)
Dim objXmlStatutesDoc As XmlDocument
Dim objXmlStatuteNode As XmlNode
Dim objNameTable As Xml.NameTable
Dim objXMLNameSpaceManager As XmlNamespaceManager
Dim objXmlBcaResponseDoc As XmlDocument
Dim objXMLOutputSoapEnvelopeDoc As XmlDocument
'set up the namespace manager
objNameTable = New Xml.NameTable
objXMLNameSpaceManager = New Xml.XmlNamespaceManager(objNameTable)
objXMLNameSpaceManager.AddNamespace("soap", Msc.Integration.Utility.Library.v4.Soap.NamespaceUri(aobjBroker.SoapMessageVersion))
objXMLNameSpaceManager.AddNamespace("wsa", Msc.Integration.Utility.Library.v4.Soap.WsaNamespaceUri(aobjBroker.SoapMessageVersion))
objXMLNameSpaceManager.AddNamespace("ns1", "http://crimnet.state.mn.us/mnjustice/statute/messages/4.0")
objXMLNameSpaceManager.AddNamespace("st", "http://crimnet.state.mn.us/mnjustice/statute/4.0")
objXmlStatuteNode = aobjXMLInputSoapEnvelopeDoc.DocumentElement.SelectSingleNode("soap:Body/GetBCAStatuteRequest", objXMLNameSpaceManager)
objXmlStatutesDoc = New XmlDocument
'Get the statutes
objXmlBcaResponseDoc = New XmlDocument
objXmlBcaResponseDoc.Load("\\j00000swebint\mscapps\deve\appfiles\temp\BcaStatutes.xml")
objXmlStatutesDoc = New XmlDocument
objXmlStatutesDoc.AppendChild(objXmlStatutesDoc.CreateElement("Statutes"))
objXmlStatutesDoc.DocumentElement.SetAttribute("runType", "Request")
objXmlStatutesDoc.DocumentElement.SetAttribute("runDateTime", Format(Now, "yyyy-MM-ddTHH:mm:ss"))
'Create a variable to store the statute element information ns1:Statute name space
objXmlStatuteNode = objXmlBcaResponseDoc.DocumentElement.SelectSingleNode("ns1:Statute", objXMLNameSpaceManager)
'Add the variable objXmlStatudeNode to the object objXmlStatuteDoc
objXmlStatutesDoc.DocumentElement.AppendChild(objXmlStatutesDoc.ImportNode(objXmlStatuteNode, True))
'Create the SOAP envelope to return the reply to the submitter
objXMLOutputSoapEnvelopeDoc = aobjBroker.CreateSoapEnvelope("http://www.courts.state.mn.us/StatuteService/1.0/GetStatutesResponse", _
Msc.Integration.Utility.Library.v4.Soap.GetReplyEndpointReference(aobjXMLInputSoapEnvelopeDoc), _
objXmlStatutesDoc.DocumentElement, , aobjConsumer, _
aobjXMLInputSoapEnvelopeDoc.DocumentElement.SelectSingleNode("soap:Header/wsa:MessageID", objXMLNameSpaceManager).InnerText)
'Return the response to the requester
aobjBroker.Reply(objXMLOutputSoapEnvelopeDoc)
End Sub
End Class
End Classwinkimjr2,
Are you aware that there's a duplicate line in the XML? It won't work with that in there so I've modified it as shown here:
<ns1:Statutes xmlns:ns1="http://crimnet.state.mn.us/mnjustice/statute/messages/4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ns1:Statute>
<StatuteId xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">12875</StatuteId>
<Chapter xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">171</Chapter>
<Section xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">22</Section>
<Subdivision xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">1(7)</Subdivision>
<Year xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">1994</Year>
</ns1:Statute>
<ns1:Statute>
<StatuteId xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">12875</StatuteId>
<Chapter xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">171</Chapter>
<Section xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">22</Section>
<Subdivision xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">1(7)</Subdivision>
<Year xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">1994</Year>
</ns1:Statute>
<ns1:Statute>
<StatuteId xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">12875</StatuteId>
<Chapter xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">171</Chapter>
<Section xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">22</Section>
<Subdivision xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">1(7)</Subdivision>
<Year xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">1994</Year>
</ns1:Statute>
</ns1:Statutes>
The following isn't a way that I'm proud to do but I couldn't manage to work out LINQ-To-XML all the way through it. Nevertheless, this will work:
Option Strict On
Option Explicit On
Option Infer Off
Imports System.IO.Path
Imports <xmlns:NS1="http://crimnet.state.mn.us/mnjustice/statute/messages/4.0">
Public Class Form1
Private Class NS1
Private _statuteID As Integer
Private _chapter As Integer
Private _section As Integer
Private _subdivision As String
Private _year As Integer
Public Sub New(ByVal id As Integer, _
ByVal chapter As Integer, _
ByVal section As Integer, _
ByVal subdivision As String, _
ByVal year As Integer)
_statuteID = id
_chapter = chapter
_section = section
_subdivision = subdivision.Trim
_year = year
End Sub
Public ReadOnly Property Chapter() As Integer
Get
Return _chapter
End Get
End Property
Public ReadOnly Property Section() As Integer
Get
Return _section
End Get
End Property
Public ReadOnly Property StatuteID() As Integer
Get
Return _statuteID
End Get
End Property
Public ReadOnly Property Subdivision() As String
Get
Return _subdivision
End Get
End Property
Public ReadOnly Property Year() As Integer
Get
Return _year
End Get
End Property
End Class
Private ns1List As New List(Of NS1)
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
Dim desktop As String = _
My.Computer.FileSystem.SpecialDirectories.Desktop
Dim xmlPath As String = _
Combine(desktop, "Example.xml")
GetNS1Data(xmlPath)
Stop
' Now hover your mouse over "ns1List" above
' and expand it. You'll see your data.
End Sub
Private Sub GetNS1Data(ByVal filePath As String)
If My.Computer.FileSystem.FileExists(filePath) Then
Try
Dim xDoc As XElement = XElement.Load(filePath)
For Each sData As XElement In xDoc...<NS1:Statute>
Dim id As Integer
Dim chapter As Integer
Dim section As Integer
Dim subdivision As String = Nothing
Dim year As Integer
For Each element As XElement In sData.Elements
Select Case element.Name.LocalName
Case "StatuteId"
If Not Integer.TryParse(element.Value, id) Then
Throw New ArgumentException("The StatuteID could not be parsed.")
End If
Case "Chapter"
If Not Integer.TryParse(element.Value, chapter) Then
Throw New ArgumentException("The Chapter could not be parsed.")
End If
Case "Section"
If Not Integer.TryParse(element.Value, section) Then
Throw New ArgumentException("The Section could not be parsed.")
End If
Case "Subdivision"
If String.IsNullOrEmpty(element.Value) OrElse element.Value.Trim = "" Then
Throw New ArgumentException("The Subdivision could not be parsed.")
Else
subdivision = element.Value
End If
Case "Year"
If Not Integer.TryParse(element.Value, year) Then
Throw New ArgumentException("The Year could not be parsed.")
End If
End Select
Next
Dim instance As New NS1(id, chapter, section, subdivision, year)
ns1List.Add(instance)
Next
Catch ex As Exception
Throw
End Try
End If
End Sub
End Class
I hope that helps. :)
Still lost in code, just at a little higher level. -
How to remove namespace from root-element
Hi Gurus,
I want one xml output from xslt transformation with no namespace. I managed to remove namespace from child elements by leveraging elementFormDefault ='unqualified' property of xsd. But not able remove namespace from root-element.
Output that I want is :
<?xml version = '1.0' encoding = 'UTF-8'?>
<inp1:Email_Mod_Root>
<Email_Mod_Root_Element>
<Email_Record1>
<PERSON_NUMBER>123456</PERSON_NUMBER>
<COUNTRY/>
<EMAIL_TYPE>WORK</EMAIL_TYPE>
<EMAIL>EMAIL3</EMAIL>
<PRIMARY_FLAG>Y</PRIMARY_FLAG>
</Email_Record1>
</Email_Mod_Root_Element>
</Email_Mod_Root>
Output that I am getting:
<?xml version = '1.0' encoding = 'UTF-8'?>
<inp1:Email_Mod_Root xmlns:inp1="http://www.example.org">
<Email_Mod_Root_Element>
<Email_Record1>
<PERSON_NUMBER>123456</PERSON_NUMBER>
<COUNTRY/>
<EMAIL_TYPE>WORK</EMAIL_TYPE>
<EMAIL>EMAIL3</EMAIL>
<PRIMARY_FLAG>Y</PRIMARY_FLAG>
</Email_Record1>
</Email_Mod_Root_Element>
</Email_Mod_Root>
Anyone, pls suggest.
Thanks in advance,
SG_SOAFirst of all :
<inp1:Email_Mod_Root>
<Email_Mod_Root_Element>
<Email_Record1>
<PERSON_NUMBER>123456</PERSON_NUMBER>
<COUNTRY/>
<EMAIL_TYPE>WORK</EMAIL_TYPE>
<EMAIL>EMAIL3</EMAIL>
<PRIMARY_FLAG>Y</PRIMARY_FLAG>
</Email_Record1>
</Email_Mod_Root_Element>
</Email_Mod_Root>
isn't valid xml (you start with inp1: prefix and you end the tag with no prefix, but let's assume you don't want any prefix/namespace at all)
if i use :
[code]
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:inp1="http://www.example.org" exclude-result-prefixes="inp1">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="*">
<xsl:element name="{local-name(.)}">
<xsl:apply-templates select="@* | node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="@*">
<xsl:attribute name="{local-name(.)}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
[/code]
i get this
[code]
<Email_Root_Element>
<Email_Record>
<EMPLID>EMPLID46</EMPLID>
<EMAIL>EMAIL48</EMAIL>
<E_ADDR_TYPE>E_ADDR_TYPE49</E_ADDR_TYPE>
<COUNTRY>US</COUNTRY>
</Email_Record>
<Email_Record>
<EMPLID>EMPLID47</EMPLID>
<EMAIL>EMAIL49</EMAIL>
<E_ADDR_TYPE>E_ADDR_TYPE50</E_ADDR_TYPE>
<COUNTRY>US</COUNTRY>
</Email_Record>
<Email_Record>
<EMPLID>EMPLID48</EMPLID>
<EMAIL>EMAIL49</EMAIL>
<E_ADDR_TYPE>E_ADDR_TYPE51</E_ADDR_TYPE>
<COUNTRY>US</COUNTRY>
</Email_Record>
</Email_Root_Element>
[/code] -
How to add attribute to the elements in XML file in BPEL transformation
Hi All-
I have to create a XML file using transformation and file adapater and the parent element is USERRECORDS, now when I am creating the XML file using transformation the XML get creates like
<?xml version="1.0">
<USERRECORDS>
so on
But I want the parent element and the xml version tags as:
<?xml version="1.0" encoding="UTF-8"?>
<USERRECORDS xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="mySchema.xsd">
as I need to add the attributes.
Is it possible in transformation?
Any idea, please suggest.
Thanks and Regards,
SreejitI have never come across any functionality like that.
However I assigned values to attributes in Assign Acitivity using XML Fragment on source side. -
How to search for a particular element within a XML variable using studio?
All,
I am using studio 7.0 to develop a webbased application. In this, i need to access
an oracle db using a WLAI Application View from my Workflow. I get some data back
from Oracle as an XML variable and then apply an XPath statement to access the
individual columns returned.
My problem arises when there are no records in the db matching my criteria and
an empty XML variable is returned to me from the app view. In these cases my
XPath statement fails in studio causing an improper exit.
Does anybody know how to check for content in a XML varaible using studio? So
that if there is content i can proceed with XPath and if there is no content,
then i will take a different route.
Thanks in advance
Regards
SriIf I remember correctly, the adapter will return an XML document that contains
XML elements for each row. You can just simply check the count of these elements
with an XPath statement: ie. count(response/row)
"Sri " <[email protected]> wrote:
>
All,
I am using studio 7.0 to develop a webbased application. In this, i need
to access
an oracle db using a WLAI Application View from my Workflow. I get some
data back
from Oracle as an XML variable and then apply an XPath statement to access
the
individual columns returned.
My problem arises when there are no records in the db matching my criteria
and
an empty XML variable is returned to me from the app view. In these
cases my
XPath statement fails in studio causing an improper exit.
Does anybody know how to check for content in a XML varaible using studio?
So
that if there is content i can proceed with XPath and if there is no
content,
then i will take a different route.
Thanks in advance
Regards
Sri -
How to add text and objects (arrows) over a PDF document?
I am only familiar with Adobe Reader. Looking for the least expensive Adobe product that would allow me to add text and arrows over an existing PDF document. Not looking to edit (change) document other than add a "layer" over the original. Basic stuff I'm sure. Thanks for your help.
If you say so But I read the Original Comments and it doesn't sound like adding comments. When you adding layers as he is describing That is adding content.
"Not looking to edit (change) document other than add a 'layer' over the original."
But if you say Commenting then I suppose you are all correct.
Maybe you are looking for
-
Why doesn't Adobe recognize my password on my iPad?
Unfortunately my iPad2 went for a swim the other day and drowned----serious user error. Fortunately the user (me) had backed up the iPad on a regular basis so all data, aps and setting were recovered. The only serious glitch occured when I tri
-
Need to convert time to GMT or UNIVERSAL CO-ORDINATED TIME
Hi, I need to convert a date and time to UNIVERSAL CO-ORDINATED TIME or GMT. Is there any function module to do the same. Please do let me know. TIA Gurpreet
-
Can I make a pdf with hyperlinks from Power Point using Acrobat ?
I have a Power Point presentation which includes hyperlinks to websites. When I use the Power Point slide display they work. Can Acrobat make a pdf from Power Point which includes the hyperlinks ? Will the hyperlinks work when the pdf is displayed by
-
IDVD project info doesnt show content and wont burn properly
I am using iDVD 6 on a macbook. have successfully burned DVD's using iDVD in the past and now here is the deal I cant resolve. My imovie is first in DVD map and it is looped. It plays fine when played from this and other locations. I go to project in
-
IfsSession.disconnect( ) is throwin an exception. why
ifsSession.disconnect() is throwin the following exception.. what's the reason for this?? Exception in thread "main" org.omg.CORBA.BAD_OPERATION: The delegate has not been set! minor code: 0 completed: No at org.omg.CORBA.portable.ObjectImpl._get_del