How to remove xmlns attribute from XML tag?
Hello!
I have a XMLType document:
--- P R O B L E M # 1 ---
<?xml version="1.0" encoding="windows-1257" ?>
<RESPONSE xmlns="http://testserver" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://testserver response.xsd">
<DATA REQUEST_ID="111">
<ENTITY name="PACKAGE_001">
<ATTRIBUTE name="PERS_ID" value="1111" />
<ATTRIBUTE name="FIRST_NAME" value="OLGA" />
<ATTRIBUTE name="SURNAME" value="NOVIKOVA" />
</ENTITY>
</DATA>
</RESPONSE>
I very need to remove from RESPONSE tag all addition information. Result I need is:
<?xml version="1.0" encoding="windows-1257" ?>
<RESPONSE>
<DATA REQUEST_ID="111">
<ENTITY name="PACKAGE_001">
<ATTRIBUTE name="PERS_ID" value="1111" />
<ATTRIBUTE name="FIRST_NAME" value="OLGA" />
<ATTRIBUTE name="SURNAME" value="NOVIKOVA" />
</ENTITY>
</DATA>
</RESPONSE>
What can I do in this situation? My Oracle version is 9.2.
--- P R O B L E M # 2 ---
How I can create from source XML this one:
<?xml version="1.0" encoding="windows-1257" ?>
<MY_RESPONSE>
<RESPONSE xmlns="http://testserver" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://testserver response.xsd">
<DATA REQUEST_ID="111">
<ENTITY name="PACKAGE_001">
<ATTRIBUTE name="PERS_ID" value="1111" />
<ATTRIBUTE name="FIRST_NAME" value="OLGA" />
<ATTRIBUTE name="SURNAME" value="NOVIKOVA" />
</ENTITY>
</DATA>
</RESPONSE>
</MY_RESPONSE>
Thanks for your answers!
Flu
Maybe the problem#1 can be solved with a simple pl/sql using REPLACE statement. start with the <RESPONSE and look for the end > and get the entire string and replace that with only <RESPONSE> or maybe you can achieve this using xmldom to delete the attributes as part of the element.
PRoblem#2 can be solved in this way.
select xmlelement("MY_RESPONSE",
xmltype('<RESPONSE xmlns="http://testserver" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://testserver response.xsd">
<DATA REQUEST_ID="111">
<ENTITY name="PACKAGE_001">
<ATTRIBUTE name="PERS_ID" value="1111" />
<ATTRIBUTE name="FIRST_NAME" value="OLGA" />
<ATTRIBUTE name="SURNAME" value="NOVIKOVA" />
</ENTITY>
</DATA>
</RESPONSE>')).GetClobVal()
from dual
/
Similar Messages
-
How to remove elements/attributes from XML using Xpath in XSLT ??
Hello ,
Is there anyway or method of Xpath from which I can delete the elements and attributes from XML at runtime ??
Like I have such XML and I have to remove per attribute highlighted below
<person per="and">
<e:emp a="ir" b="ad" >
</e:emp>
</person>
And want a result like this
<person>
<e:emp a="ir" b="ad" >
</e:emp>
</person>
ThanksTo achieve this you can use the bpelx:remove function: http://download.oracle.com/docs/cd/E12483_01/integrate.1013/b28981/manipdoc.htm#CIHJBJFD
your assign will look like:
<bpel:assign>
<bpelx:remove>
<target variable="person" query="/person/@per" />
</bpelx:remove>
</bpel:assign>
Regards,
Melvin -
How to remove an Element from XML by confirming Attribute of that element
Hi guys
I have an XML file where i have all users DB. Now i want to remove a user from that XML file. I want to check an user id attribute which is uniqe with existing users in XML file, if its the same user then delete this user from XML file and save the changes in XML file.
here is my XML file:
<?xml version="1.0" encoding="UTF-8"?>
<users>
<user id="zahid" password="X8UrUN79avT27LYwUESiliAV328=" name="Zahid Nawaz" phone="9599808" email="[email protected]" role="Tnr+vPuuAAsix8heVWD4mioCgLQ=" />
<user id="Admin" name="alpha beta" password="fEqNCco3Yq9h5ZUglD3CZJT4lBs=" phone="456782656" email="[email protected]" role="Tnr+vPuuAAsix8heVWD4mioCgLQ=" />
<user id="Guest" name="beta alpha" password="+ml3yZuAnbaOHFaIjsOL0ARxmzk=" phone="8765432" email="[email protected]" role="+s6D7jAUvcj5ggPMlOLokiJFLpA=" /><user id="Guest1" name="unknown unknown" password="+ml3yZuAnbaOHFaIjsOL0ARxmzk=" phone="123122112" email="[email protected]" role="+s6D7jAUvcj5ggPMlOLokiJFLpA=" />
</users>for example i want to delete a user which have user id= Guest.
How can i do it in Java. Any code example please. i am using JDOM document and SAXBuilder for parsing.
Waiting for your replay.
Thanks in Advance
Best regardHi,
Till now i tried the following code which give null pointer exception at following line
element.getParentNode().removeChild(element);
public String removeUserByID(String id) throws Exception{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer tFormer = tFactory.newTransformer();
doc = builder.parse(usersXml);
Element element = (Element)doc.getElementsByTagName("user id="+id).item(0);
// Remove the node
element.getParentNode().removeChild(element);
// Normalize the DOM tree to combine all adjacent nodes
doc.normalize();
FileOutputStream fos = new FileOutputStream(this.usersXml);
XMLOutputter out = new XMLOutputter();
out.output(((org.jdom.Document)doc), fos);
/* Source source = new DOMSource(doc);
Result dest = new StreamResult(System.out);
tFormer.transform(source, dest);
System.out.println();
return "true";
if following line i m trying to use first attribute of my XML file where i am passing a string which is for example like "user id=Guest". id is a string which have user Id "Guest".
Element element = (Element)doc.getElementsByTagName("user id="+id).item(0);So any suggestion??Whats wrong here?
Best regards and thanks again 4 ur reply. -
DataWriter - removing attributes from xml tag at the start of document
Hi,
I'm using DataWriter for generating a large XML document, however I do not want the attributees of the starting xml tag to appear in the final file.
Eg: <?xml version="1.0" {color:#ff0000}encoding="UTF-8" standalone="yes"{color}?>I do not want to output the part highlighted in red.
What could be the possible ways to do it? I prefer if it can be removed in the begining itself instead of parsing the document and removing in the end.
-TIA, saum
Edited by: nkrust on Feb 15, 2010 4:29 PMtry {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Marshaller marshaller = new Marshaller(new OutputStreamWriter(
baos));
marshaller.marshal(ResponseContents);
// Create an object of type Document from the XML document
// created.
DocumentBuilderFactory domFactory = DocumentBuilderFactory
.newInstance();
domFactory.setNamespaceAware(false);
DocumentBuilder builder = domFactory.newDocumentBuilder();
responseDoc = builder.parse(new ByteArrayInputStream(
ResponseUtils.formatXMLString(baos.toString())));
} catch (IOException e) {
e.printStackTrace();
System.out.println(e.getMessage());
} -
Fedlet: How to remove SPNameQualifier attribute from Authnrequest message
Hi all,
Hopefully someone on this forum is able to give me some hints how to proceed.
I'm trying to understand how SAML2 works, and how (if I get it working with sample application) I can integrate it with our existing application.
SP: Fedlet (Running on Weblogic 10.3)
IDP: Shibboleth (Running on Weblogic 10.3)
Both are running on the same server, but in different domains (and obviously with different ports).
Fedlet is installed, and has the IDP meta data file loaded. When I go to the fedletsample application, I get the 3 hyperlinks (Of which "Run Identity Provider initiated Single Sign-On" is a broken link). Clicking on the "Run Fedlet (SP) initiated Single Sign-On using HTTP POST binding" brings me to the IDP login page.
My IDP is using the embedded LDAP server from Weblogic. I enter the UID and Password, and (if details are entered correct), I'm redirected to the SP site again. Unfortunately at the SP site (The fedlet app) the message states "Single Sign On failed.".
From reading the log file at the IDP, I understand that my user is successfully authenticated, however IDP (Shibboleth) is unable to process "SPNameQualifer"
The log states a lot but I think the issue is related to an unknown attribute in the NameIDPolicy element:
My NameIDPolicy in the AuthnRequest looks like this
=====
<samlp:NameIDPolicy
AllowCreate="true"
Format="urn:oasis:names:tc:SAML:2.0:nameid-format:transient"
SPNameQualifier="fedletsp"
xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"/>
=====
If I look up the details in the IDP log I see this
======
- Starting to unmarshall DOM element {urn:oasis:names:tc:SAML:2.0:protocol}NameIDPolicy
- Targeted QName checking is not available for this unmarshaller, DOM Element {urn:oasis:names:tc:SAML:2.0:protocol}NameIDPolicy was not verified
- Building XMLObject for {urn:oasis:names:tc:SAML:2.0:protocol}NameIDPolicy
- Unmarshalling attributes of DOM Element {urn:oasis:names:tc:SAML:2.0:protocol}NameIDPolicy
- Pre-processing attribute AllowCreate
- Attribute AllowCreate is neither a schema type nor namespace, calling processAttribute()
- Pre-processing attribute Format
- Attribute Format is neither a schema type nor namespace, calling processAttribute()
- Pre-processing attribute SPNameQualifier
- Attribute SPNameQualifier is neither a schema type nor namespace, calling processAttribute()
- Pre-processing attribute {http://www.w3.org/2000/xmlns/}samlp
- {http://www.w3.org/2000/xmlns/}samlp is a namespace declaration, adding it to the list of namespaces on the XMLObject
- Unmarshalling other child nodes of DOM Element {urn:oasis:names:tc:SAML:2.0:protocol}NameIDPolicy
- Unmarshalling child elements of XMLObject {urn:oasis:names:tc:SAML:2.0:protocol}AuthnRequest
- Unmarshalling child element {urn:oasis:names:tc:SAML:2.0:protocol}RequestedAuthnContextwith unmarshaller org.opensaml.saml2.core.impl.RequestedAuthnContextUnmarshaller
======
From topics I found using google, I understood that this attribute is not required, and that I should "suppres" it from the request.
Now here come my question, how do you suppress this? I assume I would need to add some information to the idp-extended.xml file that indicates to exclude this attribute (SPNameQualifer) from the authrequest. But unfortunately I'm unable to find this infomation.
Any help, tips are appreciated. I'm sure somewhere this information is stored, but I'm unable to find it.
Many thanks
Peter Daalder
Edited by: user11240309 on 13-apr-2011 1:29I would like to perform similar action too.
Anyone know how to remove the "standalone" attribute?
Thanks. -
How can i extract attributes from XML-file
Hi!
I want to extract XML-files.
And the most tags are no problem,but how can i extract attributes?
Here is a part from the XML-Schema:
<xs:complexType name="ATT_LIST">
<xs:sequence>
<xs:element name="ATTRIB" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="VALUE"/>
</xs:sequence>
<xs:attribute name="ATTNAM" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
Thanks for help.
With best regards.
NicoleHi!
If i delete one '/' i get the error message:
data can't be found'
This is my xml-file:
<?xml version="1.0" encoding="UTF-8"?>
<INSOBJ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sv6:8080/sys/schemas/SCOTT/sv6:8080/public/mydocs/inspection_pda_schema.xsd">
<INSP_PDA>
<SYSID>900000438</SYSID>
<INSPECTOR/>
<INSDAT>20001223</INSDAT>
<INSOBJ_TYP>MSP-Mast</INSOBJ_TYP>
<INSOBJ_ID1>BAM / Bad Aussee / Bad Mitterndorf/Grundlsee</INSOBJ_ID1>
<INSOBJ_ID2>MITTERNDORF 2 - M 259</INSOBJ_ID2>
<INSOBJ_ID3>239</INSOBJ_ID3>
<INSOBJ_NAME>259</INSOBJ_NAME>
<PDA_PORTION>0000000391</PDA_PORTION>
<GESQUALITAET/>
<AUSFALLSEINSCH/>
<ANMERKUNGEN/>
<LAGE_NORD>48,2281993</LAGE_NORD>
<LAGE_OST>14,2394658</LAGE_OST>
<HOEHE/>
<GPS_STATUS/>
<KOORD_SYSTEM/>
<KOORD_EINHEIT/>
<PLZ/>
<ORT/>
<STR_ORTSTEIL/>
<NUMMER/>
<BEZEICHNUNG/>
<GRUNDBESITZER/>
<TELENR/>
<ERREICHBARKEIT/>
<ATT_LIST>
<ATTRIB ATTNAM="BAUWEISE">
<VALUE>E-Mast</VALUE>
</ATTRIB>
<ATTRIB ATTNAM="HOLZART">
<VALUE>KIEFER</VALUE>
</ATTRIB>
</ATT_LIST>
<MZ_LIST>
<MAS_ZU MZ_NAM="AUSHOLZEN">
<VALUE>J</VALUE>
<BEMERKUNG/>
<INSP_AM/>
<INSP_VON/>
<DONE_AM>N</DONE_AM>
<DONE_VOM/>
<URSACHE>2</URSACHE>
<DRINGLICH>2</DRINGLICH>
<ZIEL_DAT/>
<MZ_PARAM_LIST/>
</MAS_ZU>
<MAS_ZU MZ_NAM="ALLGEMEIN-ANMERKUNG">
<VALUE>2 Isolatoren</VALUE>
<BEMERKUNG/>
<INSP_AM/>
<INSP_VON/>
<DONE_AM/>
<DONE_VOM/>
<URSACHE>2</URSACHE>
<DRINGLICH/>
<ZIEL_DAT/>
<MZ_PARAM_LIST/>
</MAS_ZU>
<MAS_ZU MZ_NAM="Stange erdfaul/hohl">
<VALUE>J</VALUE>
<BEMERKUNG/>
<INSP_AM/>
<INSP_VON/>
<DONE_AM/>
<DONE_VOM/>
<URSACHE/>
<DRINGLICH/>
<ZIEL_DAT/>
<MZ_PARAM_LIST/>
</MAS_ZU>
<MAS_ZU MZ_NAM="Masttyp nicht normgerecht">
<VALUE>J</VALUE>
<BEMERKUNG/>
<INSP_AM/>
<INSP_VON/>
<DONE_AM/>
<DONE_VOM/>
<URSACHE/>
<DRINGLICH/>
<ZIEL_DAT/>
<MZ_PARAM_LIST/>
</MAS_ZU>
</MZ_LIST>
</INSP_PDA>
<INSP_PDA>
<SYSID>900000437</SYSID>
<INSPECTOR/>
<INSDAT>20001223</INSDAT>
<INSOBJ_TYP>MSP-Mast</INSOBJ_TYP>
<INSOBJ_ID1>BAM / Bad Aussee / Bad Mitterndorf/Grundlsee</INSOBJ_ID1>
<INSOBJ_ID2>MITTERNDORF 2 - M 259</INSOBJ_ID2>
<INSOBJ_ID3>239</INSOBJ_ID3>
<INSOBJ_NAME>259</INSOBJ_NAME>
<PDA_PORTION>0000000391</PDA_PORTION>
<GESQUALITAET/>
<AUSFALLSEINSCH/>
<ANMERKUNGEN/>
<LAGE_NORD>48,2281993</LAGE_NORD>
<LAGE_OST>14,2394658</LAGE_OST>
<HOEHE/>
<GPS_STATUS/>
<KOORD_SYSTEM/>
<KOORD_EINHEIT/>
<PLZ/>
<ORT/>
<STR_ORTSTEIL/>
<NUMMER/>
<BEZEICHNUNG/>
<GRUNDBESITZER/>
<TELENR/>
<ERREICHBARKEIT/>
<ATT_LIST>
<ATTRIB ATTNAM="BAUWEISE">
<VALUE>E-Mast</VALUE>
</ATTRIB>
<ATTRIB ATTNAM="HOLZART">
<VALUE>KIEFER</VALUE>
</ATTRIB>
</ATT_LIST>
<MZ_LIST>
<MAS_ZU MZ_NAM="AUSHOLZEN">
<VALUE>J</VALUE>
<BEMERKUNG/>
<INSP_AM/>
<INSP_VON/>
<DONE_AM>N</DONE_AM>
<DONE_VOM/>
<URSACHE>2</URSACHE>
<DRINGLICH>2</DRINGLICH>
<ZIEL_DAT/>
<MZ_PARAM_LIST/>
</MAS_ZU>
<MAS_ZU MZ_NAM="ALLGEMEIN-ANMERKUNG">
<VALUE>2 Isolatoren</VALUE>
<BEMERKUNG/>
<INSP_AM/>
<INSP_VON/>
<DONE_AM/>
<DONE_VOM/>
<URSACHE>2</URSACHE>
<DRINGLICH/>
<ZIEL_DAT/>
<MZ_PARAM_LIST/>
</MAS_ZU>
<MAS_ZU MZ_NAM="Stange erdfaul/hohl">
<VALUE>J</VALUE>
<BEMERKUNG/>
<INSP_AM/>
<INSP_VON/>
<DONE_AM/>
<DONE_VOM/>
<URSACHE/>
<DRINGLICH/>
<ZIEL_DAT/>
<MZ_PARAM_LIST/>
</MAS_ZU>
<MAS_ZU MZ_NAM="Masttyp nicht normgerecht">
<VALUE>J</VALUE>
<BEMERKUNG/>
<INSP_AM/>
<INSP_VON/>
<DONE_AM/>
<DONE_VOM/>
<URSACHE/>
<DRINGLICH/>
<ZIEL_DAT/>
<MZ_PARAM_LIST/>
</MAS_ZU>
</MZ_LIST>
</INSP_PDA>
</INSOBJ>
Thanks for help.
With best regards
Nicole -
How to remove the prolog from XML in Oracle?
Our system works like this:
1. Pass in a piece of XML to the database as a CLOB
2. Database converts this to XMLTYPE (stored as a CLOB (you can skip over this, Marco *{;-) ))
3. An application then reads the XML from the database and inserts it into another bit of XML
4. The application continues its processing based on this new composite XML.
Up until now, the XML loaded into the database in step 1 (by various systems) has never contained a prolog. However, a new system has come along and is now passing in a prolog. This causes problems for the application in step 3.
Aside from trying to get the new system to not pass in the prolog, is there a way to remove it from within Oracle?
The two solutions I've come up with don't feel elegant:
1. Use XMLTABLE to extract the main root node (which could be different, depending on which system sent in the data, and could change)
2. Convert the prolog into a comment, using REPLACE, before converting the CLOB into an XMLTYPE.
If I was forced to use one of these methods, I'd go with 2, but I really, really hope there's a better way of doing it.
Has anyone got any other suggestions, please?
PS. We're currently on 10.2.0.4 and are shortly about to move to 11.2.0.3, but the solution has to work on both versions, for added fun and excitement!This is the error the application gives: "Error obtaining Additional Info SAX Exception : No processing instruction starts with 'xml'" which the app dev says is due to the presence of the prolog in the middle of the xml the app has build up.So basically, the app just "pastes" the XML in the middle of another without caring about the structure? What kind of design is that?
IMO, the app has to be fixed, not the input XML.
Plenty about how to add the prolog, nothing about how to remove it!You can use XMLQuery function to extract the root element :
SQL> create table tmp_xml3 of xmltype
2 xmltype store as basicfile clob;
Table created
SQL> insert into tmp_xml3 values (xmltype('<?xml version="1.0" encoding="UTF-8"?><root/>'));
1 row inserted
SQL> select * from tmp_xml3;
SYS_NC_ROWINFO$
<?xml version="1.0" encoding="UTF-8"?><root/>
SQL>
SQL> select xmlquery('*' passing object_value returning content)
2 from tmp_xml3;
XMLQUERY('*'PASSINGOBJECT_VALU
<root/>
Edited by: odie_63 on 22 août 2012 15:26 -
How to remove empty lines from xml files after removing nodes from document
<pre>
Hi
<b>i have xml document, which is shown below
after removing some nodes from the document ,i am getting empty lines in place of removed nodes,how to resolve this and get the proper xml document without any errors</b>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE Message SYSTEM "TRD01.dtd">
<Message>
<Header>
<CounterPartyType>CLIENT</CounterPartyType>
<CreationTime>20134455</CreationTime>
<ErrorCode>363 </ErrorCode>
<ErrorEnterPriseId>N</ErrorEnterPriseId>
<ErrorStatus>1</ErrorStatus>
<ErrorSystemId>STL</ErrorSystemId>
<ErrorTimes>31</ErrorTimes>
<MessageType>T</MessageType>
<RecipientEnterpriseId>N</RecipientEnterpriseId>
<RecipentSystemId>EXM</RecipentSystemId>
<Remarks>REMARSK</Remarks>
<SenderEnterpriseId>N</SenderEnterpriseId>
<SenderSystemId>TR</SenderSystemId>
</Header>
</Message>
<ErrorCode>363 </ErrorCode>
<ErrorEnterPriseId>NIHK</ErrorEnterPriseId>
<ErrorStatus>1</ErrorStatus>
<ErrorSystemId>STL</ErrorSystemId>
<ErrorTimes>31</ErrorTimes>
XPathExpression expression5 = xpath.compile(xmlpath5);
Object result5 = expression5.evaluate(doc, XPathConstants.NODE);
Node node5 = (Node) result5;
node5.getParentNode().removeChild(node5);
XPathExpression expression6 = xpath.compile(xmlpath6);
Object result6 = expression6.evaluate(doc, XPathConstants.NODE);
Node node6=(Node) result6;
node6.getParentNode().removeChild(node6);
XPathExpression expression7 = xpath.compile(xmlpath7);
Object result7 = expression7.evaluate(doc, XPathConstants.NODE);
Node node7=(Node) result7;
node7.getParentNode().removeChild(node7);
doc.normalize();
doc.normalizeDocument();
TransformerFactory tf = TransformerFactory.newInstance();
Transformer t = tf.newTransformer();
t.setOutputProperty(OutputKeys.INDENT, "yes");
t.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
t.setOutputProperty(OutputKeys.METHOD,"xml");
t.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
the xml output i am getting is
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Message>
<Header>
<CounterPartyType>CLIENT</CounterPartyType>
<CreationTime>20134455</CreationTime>
<MessageType>TRD01</MessageType>
<RecipientEnterpriseId>N</RecipientEnterpriseId>
<RecipentSystemId>STL</RecipentSystemId>
<Remarks>REMARSK</Remarks>
<SenderEnterpriseId>N</SenderEnterpriseId>
<SenderSystemId>T</SenderSystemId>
</Header>
</Message>
<b>could you please let me know how to avoid empty lines in the xml doucment output</b>
this is the method i am using to get the result
public void ValidateRecord(String xml){
try{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder db = factory.newDocumentBuilder();
//parse file into DOM
/*DOMParser parser = new DOMParser();
parser.setErrorStream(System.err);
parser.setValidationMode(DTD_validation);
parser.showWarnings(true);*/
System.out.println ("HI THIS xml is validation "+xml);
Resolver res = new Resolver();
db.setEntityResolver(res);
Document doc = db.parse(new InputSource(new StringReader(xml)));
XPathFactory xpf = XPathFactory.newInstance();
XPath xpath = xpf.newXPath();
// XPathExpression expression = xpath.compile("//A/B[C/E/text()=13]");
String xmlpath="/Message/Header/CounterPartyType/text()";
String xmlpath1="/Message/Header/RecipentSystemId/text()";
String xmlpath2="/Message/Header/ErrorSystemId/text()";
XPathExpression expression = xpath.compile(xmlpath);
XPathExpression expression1 = xpath.compile(xmlpath2);
Object result = expression.evaluate(doc, XPathConstants.NODE);
Object result1 = expression1.evaluate(doc, XPathConstants.NODE);
Node node = (Node) result;
Node node1 = (Node) result1;
System.out.println("the values of the string is " +node.getNodeValue());
System.out.println("the values of the string is " +node1.getNodeValue());
// for (int i = 0; i < nodes.getLength(); i++) {
//System.out.println(nodes.item(i).getNodeValue());
// CAHNGING THE RECEIPENT NODE
XPathExpression expression2 = xpath.compile(xmlpath1);
Object result2 = expression2.evaluate(doc, XPathConstants.NODE);
Node node2 = (Node) result2;
System.out.println(node2);
node2.setNodeValue(node1.getNodeValue());
System.out.println(node2);
//removing the nodes from document
String xmlpath3="/Message/Header/ErrorCode";
String xmlpath4="/Message/Header/ErrorEnterPriseId";
String xmlpath5="/Message/Header/ErrorStatus";
String xmlpath6="/Message/Header/ErrorSystemId";
String xmlpath7="/Message/Header/ErrorTimes";
XPathExpression expression3 = xpath.compile(xmlpath3);
Object result3 = expression3.evaluate(doc, XPathConstants.NODE);
Node node3 = (Node) result3;
node3.getParentNode().removeChild(node3);
XPathExpression expression4 = xpath.compile(xmlpath4);
Object result4 = expression4.evaluate(doc, XPathConstants.NODE);
Node node4 = (Node) result4;
System.out.println("node value");
System.out.println(node4.getParentNode().getNodeName());
node4.getParentNode().removeChild(node4);
XPathExpression expression5 = xpath.compile(xmlpath5);
Object result5 = expression5.evaluate(doc, XPathConstants.NODE);
Node node5 = (Node) result5;
node5.getParentNode().removeChild(node5);
XPathExpression expression6 = xpath.compile(xmlpath6);
Object result6 = expression6.evaluate(doc, XPathConstants.NODE);
Node node6=(Node) result6;
node6.getParentNode().removeChild(node6);
XPathExpression expression7 = xpath.compile(xmlpath7);
Object result7 = expression7.evaluate(doc, XPathConstants.NODE);
Node node7=(Node) result7;
node7.getParentNode().removeChild(node7);
// Node b13Node = (Node) expression.evaluate(doc, XPathConstants.NODE);
//b13Node.getParentNode().removeChild(b13Node);
doc.normalize();
doc.normalizeDocument();
TransformerFactory tf = TransformerFactory.newInstance();
Transformer t = tf.newTransformer();
t.setOutputProperty(OutputKeys.INDENT, "yes");
t.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
t.setOutputProperty(OutputKeys.METHOD,"xml");
t.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
t.transform(new DOMSource(doc), new StreamResult(System.out));
catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
</pre>
Edited by: user12185243 on Apr 6, 2013 6:38 AM
Edited by: user12185243 on Apr 6, 2013 6:41 AM
Edited by: user12185243 on Apr 6, 2013 6:43 AM
Edited by: user12185243 on Apr 6, 2013 6:45 AM
Edited by: user12185243 on Apr 6, 2013 9:00 AMeither this way we can do this
1)
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
<b> factory.setIgnoringElementContentWhitespace(true); </b>
DocumentBuilder db = factory.newDocumentBuilder();
or
2)
java.io.StringWriter sw = new java.io.StringWriter();
StreamResult sr = new StreamResult(sw);
t.transform(new DOMSource(doc), sr);
String xml1 = sw.toString().trim();
<b> xml1=xml1.replaceAll("\\s",""); </b>
System.out.println(xml1.trim()); -
Firefox removes href attribute from anchor tag on copy paste
Hi Support,
I have a text along with the image used as a hyperlink as follows.
"Sample Text.<a href="javascript:myfunction()"><img title="sample image" src="sample.gif" /></a>"
When i copy the above text and paste it inside a HTML Control (for e.g. iframe), the control removes the href attribute of 'anchor' tag. It happens only with firefox and safari. It is working correctly in internet explorer.
"Sample Text.<a ><img title="sample image" src="sample.gif" /></a>"
Is there any solution for this.? Awaiting for sooner response
Try clicking on the below link
http://screencast.com/t/sXq6BcZvJBI tested this in Gmail compose, and what I see is: regular links (href="url") are preserved during copy/paste, but javascript links (href="javascript:") are dropped/cleared.
I don't know whether this is by design. One place to research that would be [https://bugzilla.mozilla.org/]. -
How to remove white spaces from XML content using Coldfusion?
Hi,
Can anybody help me in removing white spaces in between the tags from the below XML content using coldfusion?
XML content:
<?xml version="1.0" encoding="UTF-8"?> <chart showdates="true" today="08/12/2009"> <phases> <phase color="CCFFCC" name="Funded"/> <phase color="CDCD67" name="Concept"/> <phase color="99CCFF" name="Feasibility"/> <phase color="0099FF" name="Development"/> <phase color="0099FF" name="Development"/> <phase color="CC99FF" name="Close-out"/> <phase color="909090" name="Sustaining"/> </phases><program name=""> <project enddate=" 30/03/2007 " id="43250" startdate=" 28/02/2006 "> <version enddate=" 30/03/2007 " number=" 1" startdate=" 28/02/2006 "> <phase color="CCFFCC" currentdate="23/03/2006" name="Project Start" plandate="28/02/2006" type="phase"/> <phase color="99CCFF" currentdate="04/04/2006" name="Feasibility Closure" plandate="31/05/2006" type="phase"/> <phase color="0099FF" currentdate="29/03/2007" name="Commercialization" plandate="30/12/2006" type="phase"/> <phase color="CC99FF" currentdate="30/03/2007" name="Project Closed" plandate="30/03/2007" type="phase"/> <phase color="909090" currentdate="" name="Obsolescence" plandate="" type="phase"/> </version> </project> </program> </chart>
Output I am expecting is like below,
<?xml version="1.0" encoding="UTF-8"?><chart showdates="true" today="08/12/2009"><phases><phase color="CCFFCC" name="Funded"/><phase color="CDCD67" name="Concept"/><phase color="99CCFF" name="Feasibility"/><phase color="0099FF" name="Development"/><phase color="0099FF" name="Development"/><phase color="CC99FF" name="Close-out"/><phase color="909090" name="Sustaining"/></phases><program name=""><project enddate=" 30/03/2007 " id="43250" startdate=" 28/02/2006 "><version enddate=" 30/03/2007 " number=" 1" startdate=" 28/02/2006 "><phase color="CCFFCC" currentdate="23/03/2006" name="Project Start" plandate="28/02/2006" type="phase"/><phase color="99CCFF" currentdate="04/04/2006" name="Feasibility Closure" plandate="31/05/2006" type="phase"/><phase color="0099FF" currentdate="29/03/2007" name="Commercialization" plandate="30/12/2006" type="phase"/><phase color="CC99FF" currentdate="30/03/2007" name="Project Closed" plandate="30/03/2007" type="phase"/><phase color="909090" currentdate="" name="Obsolescence" plandate="" type="phase"/></version> </project></program></chart>
Thanks in advance,
Regards,
Manoz.Daverms,
Thanks for the quick turn around..
I have applied the solution what you suggested above (<cfprocessingdrirective suppresswhitespaces="yes"), still whitespaces are existing in my output.
The output what I am getting is,
(blue color part is my output & red color indicates whitespaces)
<?xml version="1.0" encoding="UTF-8"?>
<chart showdates="true" today="09/12/2009">
<phases>
<phase color="CCFFCC" name="Funded"/>
<phase color="CDCD67" name="Concept"/>
<phase color="99CCFF" name="Feasibility"/>
<phase color="0099FF" name="Development"/>
<phase color="0099FF" name="Development"/>
<phase color="CC99FF" name="Close-out"/>
<phase color="909090" name="Sustaining"/>
</phases>
<program name="">
<project enddate=" 01/01/2010 " id="12059" startdate=" 20/06/2003 ">
<version enddate=" 01/01/2010 " number=" 1" startdate=" 20/06/2003 ">
<phase color="CCFFCC" currentdate="20/06/2003" name="Project Start" plandate="20/06/2003" type="phase"/>
<phase color="CDCD67" currentdate="" name="Concept Closure" plandate="" type="phase"/>
<phase color="99CCFF" currentdate="20/06/2003" name="Feasibility Closure" plandate="20/06/2003" type="phase"/>
<phase color="F0FF00" currentdate="" name="Alpha Test" plandate="" type="milestone"/>
<phase color="F0FF00" currentdate="26/07/2004" name="Beta Test" plandate="31/05/2004" type="milestone"/>
<phase color="0099FF" currentdate="29/06/2005" name="Commercialization" plandate="08/12/2004" type="phase"/>
<phase color="CC99FF" currentdate="24/02/2006" name="Project Closed" plandate="01/01/2010" type="phase"/>
</version>
<subproject enddate=" 16/10/2008 " id="11809" name="espWatcher Pricing Toolkit" startdate=" 01/08/2003 ">
<version enddate=" 16/10/2008 " number=" 1" startdate=" 01/08/2003 ">
<phase color="CCFFCC" currentdate="01/08/2003" name="Project Start" plandate="01/08/2003" type="phase"/>
<phase color="99CCFF" currentdate="" name="Feasibility Closure" plandate="" type="phase"/>
<phase color="0099FF" currentdate="15/06/2005" name="Commercialization" plandate="08/12/2004" type="phase"/>
<phase color="CC99FF" currentdate="16/10/2008" name="Project Closed" plandate="16/10/2008" type="phase"/>
</version>
</subproject>
<subproject enddate=" 31/12/2070 " id="35704" name="espWatcher version 2 (2005)" startdate=" 01/01/2005 ">
<version enddate=" 31/12/2070 " number=" 1" startdate=" 01/01/2005 ">
<phase color="CCFFCC" currentdate="01/01/2005" name="Project Start" plandate="01/01/2005" type="phase"/>
<phase color="99CCFF" currentdate="01/07/2005" name="Feasibility Closure" plandate="01/07/2005" type="phase"/>
<phase color="0099FF" currentdate="31/03/2006" name="Commercialization" plandate="31/03/2006" type="phase"/>
<phase color="CC99FF" currentdate="31/12/2070" name="Project Closed" plandate="31/12/2070" type="phase"/>
</version>
</subproject>
</project>
</program>
</chart>
However this solution removes most of the whitespaces, I want exact output as flash file is expecting so..
Where ever I am calling the CF functions, there I am getting the whitespaces. like below cases.
startdate="#getProjectStartDate(sProjectIdList)#" -> output I am getting for this statement is -> " 12/09/2009 "
Please assist me...
Regards,
Manoz. -
How do i query attributes from xml documents
I want to to query only details in Issue id="705230" (id is an attribute)
I tried this, but does not help. I should be able to query the value of core_org_id attribute
select extract(CLOB_DATA, 'PcrDocument/PcrOrganization/core_org_id) CORE_ORG_ID from from pcr_files where existsNode(CLOB_DATA, 'PcrDocument/PcrOrganization/Issues/Issue[@id="705230"]')=1;
-- does not return anything....
I tried to extract value for R_DATE & R_REVIEW_DATE for issue id=705230, but iam not able to.
Data for all the issues is retured.
Here is the query used...
select extract(CLOB_DATA, 'PcrDocument/PcrOrganization/Issues/Issue') ISSUE from pcr_files where existsNode(CLOB_DATA, 'PcrDocument/PcrOrganization/Issues/Issue[@id="705230"]')=1;
Here is the part of XML document iam querying on...
- <ns1:PcrDocument id="PCR-13562" title="EU Disclosures - EC 1060/2009" version="1" pcrPublishDate="2012-01-11T12:49:02" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns1="http://integration.mysite.com/ServiceSchema/v3">
- <ns1:PcrOrganization core_org_id="345840">
<ns1:PcrLinkedTo value="ISSUE" />
- <ns1:AdditionalInfo>
<ns1:Info type="AdditionalInfo_QuartelyReport_URL"><br></br>MGH</ns1:Info>
</ns1:AdditionalInfo>
- <ns1:Issues>
- <ns1:Issue id="705230">
- <ns1:AdditionalInfo>
<ns1:Info type="R_DATE">Credit Release Date: 09-Apr-2010</ns1:Info>
<ns1:Info type="R_REVIEW_DATE">Credit Last Review Date: 12-Oct-2011</ns1:Info>
<ns1:Info type="AdditionalInfo_QuartelyReport_URL"><br></br>MGH</ns1:Info>
</ns1:AdditionalInfo>
- <ns1:IssueDetail id="114766798">
- <ns1:AdditionalInfo>
<ns1:Info type="R_DATE">Credit Release Date: 09-Apr-2010</ns1:Info>
<ns1:Info type="R_REVIEW_DATE">Credit Last Review Date: 12-Oct-2011</ns1:Info>
<ns1:Info type="AdditionalInfo_QuartelyReport_URL"><br></br>MGH</ns1:Info>
</ns1:AdditionalInfo>
</ns1:IssueDetail>
</ns1:Issue>
- <ns1:Issue id="727193">
- <ns1:AdditionalInfo>
<ns1:Info type="R_DATE">Credit Release Date: 09-Apr-2010</ns1:Info>
<ns1:Info type="R_REVIEW_DATE">Credit Last Review Date: 12-Oct-2011</ns1:Info>
<ns1:Info type="AdditionalInfo_QuartelyReport_URL"><br></br>MGH</ns1:Info>
</ns1:AdditionalInfo>
- <ns1:IssueDetail id="117994574">
- <ns1:AdditionalInfo>
<ns1:Info type="R_DATE">Credit Release Date: 09-Apr-2010</ns1:Info>
<ns1:Info type="R_REVIEW_DATE">Credit Last Review Date: 12-Oct-2011</ns1:Info>
<ns1:Info type="AdditionalInfo_QuartelyReport_URL"><br></br>MGH</ns1:Info>
</ns1:AdditionalInfo>
</ns1:IssueDetail>
</ns1:Issue>
</ns1:Issues>
</ns1:PcrOrganization>
</ns1:PcrDocument>I did not include the name space declaration for it is working fine. Really? Then I suppose you must be using a schema-based XMLType column?
Is it Object-Relational or Binary XML storage?
You mentioned it is depricated in 11.2, but iam able to run it on 11.2.Deprecated doesn't mean it ceases functioning.
Any suggestions to covert this to XMLTable/XMLQuery format please..If you read the documentation, it covers this part too ;)
Example :
create table tmp_xml of xmltype;
insert into tmp_xml values(
xmltype('<ns1:PcrDocument id="PCR-13562" title="EU Disclosures - EC 1060/2009" version="1" pcrPublishDate="2012-01-11T12:49:02" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns1="http://integration.mysite.com/ServiceSchema/v3">
<ns1:PcrRatingDetails>
<ns1:LeadAnalyst>
<ns1:FirstName>xxxxx</ns1:FirstName>
<ns1:MiddleName/>
<ns1:LastName>xxxxxx</ns1:LastName>
<ns1:Title>Director</ns1:Title>
<ns1:Label>Primary Analyst</ns1:Label>
<ns1:Telephone>xxxxxxxxxxxx</ns1:Telephone>
<ns1:Email>[email protected]</ns1:Email>
<ns1:Address>
<ns1:Line1>Main Tower</ns1:Line1>
<ns1:Line2>Neue Mainzer Strasse</ns1:Line2>
<ns1:City>FFT</ns1:City>
<ns1:State/>
<ns1:ZipCode>99999</ns1:ZipCode>
<ns1:Country>Germany</ns1:Country>
</ns1:Address>
</ns1:LeadAnalyst>
<ns1:RatingApprover>
<ns1:FirstName>Nick</ns1:FirstName>
<ns1:MiddleName/>
<ns1:LastName>Mate</ns1:LastName>
</ns1:RatingApprover>
</ns1:PcrRatingDetails>
<ns1:PcrOrganization core_org_id="345840">
<ns1:PcrLinkedTo value="ISSUE"/>
<ns1:AdditionalInfo>
<ns1:Info type="AdditionalInfo_QuartelyReport_URL">
<br/>
<A href="http://www.mysite.com/rts/articles/en/us/?articleType=HTML&assetID=1245321070686" target="_blank">MGH</A>
</ns1:Info>
</ns1:AdditionalInfo>
<ns1:Issues>
<ns1:Issue id="705230">
<ns1:AdditionalInfo>
<ns1:Info type="R_DATE">Credit Release Date: 09-Apr-2010</ns1:Info>
<ns1:Info type="R_REVIEW_DATE">Credit Last Review Date: 12-Oct-2011</ns1:Info>
<ns1:Info type="AdditionalInfo_QuartelyReport_URL">
<br/>
<A href="http://www.mysite.com/rts/articles/en/us/?articleType=HTML&assetID=1245321070686" target="_blank">MGH</A>
</ns1:Info>
</ns1:AdditionalInfo>
<ns1:IssueDetail id="114766798">
<ns1:AdditionalInfo>
<ns1:Info type="R_DATE">Credit Release Date: 09-Apr-2010</ns1:Info>
<ns1:Info type="R_REVIEW_DATE">Credit Last Review Date: 12-Oct-2011</ns1:Info>
<ns1:Info type="AdditionalInfo_QuartelyReport_URL">
<br/>
<A href="http://www.mysite.com/rts/articles/en/us/?articleType=HTML&assetID=1245321070686" target="_blank">MGH</A>
</ns1:Info>
</ns1:AdditionalInfo>
</ns1:IssueDetail>
</ns1:Issue>
<ns1:Issue id="727193">
<ns1:AdditionalInfo>
<ns1:Info type="R_DATE">Credit Release Date: 09-Apr-2010</ns1:Info>
<ns1:Info type="R_REVIEW_DATE">Credit Last Review Date: 12-Oct-2011</ns1:Info>
<ns1:Info type="AdditionalInfo_QuartelyReport_URL">
<br/>
<A href="http://www.mysite.com/rts/articles/en/us/?articleType=HTML&assetID=1245321070686" target="_blank">MGH</A>
</ns1:Info>
</ns1:AdditionalInfo>
<ns1:IssueDetail id="117994574">
<ns1:AdditionalInfo>
<ns1:Info type="R_DATE">Credit Release Date: 09-Apr-2010</ns1:Info>
<ns1:Info type="R_REVIEW_DATE">Credit Last Review Date: 12-Oct-2011</ns1:Info>
<ns1:Info type="AdditionalInfo_QuartelyReport_URL">
<br/>
<A href="http://www.mysite.com/rts/articles/en/us/?articleType=HTML&assetID=1245321070686" target="_blank">MGH</A>
</ns1:Info>
</ns1:AdditionalInfo>
</ns1:IssueDetail>
</ns1:Issue>
</ns1:Issues>
</ns1:PcrOrganization>
</ns1:PcrDocument>')
SQL> set long 10000
SQL>
SQL> select x1.analyst
2 , x1.chair
3 , x1.core_org_id
4 , x2.*
5 from tmp_xml t
6 , xmltable(
7 xmlnamespaces(default 'http://integration.mysite.com/ServiceSchema/v3')
8 , '/PcrDocument'
9 passing t.object_value
10 columns analyst xmltype path 'PcrRatingDetails/LeadAnalyst'
11 , chair xmltype path 'PcrRatingDetails/RatingApprover'
12 , core_org_id number path 'PcrOrganization/@core_org_id'
13 , issues xmltype path 'PcrOrganization/Issues/Issue'
14 ) x1
15 , xmltable(
16 xmlnamespaces(default 'http://integration.mysite.com/ServiceSchema/v3')
17 , '/Issue'
18 passing x1.issues
19 columns issue number path '@id'
20 , rating_date varchar2(40) path 'AdditionalInfo/Info[@type="R_DATE"]'
21 , rating_review_date varchar2(40) path 'AdditionalInfo/Info[@type="R_REVIEW_DATE"]'
22 , issue_detail number path 'IssueDetail/@id'
23 , id_rating_date varchar2(40) path 'IssueDetail/AdditionalInfo/Info[@type="R_DATE"]'
24 , id_rating_review_date varchar2(40) path 'IssueDetail/AdditionalInfo/Info[@type="R_REVIEW_DATE"]'
25 ) x2
26 where x2.issue = 705230
27 ;
ANALYST CHAIR CORE_ORG_ID ISSUE RATING_DATE RATING_REVIEW_DATE ISSUE_DETAIL ID_RATING_DATE ID_RATING_REVIEW_DATE
<LeadAnalyst xmlns="http://integration.mysite.com/ServiceSchema/v3"> <RatingApprover xmlns="http://integration.mysite.com/ServiceSchema/v3"> 345840 705230 Credit Release Date: 09-Apr-2010 Credit Last Review Date: 12-Oct-2011 114766798 Credit Release Date: 09-Apr-2010 Credit Last Review Date: 12-Oct-2011
<FirstName>xxxxx</FirstName> <FirstName>Nick</FirstName>
<MiddleName/> <MiddleName/>
<LastName>xxxxxx</LastName> <LastName>Mate</LastName>
<Title>Director</Title> </RatingApprover>
<Label>Primary Analyst</Label>
<Telephone>xxxxxxxxxxxx</Telephone>
<Email>[email protected]</Email>
<Address>
<Line1>Main Tower</Line1>
<Line2>Neue Mainzer Strasse</Line2>
<City>FFT</City>
<State/>
<ZipCode>99999</ZipCode>
<Country>Germany</Country>
</Address>
</LeadAnalyst> -
How to remove default comment from XML output
Hi,
I have a requirement to generate the XML report with XML output(Not PDF). Everything is working fine except I am getting one comment line "<!--Generated by Oracle Reports version 6.0.8.28.0--> which is not required and I want to remove this line. This report will be run through Oracle Apps 11i.
Thanks.Hi,
There is option to change the "Prolog Value" but nothing is there to remove the comment.
Thanks -
How to remove xmlns tag in Node level
Hi Experts!
How to remove xmlns tag in xml file, where only xmlns="". I do not want to remove if xmlns contains a value.
I am using below xslt mapping, but it is removing all xmlns tags in a xml file. I want to remove only xmlns="" .
please help me on this.
Here is the code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.arconw.com/XI/XSLT_Library/XmlNamespacePrefixRemoval"
version="1.0">
<xsl:output method = "xml" />
<xsl:template match="/">
<xsl:apply-templates select="*" mode="remprefix"/>
</xsl:template>
<xsl:template match="*" mode="remprefix">
<xsl:variable name="newname" select="local-name(.)"/>
<xsl:element name="{$newname}" namespace ="{namespace-uri()}">
<xsl:apply-templates mode="copyall" select="@*|comment()|processing-instruction()|text()"/>
<xsl:apply-templates select="*" mode="remprefix"/>
</xsl:element>
</xsl:template>
<xsl:template mode="copyall" match="@*|comment()|processing-instruction()|text()">
<xsl:copy>
<xsl:apply-templates mode="copyall" select="@*|comment()|processing-instruction()|text()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Thanks,
HariHi Hari,
Please try this as an option:
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Map;
import com.sap.aii.mapping.api.StreamTransformation;
import com.sap.aii.mapping.api.StreamTransformationException;
public class RemoveBlankNS implements StreamTransformation {
private Map _param;
public void setParameter(Map param) {
_param = param;
public void execute(InputStream in, OutputStream out) throws StreamTransformationException {
try {
byte[] bytes = new byte[in.available()];
in.read(bytes, 0, in.available());
String payload = new String(bytes, "UTF-8");
payload = payload.replaceAll(" xmlns=\"\"", "");
out.write(payload.getBytes("UTF-8"));
} catch (Exception e) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
throw new StreamTransformationException(sw.toString());
Thanks,
-Russ -
How to remove xmlns in node level
Hi Experts!
How to remove xmlns in node level in response xml file. I tried to use AF_Modules/XMLAnonymizerBean, but it did not work.
Can you please help me out on this.
I want to remvoe xmlns tag in LEVICOM
Eg:
- <Addenda>
- <LEVICOM xmlns="">
Thanks,
HariHi Expers!
Please help me out on this. The below xslt mapping working only to remove xmlns prefix in xml file, if parent having only one child. This code is not working if parent having multiple childs.
Eg: <parent>
<phild xmlns="">
test1
</phild>
</parent>
The above example working fine with below xslt mapping to remove xmlns tag.
Second scenarion not working
Eg: <parent>
<child1 xmlns="">
test1
</child1>
<child2 xmlns="">
test2
</child2>
</parent>
The above example is not working.
Here is the code:
You can remove the namespace prefixes using an XSLT mapping if they are causing problems with applications outside of XI.
Try the following code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.arconw.com/XI/XSLT_Library/XmlNamespacePrefixRemoval"
version="1.0">
<xsl:output method = "xml" />
<xsl:template match="/">
<xsl:apply-templates select="*" mode="remprefix"/>
</xsl:template>
<xsl:template match="*" mode="remprefix">
<xsl:variable name="newname" select="local-name(.)"/>
<xsl:element name="{$newname}" namespace ="{namespace-uri()}">
<xsl:apply-templates mode="copyall" select="@*|comment()|processing-instruction()|text()"/>
<xsl:apply-templates select="*" mode="remprefix"/>
</xsl:element>
</xsl:template>
<xsl:template mode="copyall" match="@*|comment()|processing-instruction()|text()">
<xsl:copy>
<xsl:apply-templates mode="copyall" select="@*|comment()|processing-instruction()|text()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Thanks,
Hari -
How to insert the data from XML to a table
Hi,
I'm using Oracle 10g Express Edition
I need help in How to insert the data from XML file into the table.
Below is the example i'm working on..
I have create ridb user with below mentioned privileges:
Account Status Locked Unlocked
Default Tablespace: USERS
Temporary Tablespace: TEMP
User Privileges :
Roles:
CONNECT
RESOURCE
Direct Grant System Privileges:
CREATE DATABASE LINK
CREATE MATERIALIZED VIEW
CREATE PROCEDURE
CREATE PUBLIC SYNONYM
CREATE ROLE
CREATE SEQUENCE
CREATE SYNONYM
CREATE TABLE
CREATE TRIGGER
CREATE TYPE
CREATE VIEW
& table is created TRIALZIPCODES below mentioned is the DDL:
CREATE TABLE TRIALZIPCODES
STATE_ABBR VARCHAR2(20) NOT NULL
, ZIP_CODE NUMBER(10, 0) NOT NULL
, ZIP_CODE_EXT VARCHAR2(20)
Below is the XML FILE: which is stored in C:\OracleProject Folder
File name: trial.xml
<?xml version="1.0" ?>
<metadata>
- <Zipcodes>
- <mappings Record="4">
<STATE_ABBREVIATION>CA</STATE_ABBREVIATION>
<ZIPCODE>94301</ZIPCODE>
</mappings>
- <mappings Record="5">
<STATE_ABBREVIATION>CO</STATE_ABBREVIATION>
<ZIPCODE>80323</ZIPCODE>
<ZIP_CODE_EXTN>9277</ZIP_CODE_EXTN>
</mappings>
</Zipcodes>
</metadata>
PL/SQL Procedure:which i'm trying to execute from SQLDeveloper
create or replace
PROCEDURE TRIAL AS
BEGIN
DECLARE
-- declare attributes
charString varchar2(80);
finalStr varchar2(4000) := null;
rowsp integer;
v_FileHandle UTL_FILE.FILE_TYPE;
l_context_handle dbms_xmlgen.ctxHandle;
insCtx DBMS_XMLStore.ctxType;
begin
-- DBMS_XMLGEN.setRowTag ( ctx IN ctxHandle, rowTag IN VARCHAR2);
-- DBMS_XMLGEN.setRowSetTag ( ctx IN ctxHandle, rowSetTag IN VARCHAR2);
-- the name of the table as specified in our DTD
DBMS_XMLGEN.SETROWSETTAG(l_context_handle,'zipcodes');
-- the name of the data set as specified in our DTD
DBMS_xmlgen.setRowTag(l_context_handle,'mappings');
-- for getting the output on the screen
dbms_output.enable(1000000);
-- open the XML document in read only mode
v_FileHandle := utl_file.fopen('c:/OracleProject','trial.xml', 'r');
loop
BEGIN
utl_file.get_line(v_FileHandle, charString);
exception
when no_data_found then
utl_file.fclose(v_FileHandle);
exit;
END;
dbms_output.put_line(charString);
if finalStr is not null then
finalStr := finalStr || charString;
else
finalStr := charString;
end if;
end loop;
-- for inserting the XML data into the table
insCtx := DBMS_XMLSTORE.NEWCONTEXT('RIDB.TRIALZIPCODES');
insCtx := DBMS_XMLSTORE.INSERTXML(insCtx, finalStr);
dbms_output.put_line('INSERT DONE '||TO_CHAR(rowsp));
DBMS_XMLStore.closeContext(insCtx);
END;
END TRIAL;
For the first time when i complied i got the errors as :
Procedure RIDB.PROCEDURE1@RIDB
Error(16,14): PLS-00201: identifier 'UTL_FILE' must be declared
Error(16,14): PL/SQL: Item ignored
Error(29,1): PLS-00320: the declaration of the type of this expression is incomplete or malformed
Error(29,1): PL/SQL: Statement ignored
Error(33,1): PL/SQL: Statement ignored
Error(33,19): PLS-00320: the declaration of the type of this expression is incomplete or malformed
Error(36,1): PL/SQL: Statement ignored
Error(36,17): PLS-00320: the declaration of the type of this expression is incomplete or malformed
So i logged in as sys & grant the permission to execute on UTL_FILE to ridb (user):
SQL Statement:
grant execute on utl_file to ridb
So, it got compiled successfully but when i execute it gives me error as:
Source does not have a runnable target.
What does this mean?
So I browse through forum & i got to know that i need to initial the UTL_FILE_DIR ="C:/OracleProject" in init.ora
So can i edit the init.ora with notepad.When i tried to do that it says permission denied
In my system it shows the init.ora file in path C:\oraclexe\app\oracle\product\10.2.0\server\config\scripts
but there is also other file initXETemp in the same path do i need to do the changes in it.
I have tried even editing the SPFILE as mentioned below:
C:\oraclexe\app\oracle\product\10.2.0\server\dbs\SPFILEEXE - I had edit this file using notepad & set the value of UTL_FILE_DIR ="C:/OracleProject". So next time when i restarted i'm unable to log on to the database.
So i had reinstall the software again.
Could you please let me know how to proceed..hi,
I have created the directory from sys database
CREATE or replace DIRECTORY XML_DIR2 AS 'C:\OracleProject';
& grant read,write access to the user
grant read,write on directory XML_DIR2 to RIDB;
& i had change the tag name in the xml file as shown below:
<?xml version = '1.0'?>
<metadata>
<Zipcodes>
<mappings Record="4">
<STABBRE>CA</STABBRE>
<ZIPCODE>94301</ZIPCODE>
</mappings>
<mappings Record="5">
<STABBRE>CO</STABBRE>
<ZIPCODE>80323</ZIPCODE>
<ZIPCODEEXT>9277</ZIPCODEEXT>
</mappings>
</Zipcodes>
</metadata>
TRIALZIPCODE table as shown below:
CREATE TABLE "RIDB"."TRIALZIPCODE"
( "STABBRE" VARCHAR2(20 BYTE),
"ZIPCODE" NUMBER(*,6) NOT NULL ENABLE,
"ZIPCODEEXT" NUMBER
) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS" ;
I have tried two methods as shown below:
Procedure 1:
create or replace
PROCEDURE TRIAL_V2 AS
BEGIN
DECLARE
-- declare attributes
charString varchar2(80);
finalStr varchar2(4000) := null;
rowsp integer;
v_FileHandle UTL_FILE.FILE_TYPE;
l_context_handle dbms_xmlgen.ctxHandle;
insCtx DBMS_XMLStore.ctxType;
cnt NUMBER;
xmldoc xmltype := xmltype( bfilename('XML_DIR2','trialxml.xml'), nls_charset_id('AL32UTF8') );
--XML_DIR VARCHAR2(40) := 'C:\\OracleProject';
BEGIN
insCtx := DBMS_XMLStore.newContext('DEV.TRIALZIPCODES');
DBMS_XMLStore.setUpdateColumn(insCtx, 'STABBRE');
DBMS_XMLStore.setUpdateColumn(insCtx, 'ZIPCODE');
DBMS_XMLStore.setUpdatecolumn(insCtx, 'ZIPCODEEXT');
DBMS_XMLStore.setRowTag(insCtx, 'mappings');
cnt := DBMS_XMLStore.insertXML(insCtx, xmldoc);
DBMS_XMLStore.closeContext(insCtx);
END;
Procedure 1 was compiled with out errors but when i execute i got the error as :
Source does not have a runnable target.
Procedure 2_
CREATE OR REPLACE PROCEDURE TRIAL_V3 AS
BEGIN
DECLARE
-- declare attributes
charString varchar2(80);
finalStr varchar2(4000) := null;
rowsp integer;
v_FileHandle UTL_FILE.FILE_TYPE;
l_context_handle dbms_xmlgen.ctxHandle;
insCtx DBMS_XMLStore.ctxType;
cnt NUMBER;
xmldoc xmltype := xmltype( bfilename('XML_DIR2','trialxml.xml'), nls_charset_id('AL32UTF8') );
--XML_DIR VARCHAR2(40) := 'C:\\OracleProject';
BEGIN
INSERT INTO trialzipcode (STABBRE, ZIPCODE, ZIPCODEEXT)
SELECT extractvalue(x.column_value, 'mappings/STABBRE'),
extractvalue(x.column_value, 'mappings/ZIPCODE'),
extractvalue(x.column_value, 'mappings/ZIPCODEEXT')
FROM TABLE(
XMLSequence(
EXTRACT(
xmltype( bfilename('XML_DIR2','trialxml.xml'), nls_charset_id('AL32UTF8') ),
'metadata/Zipcodes/mappings'
) x
END;
END TRIAL_V3;
Procedure 2 was complied without errors but when i execute i got the error as:
Connecting to the database RIDB.
ORA-22288: file or LOB operation FILEOPEN failed
The system cannot find the file specified.
ORA-06512: at "SYS.DBMS_LOB", line 523
ORA-06512: at "SYS.XMLTYPE", line 287
ORA-06512: at "RIDB.TRIAL_V3", line 12
ORA-06512: at line 2
Process exited.
Disconnecting from the database RIDB.
Could you please let me know how to proceed...
Maybe you are looking for
-
How can i sync my phone songs to the itunes library?
my old desktop is gone and i bought a new laptop, how can i synchronise my phone songs , photos , videos and contacts to my itunes? now my current itunes is empty and all my data is in my iphone.
-
Itunes will not install requesting adminstrator, which I am help
I am trying to install update for itunes. I keep getting need to log on as administrator, which I am. Please help.
-
I cant get it to turn off!
Mu iphone 5 is burning battery like crazy. I can't get it to stop -- I put it in lock, screen is dark, but it still runs warm and runs down the battery. Auto lock is set to 5 min, and it locks. I ran through an entire charge in 3 hours. What am I
-
Unwanted bookmarks when generating a PDF in FM 8.0
I have a issue about generating bookmarks when creating a PDF. After I have finished my book, I identify my bookmarks while in the PDF setup window. But for some reason, FM creates bookmarks for paragraph tags that I didn't choose. This is happening
-
Err: Non-valid period-application defined or object defined error orders
Hi Please solve above error When importing the Sales Order Data i got this error. I don't undertstand yet this error Please help me Kishor