Adding an XML doc with repeating tags
Hello,
Can anyone tell me how I take an XML document with a tag that can appear from 0-N times and map it to a database table? I am currently using a supertable and then using triggers to move data to the appropriate spot but am stuck on how to map tags that don't correspond 1-1.
My structure is like
<product>
<name>
<model>
<cost>
<feature>* (0-N)
<spec>* (0-N)
</product>
Thanks.
null
Do a getElementsByTagName on a node and do a
insert on each node found.
Similar Messages
-
Has anybody tried creating and validating a XML doc with XML Schema?
Hi,
Has anybody tried creating and validating a XML doc with XML Schema?With XMLBeans, an XML document may be created from and validated with an XML schema.
-
Create XML docs with hierarchy of tags and attr defined in databaste tables
Hi,
My problem is a little unique one. I want the ability to define the structure of the XML document (i.e. the hierarchy of element tags and attribute names) in the database tables. The values of tags and attributes will also be populated at runtime in tables.
Then write some generic API that reads the structure of the XML document through the database tables and spits out an XML document based on this structure and values stored in the tables.
So, basically, I want the tag names and values both to be values in the database rather than the tag names being the columns in database tables.
With this I should be able to have one procedure/function that can serve the purpose of creating XML documents with different structures by just specifying that structure in the form of database tables.
Almost all the Oracle XML utilities I read about, create XML docs based on a SQL query with tag names being columns in the database tables. Any help will be highly appreciated.
Thanks,
MonikaWhich database release are you using...
The computed constructors feature of XQuery may help.
-Mark -
Update passed in XML doc with pl/sql xmldom
Hi,
I have an xml document that is passed in through a stored procedure as CLOB. I'm trying to use the XMLParser and XMLDOM to add an additional node
The XML looks something like the following
<rowset>
<row>
<firstname>john</firstname>
</row>
<row>
<firstname>jane</firstname>
</row>
</rowset>
I need to loop through each of <mynames> nodes and then add another node <lastame> so it looks like the following
<rowset>
<row>
<firstname>john</firstname>
<lastame>smith</lastame>
</row>
<row>
<firstname>jane</firstname>
<lastame>smith</lastame>
</row>
</rowset>
I have the following code
parseClob XMLPARSER.Parser;
newNames XMLDOM.DOMDocument;
tempNode XMLDOM.DOMNode;
mye xmldom.domelement;
item_text xmldom.DOMText;
numofrows number;
nodeList xmldom.DOMNodeList;
newnode xmldom.domnode;
parseClob := xmlparser.newParser;
XMLPARSER.parseClob(parseClob,names);
newNames := XMLPARSER.getDocument(parseClob);
XMLPARSER.freeParser(parseClob);
nodeList := xslprocessor.selectNodes(xmldom.makeNode(newNames), '//rowset/row');
numOfRows := xmldom.getlength(nodeList)-1;
for i in 0..numOfRows LOOP
newnode := xmldom.item(nodeList, i);
--create the new node
mye := xmldom.createElement(newName, 'lastname');
--add it to the new node
tempNode := xmldom.appendChild(newnode, xmldom.makeNode(mye));
--update the text in the lastname
item_text := xmldom.createTextNode(newNames, 'smith');
tempNode := xmldom.appendChild(tempNode, xmldom.makeNode(item_text));
end loop;
what happens is that when i write out the newnode xml out to a buffer i see the <lastname> tag
but when i write out the newNames xml out to a buffer after the loop is finished the <lastname> tag is
missing. like it didn't update the newNames xml
I've seen lots of example on how to create an XML document with the DOM from scratch but nothing about updating
an passed in xml document. any help would be appreciatedUpdatexml is reference in Oracle 9i, I'm sorry i should have mentioned that I am using oracle 8i. Is there something you can use in oracle 8i?
-
Still problems serializing xml-docs with xml-parser for java v2.0.2.7
Hi !
I'm using the Oracle XML Parser 2.0.2.7.0 and get some problems when serializing the XMLDocument.
In one class (DOMOut) I parse a xml-file with the oracle.xml.parser.v2.DOMParser, then obtain the XMLDocument and write it to System.out
In another class (DOMIn) I fetch the XMLDocument from System.in, search for a given Element and print it's TextValue (if existing) to System.out
That is where the error occurs.
I get the XMLDocument from System.in but the returning NodeList from doc.getElementsByTagName() is empty. [nl.getLength()==0] even if it shouldn't be.
Look at this code and output:
[DOMOut]
DOMParser parser = new DOMParser();
parser.parse(url);
XMLDocument doc = (XMLDocument)parser.getDocument();
ObjectOutputStream out = new ObjectOutputStream(System.out);
out.writeObject(doc); out.flush();
[DOMIn]
ObjectInputStream in = new ObjectInputStream(System.in);
XMLDocument doc = (XMLDocument)in.readObject();
doc.print(System.out);
NodeList nl = doc.getElementsByTagName("Name");
System.out.println("Length of NodeList: "+nl.getLength());
if (nl.getLength()==0)
System.out.println(argv[0] + ": not in this document!");
else {
XMLNode node = (XMLNode) nl.item(nl.getLength()-1);
System.out.println(node.getNodeName() + ": " + (node.getFirstChild()).getNodeValue());
This is the relevant code.
I javac both classes and then do this:
java DOMOut xmltestfile.xml > xx
java DOMIn Name < xx
And get this as output:
<?xml version = '1.0'?>
<!DOCTYPE course [
<!ELEMENT course (Name,Dept,Instructor,Student)>
<!ELEMENT Name ((#PCDATA)*)*>
<!ELEMENT Dept ((#PCDATA)*)*>
<!ELEMENT Instructor (Name)>
<!ELEMENT Student (Name)*>
]>
<course>
<Name>Calculus</Name>
<Dept>Math</Dept>
<Instructor>
<Name>Jim Green</Name>
</Instructor>
<Student>
<Name>Jack</Name>
<Name>Mary</Name>
<Name>Paul</Name>
</Student>
</course>
Length of NodeList: 0
Name: not in this document!
Has anyone an idea?
If I do all this stuff without serializing it works.
If I do not search for argv[0], but the string "Name" it fails.
If I do search for "*" it works fine!
I'm very confused could anybody please help me a bit??
Stefan.
[[email protected]]The link has been fixed. You will go to the v2 download page
now. Sorry for the inconvience.
Oracle XML Team
http://technet.oracle.com
Oracle Technology Network
Renilton Oliveira (guest) wrote:
: I didn't find the file for version 2.0.0.0 as well.
: Renilton
: Andrei Filimonov (guest) wrote:
: : I tried to download XML Parser for Java v2 it seems that
only
: v
: : 1.0.1.4 is available. Could you please give an exact URL for
: v2
: : download?
: : Andrei Filimonov
: : Oracle XML Team wrote:
: : : The Oracle XML v2 parser is now available for download
here
: as
: : : an early beta release and is written in Java. It features
: an
: : : improved architecture over the Oracle XML v1 parser and
has
: : : shown better performance on small to large XML documents.
: It
: : : will also be able to format the XML document according to
a
: : : stylesheet, having integrated an XSLT processor.
: : : Version 2 of the XML Parser for Java, besides
incorporating
: an
: : : XSLT processor, has been re-architected from version 1.
This
: : has
: : : resulted in a number of changes to the class names
: especially
: : : those that support Namespaces. See v2changes.txt and
: the .diff
: : : difference files in the sample directory.
: : : Oracle XML Team
: : : http://technet.oracle.com
: : : Oracle Technology Network
null -
XML output with multiple tags in one line
I have not done much XML exporting with SQL. Previously I had just been ending my SQL queries with
FOR XML RAW ('Company'), ROOT ('Companies'), ELEMENTS;
and it formatted my query nicely in an XML output. That put every column name as a tag and the cell data within the tag.
However, now the criteria has changed on me. I need to create a tag with multiple sub tags in it.
Example: <Location Floor="10" Suite="512" DoorType="Metal">
But I'll still need other tags to be normal in the XML output such as
<Address>123 Fake St</Address>
<City>Springfield</City>
<Location Floor="10" Suite="512" DoorType="Metal">
Is there any way to get this XML mixed in the output like above?
Thank you for any help.Hi, you can FOR XML PATH for a finer degree of control over your XML. Use the @ symbol to create attributes. Here's a simple example:
DECLARE @t TABLE ( rowId INT IDENTITY PRIMARY KEY, [address] VARCHAR(50), city VARCHAR(30), floor INT, suite INT, doorType VARCHAR(20) )
INSERT INTO @t VALUES
( '123 Fake St', 'Springfield', 10, 512, 'Metal' )
SELECT
[address] AS "Address",
city AS City,
[floor] AS "Location/@Floor",
suite AS "Location/@Suite",
doorType AS "Location/@DoorType"
FROM @t
FOR XML PATH ('Company'), ROOT ('Companies'), ELEMENTS; -
Is it possible to create indexes & use them on xml docs with namespaces?
I have put an XML doc in a BDBXML container which looks like this:
*<ns1:note xmlns:ns1="http://www.testsch.org/ns">*
*<ns1:to>Eric</ns1:to>*
*<ns1:from>Brendan</ns1:from>*
*<ns1:msg>How r u?</ns1:msg>*
*</ns1:note>*
Now, I am creating an index on the element "to", as:
addIndex "ns1" "to" node-element-equality-string
Though the index has been shown as getting created using the listIndexes command, if I lookup that index with the following command:
lookupIndex node-element-equality-string "ns1" "to"
the output is:
*0 objects returned for eager index lookup 'node-element-equality-string'*
Whereas, if I do the whole procedure without the namespaces in the document & the commands, the result is fine:
*1 object returned for eager index lookup 'node-element-equality-string'*
Can someone please tell me whether using namespaces, the indexes can be created or not? If yes, how?
Thanks,
Dev
Edited by: user11871332 on Sep 7, 2009 3:53 PMHi Dev,
When using XML, the prefix for the namespace is really just syntactic sugar. The actual namespace in your example is "http://www.testsch.org/ns", and that's the value that you need to use when creating your index:
addIndex "http://www.testsch.org/ns" "to" node-element-equality-stringJohn -
Generete xml doc with dtd form
Hi,
I am trying to generate xml doc based on dtd kind format.
I use following code to get my xml doc is ok based on dtd like
-----------dtd file---------------
<!ELEMENT client_data (client_job*, person*)>
<!ELEMENT client_job (job_cd, job_title?, primary_responsibilities?, grade_cd?, br_job_cd, eeo_job_group_id, effective_date?, end_date?)>
<!ATTLIST client_job errMsg CDATA #IMPLIED>
<!ATTLIST client_job deleteFlag ( Y | N ) 'N'>
<!ELEMENT job_cd (#PCDATA)>
<!ELEMENT job_title (#PCDATA)>
<!ELEMENT primary_responsibilities (#PCDATA)>
<!ELEMENT br_job_cd (#PCDATA)>
<!ELEMENT eeo_job_group_id (#PCDATA)>
-----------------end dtd--------------
OracleXMLQuery qry = new OracleXMLQuery(conn, sql);
qry.setRowsetTag("client_data");
qry.setRowIdAttrName(null);
// qry.useNullAttributeIndicator(true);
qry.useLowerCaseTagNames();
qry.setRowTag("client_job");
xmlDocToReturn = qry.getXMLDOM();
But if my dtd like following, i.g. has tree level, and data from multiple tables, the above code doesn't work for thes case
--------------tree level dtd----------------
<!ELEMENT person (person_name)>
<!ATTLIST person person_id CDATA #REQUIRED>
<!ATTLIST person hire_date CDATA #IMPLIED>
<!ATTLIST person effective_date CDATA #IMPLIED>
<!ATTLIST person end_date CDATA #IMPLIED>
<!ELEMENT person_name (formatted_name*, given_name*, prefered_given_name?, middle_name?, family_name*, affix*)>
<!ELEMENT formatted_name EMPTY>
<!ATTLIST formatted_name type ( presentation | legal | sortOrder) 'presentation'>
<!ELEMENT given_name (#PCDATA)>
<!ELEMENT prefered_given_name (#PCDATA)>
<!ELEMENT middle_name (#PCDATA)>
<!ELEMENT family_name (#PCDATA)>
<!ATTLIST family_name primary ( true | false | undefined ) 'undefined'>
-----------------end dtd -------------------
I try to use XMLDocumentFragment to create xml doc and appendChild , but the xml doc is not the format of the dtd required. Can you give me a Java sample?
Thanks in advance.
YanWhy don't you use XSLT?
-
XML doc with multiple namespaces
Hi,
a little stupid question...
Is it possible to get a xml file that assigns two different namespaces and I don't want to use a prefix?
example:
xml doc uses namespace xmlns:a="someuri" and xmlns:b="otheruri"
<?xml version="1.0" encoding="UTF-8"?>
<Root xmlns="someuri" xmlns:b="otheruri">
<test/>
<b:rest/>
</Root>
Some way to get prefix b out of it?
Thanxokay, it was a stupid question...
solution:
<?xml version="1.0" encoding="UTF-8"?>
<Root xmlns="someuri" xmlns:b="otheruri">
<test/>
<rest xmlns="otheruri"/>
</Root> -
Creating a PLSQL script to parse structured XML with repeated tags
Hi, I'm trying to parse an xml feed but the way it's structured makes it difficult to pull out the values. (see example) Would anyone be able to recommend a solution or some ideas as to how to get around this?
SAMPLE XML:<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>
<env:Header>
</env:Header>
<env:Body>
<ns3:commandResponse xmlns:ns2="http://test.com/2011/Generic/schema" xmlns:ns3="http://test.com/2011/Generic">
<return>
<ns2:return>success</ns2:return>
<ns2:Command>issues</ns2:Command>
<ns2:WorkItems>
<ns2:Id>216141</ns2:Id>
<ns2:ModelType>Issue</ns2:ModelType>
<ns2:DisplayId>216141</ns2:DisplayId>
<ns2:Field>
<ns2:Name>Type</ns2:Name>
<ns2:Value>
<ns2:Item>
<ns2:Id>Dev Task</ns2:Id>
<ns2:ModelType>Type</ns2:ModelType>
<ns2:DisplayId>Dev Task</ns2:DisplayId>
</ns2:Item>
</ns2:Value>
</ns2:Field>
<ns2:Field>
<ns2:Name>ID</ns2:Name>
<ns2:Value>
<ns2:int>216141</ns2:int>
</ns2:Value>
</ns2:Field>
<ns2:Field>
<ns2:Name>Reason</ns2:Name>
<ns2:Value>
<ns2:string>Integrating</ns2:string>
</ns2:Value>
</ns2:Field>
<ns2:Field>
<ns2:Name>Dev Task Component</ns2:Name>
<ns2:Value>
<ns2:string>Java Tools</ns2:string>
</ns2:Value>
</ns2:Field>
<ns2:Field>
<ns2:Name>Created Date</ns2:Name>
<ns2:Value>
<ns2:datetime>2009-08-10T15:52:39.000-04:00</ns2:datetime>
</ns2:Value>
</ns2:Field>
<ns2:Field>
<ns2:Name>Date Closed</ns2:Name>
<ns2:Value/>
</ns2:Field>
<ns2:Field>
<ns2:Name>Modified Date</ns2:Name>
<ns2:Value>
<ns2:datetime>2011-03-04T12:57:05.000-05:00</ns2:datetime>
</ns2:Value>
</ns2:Field>
</ns2:WorkItems>
</return>
</ns3:commandResponse>
</env:Body>
</env:Envelope>This is just a sample with just one WorkItem, but there would be much more, N number of items with 9 fields per item. (Not all of the fields were put in the sample, and some can have null values)
I only need to pull the content from /ns2:WorkItems/ns2:Field/ns2:Value/ns2:Item/ns2:Id for the first field and the /ns2:value/* tag of all the other fields. Then put this in a table where each row is a workitem and the fields are the columns (create table workitems (Type,ID,Reason,Dev Task Component,Created Date, Date Closed, Modified Date) --all the fields should be varchar2 except the dates)
What I've been trying so far seems rather brute force by running a nested loop to go through every item and field and then an IF case for each field 1,2,...9 which would insert the value into a table.
At the moment I'm using something like below to pull a single value
path1 = '//ns2:WorkItems[1]/ns2:Field[1]/ns2:Value[1]/ns2:Item[1]/ns2:Id[1]';
nameserve = 'xmlns:ns2="http://test.com/2011/Generic/schema"';
extractvalue(xmltype(src_clob),path1,nameserve);I'm not entirely sure if I would be able to substitute the [1]'s with [' || nitem || '] where nitem is loop number to do something like:
for nitem in 1..itemcount
loop
FOR nfield in 1..9
loop
if nfield=1 then
path1 := '//ns2:WorkItems[' || nitem || ']/ns2:Field[' || nfield || ']/ns2:Value[1]/ns2:Item[1]/ns2:Id';
fieldvalue := extractvalue(xmltype(src_clob),path1,nameserve);';
else
path2 := '//ns2:WorkItems[' || nitem || ']/ns2:Field[' || nfield || ']/ns2:Value[1]/*[1]';
fieldvalue := extractvalue(xmltype(src_clob),path2,nameserve);';
end if;
end loop;
end loop;The problem with the above script is how do I insert this fieldvalue into different columns on a table without using an IF case for each field.
I was wondering if there is simpler way to put each field into a different column and loop through every workitem. I looked into dynamically naming variables but I don't think plsql supports that.
Any help/advice is appreciated,
Thanks!
Edited by: 843508 on Mar 10, 2011 1:56 PM
Edited by: 843508 on Mar 10, 2011 1:57 PM
Edited by: 843508 on Mar 10, 2011 2:01 PMIf it were me, I wouldn't use PL/SQL to try and process XML, but would use SQL's XMLTABLE functionality e.g.
SQL> ed
Wrote file afiedt.buf
1 WITH t as (select XMLTYPE('
2 <RECSET xmlns:aa="http://www.w3.org">
3 <aa:REC>
4 <aa:COUNTRY>1</aa:COUNTRY>
5 <aa:POINT>1800</aa:POINT>
6 <aa:USER_INFO>
7 <aa:USER_ID>1</aa:USER_ID>
8 <aa:TARGET>28</aa:TARGET>
9 <aa:STATE>6</aa:STATE>
10 <aa:TASK>12</aa:TASK>
11 </aa:USER_INFO>
12 <aa:USER_INFO>
13 <aa:USER_ID>5</aa:USER_ID>
14 <aa:TARGET>19</aa:TARGET>
15 <aa:STATE>1</aa:STATE>
16 <aa:TASK>90</aa:TASK>
17 </aa:USER_INFO>
18 </aa:REC>
19 <aa:REC>
20 <aa:COUNTRY>2</aa:COUNTRY>
21 <aa:POINT>2400</aa:POINT>
22 <aa:USER_INFO>
23 <aa:USER_ID>3</aa:USER_ID>
24 <aa:TARGET>14</aa:TARGET>
25 <aa:STATE>7</aa:STATE>
26 <aa:TASK>5</aa:TASK>
27 </aa:USER_INFO>
28 </aa:REC>
29 </RECSET>') as xml from dual)
30 -- END OF TEST DATA
31 select x.country, x.point, y.user_id, y.target, y.state, y.task
32 from t
33 ,XMLTABLE(XMLNAMESPACES('http://www.w3.org' as "aa"),
34 '/RECSET/aa:REC'
35 PASSING t.xml
36 COLUMNS country NUMBER PATH '/aa:REC/aa:COUNTRY'
37 ,point NUMBER PATH '/aa:REC/aa:POINT'
38 ,user_info XMLTYPE PATH '/aa:REC/*'
39 ) x
40 ,XMLTABLE(XMLNAMESPACES('http://www.w3.org' as "aa"),
41 '/aa:USER_INFO'
42 PASSING x.user_info
43 COLUMNS user_id NUMBER PATH '/aa:USER_INFO/aa:USER_ID'
44 ,target NUMBER PATH '/aa:USER_INFO/aa:TARGET'
45 ,state NUMBER PATH '/aa:USER_INFO/aa:STATE'
46 ,task NUMBER PATH '/aa:USER_INFO/aa:TASK'
47* ) y
SQL> /
COUNTRY POINT USER_ID TARGET STATE TASK
1 1800 1 28 6 12
1 1800 5 19 1 90
2 2400 3 14 7 5p.s. XML questions are better suited in the XML DB forum:
XML DB FAQ -
I know it is possible to save an XML document into a BLOB field. However, can anyone tell me if it is possible to pass a BLOB in an XML document. What I mean is can I have an XML document structured as follows? Is so, where can I find the syntax. We receive XML orders via XSQL page and would like to store this data in the DB.
<xml version="1.0">
<books>
<book>
<isbn>032541251</isbn>
<title>How to Program in XML</title>
<cover>****.jpg file with picture of book that can be store in BLOB ****</cover>
<exceprt>****.PDF or MS Word .DOC of prelude for example****</except>
</book>
</books>
</xml>
Any help would be appreciatedRefer
http://builder.com.com/5100-31-5075709.html
The XMLType may also be used.
http://www.oracle.com/technology/sample_code/tech/java/codesnippet/xmldb/HowToLoadLargeXML.html -
Hi,
I have a simple form for a simple page flow app
public static class CheckforloopcountForm extends FormData
private List loopCountResult;
private String loopCountVal;
public void setLoopCountVal(String loopCountVal)
this.loopCountVal = loopCountVal;
public String getLoopCountVal()
return this.loopCountVal;
public void setLoopCountResult(List loopCountResult)
this.loopCountResult = loopCountResult;
public List getLoopCountResult()
return this.loopCountResult;
now I populate the loopCountReult list with value in
my jpf.
then in the reponse.jsp I try to
get it as
<body>
<p>
The result page is showing:
</p>
<netui-data:repeater dataSource="{actionForm.loopCountResult}">
<netui-data:repeaterHeader><ol></netui-data:repeaterHeader>
<netui-data:repeaterItem>
<li>
<netui:label value="{container.item}"></netui:label>
</li>
</netui-data:repeaterItem>
<netui-data:repeaterFooter></ol>
</netui-data:repeaterFooter>
</netui-data:repeater>
I get the following error in jsp.
Caught exception when evaluating expression '{actionForm.loopCountResult}' with
available binding contexts [currentTag, session, pageContext, request, response,
application]. Root exception cause: com.bea.wlw.netui.script.xscript.IllegalContextStateException:
The action form for the expression "actionForm["loopCountResult"]" could not be
found
Any help on this will be great.
thanks,
SubhabrataThanks,
For your answer. Make sense now. So what will
be the best approach for receiving result from a formbean
in the result jsp.
Thanks,
Subhabrata
Eddie O'Neil <[email protected]> wrote:
Subhabrata--
I'm not exactly sure what the rest of the structure of your
application is, but the "actionForm" binding context can only be used
inside of the <netui:form> tag. Using it outside of this tag will
result in the error that you mention.
You can either pass the data to your page in the request and bind
to
it using the "request" binding context, or you can expose it as a public
property of the page flow and bind to it using the "pageFlow" binding
context. You could also wrap the repeater in a <netui:form> tag if you
have data to submit from the page.
Hope that helps...
Eddie
Subhabrata Sarkar wrote:
Hi,
I have a simple form for a simple page flow app
public static class CheckforloopcountForm extends FormData
private List loopCountResult;
private String loopCountVal;
public void setLoopCountVal(String loopCountVal)
this.loopCountVal = loopCountVal;
public String getLoopCountVal()
return this.loopCountVal;
public void setLoopCountResult(List loopCountResult)
this.loopCountResult = loopCountResult;
public List getLoopCountResult()
return this.loopCountResult;
now I populate the loopCountReult list with value in
my jpf.
then in the reponse.jsp I try to
get it as
<body>
<p>
The result page is showing:
</p>
<netui-data:repeater dataSource="{actionForm.loopCountResult}">
<netui-data:repeaterHeader><ol></netui-data:repeaterHeader>
<netui-data:repeaterItem>
<li>
<netui:label value="{container.item}"></netui:label>
</li>
</netui-data:repeaterItem>
<netui-data:repeaterFooter></ol>
</netui-data:repeaterFooter>
</netui-data:repeater>
I get the following error in jsp.
Caught exception when evaluating expression '{actionForm.loopCountResult}'with
available binding contexts [currentTag, session, pageContext, request,
response,>> application. Root exception cause: com.bea.wlw.netui.script.xscript.IllegalContextStateException:
The action form for the expression "actionForm["loopCountResult"]"could not be
found
Any help on this will be great.
thanks,
Subhabrata -
Recordset xml export WITH html tags
Hi there,
I am trying a rather simple thing (I hope) but cannot figure it out how to do it.
I created a dynamic xml (.php) file using the export recordset as xml behaviour. The generated xml works fine when I use spry to display it. The downside is that html tags are converted to something like this (I understand that these are the greater then and lesser then signs used in html):
<strong>fringilla</strong>
In the html document where I use spry to display this xml, the < etc are converted back to < and >, but the html is not rendered.
I tried cdata, but somehow cannot get this to work. I also cannot get dsSpecials.setColumnType("quote_tekst", "html"); to render the xml as correct html.
Can someone tell me how to do this? Database and xml are both utf-8.
Kind regards and big thanks in advance if you can help (it is really appreciated ;-D),
BenSorry about that, don't know what happened in that last post..formatting I guess, here's the whole reply - xml enclosed w/ a pre - thanks again.<br /><br />Hi Günter,<br /><br />Thanks so much for the info. I have been diligently trying to use CDATA and read the generated XML, but still I'm not seeing the HTML text rendereed in my detail section.<br /><br />The XML is setup from my mySQL data as:<br /><pre> <br /><?xml version="1.0" encoding="UTF-8"?><br /><CurrentSpecials><br /> <special><br /> <name> Caribbean Sun </name><br /> <detail> <h1>special deal!!</h1><p style="color:#00f;"><strong>Join us</strong>!</h1> </detail><br /> <expire> 2007-08-31 00:00:00 </expire><br /> <rating> highest </rating><br /> </special><br />...<br /></pre><br />and I want the detail to render in my div (or I'll add a table/textarea...) as the html indicates. I'm not having any luck w/ using CDATA for it - it's probably just me - I'm just starting out with this stuff. Any pointers in the right direction? I'm getting the detail as {dsList:detail} and somehow need to say - this is html. I've tried using javascript and php to render it.<br /><br />I could I guess just echo the detail on a mouseclick without a spry but didn't want to have to do all the implementation myself - I wanted to take advantage of dreamweaver's functionality! <br /><br />Thanks so much for looking at this - any help is so much appreciated!!
-
I have extracted some code from codeproject to
reindent an XML document. Does anyone know how I can modify the stylesheet to make it so that the transform of an XML file will result in empty tags showing up as <tag /> instead of <tag></tag>?
// http://www.codeproject.com/Articles/43309/How-to-create-a-simple-XML-file-using-MSXML-in-C
MSXML2::IXMLDOMDocumentPtr FormatDOMDocument(MSXML2::IXMLDOMDocumentPtr pDoc)
LPCSTR const static szStyleSheet =
R"!(<?xml version="1.0" encoding="utf-8"?>)!"
R"!(<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">)!"
R"!( <xsl:output method="xml" indent="yes"/>)!"
R"!( <xsl:template match="@* | node()">)!"
R"!( <xsl:copy>)!"
R"!( <xsl:apply-templates select="@* | node()"/>)!"
R"!( </xsl:copy>)!"
R"!( </xsl:template>)!"
R"!(</xsl:stylesheet>)!";
MSXML2::IXMLDOMDocumentPtr pXmlStyleSheet;
pXmlStyleSheet.CreateInstance(__uuidof(MSXML2::DOMDocument60));
pXmlStyleSheet->loadXML(szStyleSheet);
MSXML2::IXMLDOMDocumentPtr pXmlFormattedDoc;
pXmlFormattedDoc.CreateInstance(__uuidof(MSXML2::DOMDocument60));
CComPtr<IDispatch> pDispatch;
HRESULT hr = pXmlFormattedDoc->QueryInterface(IID_IDispatch, (void**)&pDispatch);
if (SUCCEEDED(hr))
_variant_t vtOutObject;
vtOutObject.vt = VT_DISPATCH;
vtOutObject.pdispVal = pDispatch;
vtOutObject.pdispVal->AddRef();
hr = pDoc->transformNodeToObject(pXmlStyleSheet, vtOutObject);
//By default it is writing the encoding = UTF-16. Let us change the encoding to UTF-8
// <?xml version="1.0" encoding="UTF-8"?>
MSXML2::IXMLDOMNodePtr pXMLFirstChild = pXmlFormattedDoc->GetfirstChild();
// A map of the a attributes (vesrsion, encoding) values (1.0, UTF-8) pair
MSXML2::IXMLDOMNamedNodeMapPtr pXMLAttributeMap = pXMLFirstChild->Getattributes();
MSXML2::IXMLDOMNodePtr pXMLEncodNode = pXMLAttributeMap->getNamedItem(_T("encoding"));
pXMLEncodNode->PutnodeValue(_T("UTF-8")); //encoding = UTF-8
return pXmlFormattedDoc;
Or, if there is some other method for reindenting a MSXML2::IXMLDOMDocumentPtr object where I can specify how I want empty tags to be stored, that would be great too. However, I don't want it to lose its status of an MSXML2::IXMLDOMDocumentPtr object.
I.e. I would like to still perform operations on the result as if it was still an MSXML2::IXMLDOMDocumentPtr object.
Thanks,
A
AdrianIf anyone is interested, I got an answer on StackOverflow
here.
Adrian -
Parsing an XML doc with unavailable entity (DTD)
Hi all,
I am trying to parse an XML file (web.xml) that has the following DOCTYPE in the head of the document:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app id="WebApp">When the parser starts, it will look for the DTD on the Sun site, however my work firewall blocks access to this so I get an exception when parsing.
To resolve this, I have tried to force the parser to look for a local copy of the DTD instead of the Sun site but to no avail. I still get the same error but don't know why it wont look at the local DTD.
Here is my code:
* InterceptingXml.java
* Created on 04 April 2006, 15:58
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
package org.xmldemos;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
* @author CS781RJ
public class InterceptingXml
/** Creates a new instance of InterceptingXml */
public InterceptingXml() { }
public void parse(String filename)
try
// Create an XML parser
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
// Install the entity resolver
builder.setEntityResolver(new MyResolver());
// Parse the XML file
Document doc = builder.parse(new File(filename));
catch (SAXException e) { e.printStackTrace(); }
catch (ParserConfigurationException e) { e.printStackTrace(); }
catch (IOException e) { e.printStackTrace(); }
catch (Exception e) { e.printStackTrace(); }
public class MyResolver implements EntityResolver
// This method is called whenever an external entity is accessed
// for the first time.
public InputSource resolveEntity(String publicId, String systemId)
try
System.out.println("publicId: " + publicId + " systemId: " + systemId);
// Wrap the systemId in a URI object to make it convenient
// to extract the components of the systemId
URI uri = new URI(systemId);
System.out.println("URI scheme: " + uri.getScheme());
System.out.println("URI scheme specific: " + uri.getSchemeSpecificPart());
// Check if external source is a file
if ("http".equals(uri.getScheme()))
String filename = uri.getSchemeSpecificPart();
filename = "file:/C:/web-app_2_3.dtd";
InputSource isrc = new InputSource(new FileReader(filename));
return isrc;
catch (URISyntaxException e) { }
catch (IOException e) { }
// Returning null causes the caller to try accessing the systemid
return null;
public static void main(String[] args)
InterceptingXml ixml = new InterceptingXml();
ixml.parse("c:\\web.xml");
}And here is the exception:
init:
deps-jar:
compile-single:
run-single:
publicId: -//Sun Microsystems, Inc.//DTD Web Application 2.3//EN systemId: http://java.sun.com/dtd/web-app_2_3.dtd
URI scheme: http
URI scheme specific: //java.sun.com/dtd/web-app_2_3.dtd
java.net.UnknownHostException: java.sun.com
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:177)
at java.net.Socket.connect(Socket.java:507)
at java.net.Socket.connect(Socket.java:457)
at sun.net.NetworkClient.doConnect(NetworkClient.java:157)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:365)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:477)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:214)
at sun.net.www.http.HttpClient.New(HttpClient.java:287)
at sun.net.www.http.HttpClient.New(HttpClient.java:299)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:792)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:744)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:669)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:913)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:973)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity(XMLEntityManager.java:905)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startDTDEntity(XMLEntityManager.java:872)
at com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.setInputSource(XMLDTDScannerImpl.java:282)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDispatcher.dispatch(XMLDocumentScannerImpl.java:1021)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:368)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:834)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:250)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:292)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:172)
at org.xmldemos.InterceptingXml.parse(InterceptingXml.java:45)
at org.xmldemos.InterceptingXml.main(InterceptingXml.java:88)
BUILD SUCCESSFUL (total time: 18 seconds)I have noticed that return isrc; does not get executed even though the debugger steps to the line above it.
Thanks in advance.
RizWhat's the point of all that code in your EntityResolver? Would the code work just as well if the DTD didn't even exist? Then do this:public InputSource resolveEntity(String publicId, String systemId)
return new InputSource(new StringReader(""));
}However if you really do need to redirect to a local copy of the DTD then consider this:catch (IOException e) { }can be a real barrier to understanding in the case that an IOException is thrown. At least print a stacktrace. And: the FileReader class wants a file name in its constructor, not a URI. And in this code:String filename = uri.getSchemeSpecificPart();
filename = "file:/C:/web-app_2_3.dtd";you could write this instead:String filename = "file:/C:/web-app_2_3.dtd";which would be both shorter and easier to understand.
Maybe you are looking for
-
How do I stop a sync mucking about with my contacts list?
I have repeatedly set up the same contacts list in my computer and phone. All are in the form: Marybeth @ M in the first name field - a habit from long ago! Either the computer or the phone keeps trying to create surnames or dredge them out of some o
-
How do I get my ipad to recognize the microphone on my earbuds?
How do I get my ipad to recognize the microphone on my arbuds?
-
Why is Intellisense showing this error in VS2013?
Intellisense is showing a red wiggly line below the function name `get_today` in its definition below, with the following error message: "cannot overload functions distinguished by return type alone". Note that the code compiles and executes without
-
Mail doesn't launch after 10.5.7 update
Hello, After updating to 10.5.7 everything works fine - except Mail. The dock icon bounces one or two times and then stops. There is no error message, no beach ball and the blue dot below the icon doesn't appear either. Before the update Mail worked
-
Access encrypted folder from external drive.
I spilled some water on my Thinkpad T60 while it was in standby. Neadless to say, it doesn't work anymore. I took out the harddrive and put it in an external enclosure and hooked it up to another computer. But I can't access the encrypted folders