[prev in list] [next in list] [prev in thread] [next in thread] 

List:       xerces-c-dev
Subject:    RE: XML Dom parsers and updators.
From:       "Jesse Pelton" <jsp () PKC ! com>
Date:       2005-10-17 17:09:10
Message-ID: 16E2027582CDB74180896CDB4B8CC1F901D0446F () PKCVT01 ! pkc ! com
[Download RAW message or body]

I don't think there are any Xerces samples that demonstrate editing the
DOM tree, but the process is straightforward. Find a node that you want
to modify, then use create..() functions (createElement(),
createTextNode(), etc) to create any new nodes and append...() or
replace...() functions (appendChild(), replaceChild() etc) to append
them to the parent or replace existing nodes. You can also remove nodes
(removeChild()) and add or remove attributes.
 
The CreateDOMDocument sample demonstrates the process of creating and
appending nodes. See the API docs on the Xerces-C site and the DOM spec
on the W3C site (and/or a good book on the DOM) for more information.
 
Bear in mind that XSLT is designed for precisely this purpose. The W3C
site calls it "a language for transforming XML." You may be able to
accomplish what you need by writing one or more stylesheets instead of
code, and you'll have all the power and flexibility of XSLT available to
meet future demands on your system. It might not perform as well as
carefully purpose-built code, though. Using XSLT would also give you a
degree of platform independence. (For instance, modern XSLT processors
in Java can generate efficient classes to implement any given transform
that will run anywhere there's a Java virtual machine.)
 
Please be sure to send your messages to the Xerces mailing list, not
just to my address. A lot of smart, experienced people read the traffic,
and may have more useful and/or accurate advice to offer. Furthermore,
the answers to your questions will be archived for the benefit of those
who have similar questions later.


________________________________

	From: premkumar srinivasan [mailto:prem.srini@gmail.com] 
	Sent: Monday, October 17, 2005 10:12 AM
	To: Jesse Pelton
	Subject: Re: XML Dom parsers and updators.
	
	
	Hi Jesse,
	 
	There was some minor issue, and now, I could execute xgrep,
without having any problem.
	 
	I was thinking about using Xerces API for accessing the DOM
Tree, as you suggested. Will you please guide me to any known sample
classic documentation, that talks on updating XML using Xerces API.
	 
	Thanks a lot!
	 
	--Prem.
	
	 
	On 10/17/05, premkumar srinivasan <prem.srini@gmail.com> wrote: 

		On installing, and running xgrep ( as is, from
http://software.decisionsoft.com/pathanXgrepDocumentation.html ) , I am
getting the following error: 
		 
		E:\pathanGrepX\Debug>pathanGrepX -v
"/descendant::orderNumber" test.xml
		Error at file "00604C90", line 2, column 12
		   Message: 00604C28
		Error during script parsing, in file test.xml at line 2,
column 12.
		Message: 00604CF8
		Cannot open file test.xml.
		 
		test.xml file contents:
		<?xml version="1.0" encoding="utf-8"?>
		<purchases>
		<orderNumber id="PA1" />
		<group>
		<orderNumber id="PA2" />
		</group>
		</purchases>
		 
		Am I missing anything ???
		 
		Thanks for pointing at Xalan. I have already installed
Xalan.
		 
		Thanks,
		--Prem.
		
		 
		
		On 10/13/05, Jesse Pelton <jsp@pkc.com> wrote: 

			Xgrep is a nifty tool. It's a great way to
explore XPath and to develop and hone expressions.
			 
			The DOM specification (which Xerces attempts to
implement faithfully) includes methods for modifying the tree. However,
I'm beginning to wonder if you're looking for more command-line tools
like Xgrep to perform your modifications for you. If so, Xerces alone
won't help, because it's a library that implements an API. It doesn't
include any programs to make arbitrary modifications to the input. 
			 
			If you want a command-line tool to do XML-aware
document transformation, you'll need something that allows you to
specify the transformation (a template or stylesheet) to be performed
along with the input document. If this is the case, you should look at
XSLT, Velocity, etc. For instance, Xalan-C includes a command-line
processor (called, appropriately, Xalan) that takes an XML source
document and an XSLT stylesheet and outputs the result of applying the
stylesheet to the document. 


________________________________

				From: premkumar srinivasan
[mailto:prem.srini@gmail.com ] 
				Sent: Thursday, October 13, 2005 10:24
AM
				To: Jesse Pelton
				Subject: Re: XML Dom parsers and
updators.
				
				 
				
				Hi,
				Thanks for pointing at Pathan.
				 
				I have installed xerces version 2.3 and
pathan version 2. I think, the xgrep program (
http://software.decisionsoft.com/pathanXgrepDocumentation.html
<http://software.decisionsoft.com/pathanXgrepDocumentation.html> ), can
be used for XPATH. Right????
				 
				Also, for modifying the DOMTree, can
xerces API libraries for DOM files be used for updating the XML file (
which is been represented in the memory as a DOM Tree )? Is there
anything that can be used along with XERCES and PATHAN, to update the
DOM Tree. 
				 
				Am I going in the right direction?
				 
				Thanks,
				--Prem,
				
				 
				On 10/11/05, Jesse Pelton <jsp@pkc.com>
wrote: 

				There are any number of template-based
transformers, some of which use DOM and XPath as you're describing, some
of which don't. Projects with their own template systems include
Velocity and FreeMarker (both Java) among others. The standardized XML
transformation language is XSLT, which is implemented in Apache's Xalan
(C++ or Java), Gnome's libxml2/gdome2/libxslt, and quite a few other
libraries. 
				 
				If you want your updates to be driven by
code rather than templates, any of these libraries should serve, or you
can use Xerces-C for the DOM and Pathan (which is built on Xerces) for
XPath. 


________________________________

				From: premkumar srinivasan
[mailto:prem.srini@gmail.com] 
				Sent: Tuesday, October 11, 2005 11:23 AM
				To: c-dev@xerces.apache.org
				Subject: Reg: XML Dom parsers and
updators. 
				
				 

				Hi, 

				Is there any open source based on XML,
that allows us to do the following:
				- Parse XML into a DOM Tree.
				- Retrieve the XML data using XPATH
queries.
				- Update the DOM Tree, based on the
update-type. It might be DOM node updation, or addition of a new DOM
node sets. 

				It's something like making XML file, a
database, and use "SQL" sort of queries to update/retrieve data.

				Your suggestions would be really helpful
for me.

				Thanks,
				--Prem


[Attachment #3 (text/html)]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2900.2722" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=685483016-17102005>I don't think there are any Xerces samples that 
demonstrate editing the DOM tree, but the process is straightforward. Find a 
node that you want to modify, then use create..() functions (createElement(), 
createTextNode(), etc) to create any new nodes and append...()&nbsp;or 
replace...() functions (appendChild(), replaceChild() etc) to append them to the 
parent or replace existing nodes. You can also remove nodes (removeChild()) and 
add or remove attributes.</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=685483016-17102005></SPAN></FONT>&nbsp;</DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=685483016-17102005>The CreateDOMDocument sample demonstrates the process 
of creating and appending nodes. See the API docs on the Xerces-C site and the 
DOM spec on the W3C site (and/or a good book on the DOM) for more 
information.</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=685483016-17102005></SPAN></FONT>&nbsp;</DIV>
<DIV dir=ltr align=left><FONT><SPAN class=685483016-17102005><FONT 
face=Arial><FONT color=#0000ff size=2>Bear in mind that XSLT is designed for 
precisely this purpose. The W3C site calls it "<!--StartFragment -->a language 
for transforming XML." You may be able to accomplish what you need by writing 
one or more stylesheets instead of code, and you'll have all the power and 
flexibility of XSLT available to meet future demands on your system. It might 
not perform as well as carefully purpose-built code, though. Using XSLT would 
also give you a degree of platform independence. (For instance, modern XSLT 
processors in Java can generate efficient classes to implement any given 
transform that will run anywhere there's a Java virtual 
machine.)</FONT></FONT></SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=685483016-17102005></SPAN></FONT>&nbsp;</DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=685483016-17102005>Please be sure to send your messages to the Xerces 
mailing list, not just to my address. A lot of smart, experienced people read 
the traffic, and may have more useful and/or accurate advice to offer. 
Furthermore, the answers to your questions will be archived for the benefit of 
those who have similar questions later.</SPAN></FONT></DIV><BR>
<BLOCKQUOTE 
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; \
MARGIN-RIGHT: 0px">  <DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
  <HR tabIndex=-1>
  <FONT face=Tahoma size=2><B>From:</B> premkumar srinivasan 
  [mailto:prem.srini@gmail.com] <BR><B>Sent:</B> Monday, October 17, 2005 10:12 
  AM<BR><B>To:</B> Jesse Pelton<BR><B>Subject:</B> Re: XML Dom parsers and 
  updators.<BR></FONT><BR></DIV>
  <DIV></DIV>
  <DIV>Hi Jesse,</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>There was some minor issue, and now, I could execute xgrep, without 
  having any problem.</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>I was thinking about using Xerces API for accessing the DOM Tree, as you 
  suggested. Will you please guide me to any known sample classic 
  documentation,&nbsp;that talks on updating XML using Xerces API.</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>Thanks a lot!</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>--Prem.<BR><BR>&nbsp;</DIV>
  <DIV><SPAN class=gmail_quote>On 10/17/05, <B class=gmail_sendername>premkumar 
  srinivasan</B> &lt;<A 
  href="mailto:prem.srini@gmail.com">prem.srini@gmail.com</A>&gt; wrote:</SPAN> 
  <BLOCKQUOTE class=gmail_quote 
  style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
    <DIV>On installing, and running xgrep ( as is, from <A 
    onclick="return top.js.OpenExtLink(window,event,this)" 
    href="http://software.decisionsoft.com/pathanXgrepDocumentation.html" 
    target=_blank>http://software.decisionsoft.com/pathanXgrepDocumentation.html 
    </A>) , I am getting the following error: </DIV>
    <DIV>&nbsp;</DIV>
    <DIV>E:\pathanGrepX\Debug&gt;pathanGrepX -v "/descendant::orderNumber" 
    test.xml</DIV>
    <DIV>Error at file "00604C90", line 2, column 12<BR>&nbsp;&nbsp; Message: 
    00604C28<BR>Error during script parsing, in file test.xml at line 2, column 
    12.<BR>Message: 00604CF8<BR>Cannot open file test.xml.</DIV>
    <DIV>&nbsp;</DIV>
    <DIV>test.xml file contents:</DIV>
    <DIV>&lt;?xml version="1.0" encoding="utf-8"?&gt;<BR>&lt;purchases&gt;</DIV>
    <DIV>&lt;orderNumber id="PA1" /&gt;</DIV>
    <DIV>&lt;group&gt;<BR>&lt;orderNumber id="PA2" 
    /&gt;<BR>&lt;/group&gt;<BR>&lt;/purchases&gt;</DIV>
    <DIV>&nbsp;</DIV>
    <DIV>Am I missing anything ???</DIV>
    <DIV>&nbsp;</DIV>
    <DIV>Thanks for pointing at Xalan. I have already installed Xalan.</DIV>
    <DIV><FONT face=Arial color=#0000ff size=2></FONT>&nbsp;</DIV>
    <DIV>Thanks,</DIV>
    <DIV>--Prem.<BR><BR>&nbsp;</DIV>
    <DIV><SPAN class=e id=q_106fee3739f48326_1>
    <DIV><SPAN class=gmail_quote>On 10/13/05, <B class=gmail_sendername>Jesse 
    Pelton</B> &lt;<A onclick="return top.js.OpenExtLink(window,event,this)" 
    href="mailto:jsp@pkc.com" target=_blank>jsp@pkc.com</A>&gt; wrote:</SPAN> 
    <BLOCKQUOTE class=gmail_quote 
    style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px \
                solid">
      <DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN>Xgrep 
      is a nifty tool. It's a great way to explore XPath and to develop and hone 
      expressions.</SPAN></FONT></DIV>
      <DIV dir=ltr align=left><FONT face=Arial color=#0000ff 
      size=2><SPAN></SPAN></FONT>&nbsp;</DIV>
      <DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN>The 
      DOM specification (which Xerces attempts to implement faithfully) includes 
      methods for modifying the tree. However, I'm beginning to wonder if you're 
      looking for more command-line tools like Xgrep to perform your 
      modifications for you. If so, Xerces alone won't help, because it's a 
      library that implements an API. It doesn't include any programs to make 
      arbitrary modifications to the input. </SPAN></FONT></DIV>
      <DIV dir=ltr align=left><FONT face=Arial color=#0000ff 
      size=2><SPAN></SPAN></FONT>&nbsp;</DIV>
      <DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN>If you 
      want a command-line tool to do XML-aware document transformation, you'll 
      need something that allows you to specify the transformation (a template 
      or stylesheet) to be performed along with the input document. If this is 
      the case, you should look at XSLT, Velocity, etc. For instance, Xalan-C 
      includes a command-line processor (called, appropriately, Xalan) that 
      takes an XML source document and an XSLT stylesheet and outputs the result 
      of applying the stylesheet to the document. </SPAN></FONT></DIV><BR>
      <BLOCKQUOTE 
      style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; \
MARGIN-RIGHT: 0px">  <DIV lang=en-us dir=ltr align=left>
        <HR>
        <FONT face=Tahoma size=2><SPAN><B>From:</B> premkumar srinivasan 
        [mailto:<A onclick="return top.js.OpenExtLink(window,event,this)" 
        href="mailto:prem.srini@gmail.com" 
        target=_blank>prem.srini@gmail.com</A> ] <BR></SPAN><B>Sent:</B> 
        Thursday, October 13, 2005 10:24 AM<BR><B>To:</B> Jesse 
        Pelton<BR><B>Subject:</B> Re: XML Dom parsers and 
        updators.<BR></FONT><BR>&nbsp;</DIV><SPAN>
        <DIV></DIV>
        <DIV>Hi,</DIV>
        <DIV>Thanks for pointing at Pathan.</DIV>
        <DIV><FONT face=Arial color=#0000ff size=2></FONT>&nbsp;</DIV>
        <DIV>I have installed xerces version 2.3 and pathan version 2. I think, 
        the xgrep program&nbsp;<FONT size=2>(</FONT><A 
        title=http://software.decisionsoft.com/pathanXgrepDocumentation.html 
        onclick="return top.js.OpenExtLink(window,event,this)" 
        href="http://software.decisionsoft.com/pathanXgrepDocumentation.html" 
        target=_blank> <FONT 
        size=2>http://software.decisionsoft.com/pathanXgrepDocumentation.html</FONT></A><FONT \
  size=2>), can be used for XPATH. Right????</FONT></DIV>
        <DIV><FONT size=2></FONT>&nbsp;</DIV>
        <DIV><FONT size=2>Also, for modifying the DOMTree,&nbsp;can xerces API 
        libraries for DOM files be used for updating the XML file ( which is 
        been represented in the memory as a DOM Tree )? Is there anything that 
        can be used along with XERCES and PATHAN, to update the DOM Tree. 
        </FONT></DIV>
        <DIV><FONT size=2></FONT>&nbsp;</DIV>
        <DIV><FONT size=2>Am I going in the right direction?</FONT></DIV>
        <DIV><FONT face=Arial color=#0000ff size=2></FONT>&nbsp;</DIV>
        <DIV>Thanks,</DIV>
        <DIV>--Prem,<BR><BR>&nbsp;</DIV>
        <DIV><SPAN class=gmail_quote>On 10/11/05, <B 
        class=gmail_sendername>Jesse Pelton</B> &lt;<A 
        onclick="return top.js.OpenExtLink(window,event,this)" 
        href="mailto:jsp@pkc.com" target=_blank>jsp@pkc.com</A>&gt; 
        wrote:</SPAN> 
        <BLOCKQUOTE class=gmail_quote 
        style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px \
solid">  <DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff 
          size=2>There are any number of template-based transformers, some of 
          which use DOM and XPath as you're describing, some of which don't. 
          Projects with their own template systems include Velocity and 
          FreeMarker (both Java) among others. The standardized XML 
          transformation language is XSLT, which is implemented in Apache's 
          Xalan (C++ or Java), Gnome's&nbsp;libxml2/gdome2/libxslt,&nbsp;and 
          quite a few other libraries. </FONT></SPAN></DIV>
          <DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff 
          size=2></FONT></SPAN>&nbsp;</DIV>
          <DIV dir=ltr align=left><SPAN></SPAN><SPAN><FONT face=Arial 
          color=#0000ff size=2>If you want your updates to be driven by code 
          rather than templates, any of these libraries should serve, or you can 
          use Xerces-C for the DOM and Pathan (which is built on Xerces) for 
          XPath. </FONT></SPAN></DIV><BR>
          <BLOCKQUOTE dir=ltr 
          style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; \
MARGIN-RIGHT: 0px">  <DIV lang=en-us dir=ltr align=left>
            <HR>
            <FONT face=Tahoma size=2><B>From:</B> premkumar srinivasan 
            [mailto:<A onclick="return top.js.OpenExtLink(window,event,this)" 
            href="mailto:prem.srini@gmail.com" 
            target=_blank>prem.srini@gmail.com</A>] <BR><B>Sent:</B> Tuesday, 
            October 11, 2005 11:23 AM<BR><B>To:</B> <A 
            onclick="return top.js.OpenExtLink(window,event,this)" 
            href="mailto:c-dev@xerces.apache.org" 
            target=_blank>c-dev@xerces.apache.org</A><BR><B>Subject:</B> Reg: 
            XML Dom parsers and updators. <BR></FONT><BR>&nbsp;</DIV>
            <DIV></DIV>
            <P>Hi, </P>
            <P>Is there any open source based on XML, that allows us to do the 
            following:<BR>- Parse XML into a DOM Tree.<BR>- Retrieve the XML 
            data using XPATH queries.<BR>- Update the DOM Tree, based on the 
            update-type. It might be DOM node updation, or addition of a new DOM 
            node sets. </P>
            <P>It's something like making XML file, a database, and use "SQL" 
            sort of queries to update/retrieve data.</P>
            <P>Your suggestions would be really helpful for me.</P>
            <P>Thanks,<BR>--Prem</P></BLOCKQUOTE></BLOCKQUOTE></DIV></SPAN></BLOCKQUOTE></BLOCKQUOTE></DIV></SPAN></DIV></BLOCKQUOTE></DIV></BLOCKQUOTE></BODY></HTML>




[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic