Forum OpenACS Q&A: fun with XML... I need help

Collapse
Posted by Jun Yamog on
Hi,

I am having fun with ns_xml, but I have a problem. I would like to put my files to xml format. Its kinda easier that way, or more fun. Following Ben Adida's stuff on QD I started to get my xml stuff to work. Here is a sample snippet:

<?xml version="1.0"?>
<section image="/images/about.jpg" color="#67CC02" url="/about/">
    <content>

       <p>About Us</p>

</content>

</section>

Basically its a web page but as you can see the image and color for the section is a xml attribute. I am successful in getting this attributes and using it later on an ADP template. I am also successful in getting the content. But it seem that xml_node_get_content which is a wrapper to "ns_xml node getcontent $node_id" trims away the XML tags inside the content. I end up with "About Us" rather than my desired output of "<p>About Us</p>". I think is the right behavior but not good for my needs. What I need is to extract everything that is in the <content> </content>. I did a ns_xml doc render, it was nice but I renders the whole document. I would like to have something that renders the node and all children below it.

Please help. I can do a ns_xml doc render and just do a regexp, but that would not be fun. Or makes the xml stuff useless. Maybe I just create an ini style of a data or something else that is friendly to regexp.

How can I extract everything between 2 xml tags? No regexp ok, I want to do this the xml way. Thanks.

Collapse
Posted by Dave Bauer on
What version of ns_xml are your using? If you are using the right node id for <content> it should give you everything between that tags as content.
Collapse
Posted by Dave Bauer on
I thought of something else. With ns_xml be sure you have the right tag by using xml_get_first_node_by_name or a. list of children with the same name with xml_get_children_by_name. In XML every newline is a node. So if you just count the tags, you will end up at the wrong node unless there is no whitespace between the tags.
Collapse
Posted by Jun Yamog on
Hi Dave, I use ns_xml 1.4. Well anyway I do get the child node. I even try to write the node name and it seems fine. I can even get to the <p> tags. My main problem is that the inside the content node I have XHTML or HTML stuff. I need a way to get those content and tags out. Is there a way to escape tags? Getting the content from a node strips out all tags, but I do get the content. I would like is to get the content and tags under a node. Is there a way to an API to copy all nodes and children nodes to a new XML doc? That way after copying I will just do a render doc. I dont want to create one yet. Thanks. Jun
Collapse
Posted by Tilmann Singer on
The most xml-ish way to do this would propably be to embed the html in a CDATA section.

see this article for an example
Collapse
Posted by Jun Yamog on
Thanks this is what I needed.  Although I have used the 2nd method which is to escape the less than and greater than characters. =(

I will just reformat my stuff to use CDATA.

Jun