Forums / Developer / "Getting" a web page XML code

"Getting" a web page XML code

Author Message

Jorge estévez

Thursday 10 April 2008 1:57:48 am

Using ez 3.10

Hi, I am developing a complex menu with a big structure in mind.

For a bunch of nodes (all created by one class definition) I generate a page that has XML information as it's only code within the page is something like:

<tree id="172">
<item id="177" text="Delivery"/>
<item id="178" text="Products"/>
<item id="179" text="Extraction"/>
</tree>

So nodes can be accessed by the javascript as content/view/xml/172, this will allow me to get the children of the node to build other links in the menu.

So the browser does not display any information at all in this kind of access, but if I view-source from the browser the code is right there as I need it.

I would like from a javascript that builds the menu to get "the code generated" in that page, but accessing a URL like www.mysite.com/index.php/content/view/xml/172 will not get the information from the page as this URL is understandable from ez but not from the javascript (I am assuming that if it should have at the end view/xml/code.html maybe it could understand it as it has a "name")

Any Ideas, maybe a different approach to this issue on how to access (get) the code that "makes" the URL page accessed as /content/view/xml/172?

thanks

Diseño Web Cuba
Web Design Cuba
www.elfosdesign.com

Jorge estévez

Sunday 04 May 2008 4:29:52 pm

I really need a hint on this.

I need to get the code behing the webpage.

<tree id="172">
<item id="177" text="Delivery"/>
<item id="178" text="Products"/>
<item id="179" text="Extraction"/>
</tree>

Maybe there is another approach to this issue.

please help!

thanks

Diseño Web Cuba
Web Design Cuba
www.elfosdesign.com

André R.

Sunday 04 May 2008 11:19:12 pm

Do you wonder how you reach such a page with javascript?
Or do you want to know how to create such a xml page in eZ Publihs?

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Jorge estévez

Monday 05 May 2008 4:54:45 am

Hello and thanks

I have already generated the code, each node at the ez site has an /view/xml/name that has it's own code (cached by the system)

What I need is to reach that code from javascript or take the code and insert it into a variable... so I can manage it later.

What seems (to me) complicated is that the code itself is the code of the page as if it was a common html page so I really do not know hot to reach and get it.

thanks

Diseño Web Cuba
Web Design Cuba
www.elfosdesign.com

Gaetano Giunta

Monday 05 May 2008 2:23:30 pm

<i>I would like from a javascript that builds the menu to get "the code generated" in that page, but accessing a URL like www.mysite.com/index.php/content/view/xml/172 will not get the information from the page as this URL is understandable from ez but not from the javascript (I am assuming that if it should have at the end view/xml/code.html maybe it could understand it as it has a "name")</i>

I think you might be misunderstanding here.

I suppose you are using some ready made XmlHttpRequest js lib for the javascript to "get the xml content", but even if you do the xhr requests by hand, there is nothing in the world preventing the js calls to access an url like .../content/view/xml/172.

What might have an impact otoh is the "content-type" http header that is sent back to the client along with every web page by eZ Publish. Since it is set to text/html, javascript might have a hard time parsing it as valid xml.

To fix this you can either:

- use the layout/set view, which provides a way to set up a proper content-type in layout.ini

- build json templates instead of xml ones. Then javascript "might" be able to treat the received data as a javascript "string" regardless of content-type and convert it to usable js structures by making a single "eval" call. Way faster than the xml version

- make use of custom http headers via site.ini:
[HTTPHeaderSettings]
CustomHeader=enabled
HeaderList[]=Content-Type
Content-Type[/my/xml/content]=text/xml
(nothe that this applies the http header to a path, regardless of view mode)

hope it helps
Gaetano

Principal Consultant International Business
Member of the Community Project Board

Jorge estévez

Wednesday 07 May 2008 5:33:31 am

Hello, let me explain a bit further

I am using a Javascript object that builds a treeview, this treeview loads its branches (child nodes) dynamically using an XML file at the server using XMLHTTPRequest, there are two ways of doing this operation:

1. Passing the URL of the XML file with the structure of the branch that should be loaded
2. Reading the contents of the file and passing as a parameter "the XML string"

The implementation at our site allows us to generate once the URL has been given (e.g. www.mysite.com/index.php/content/view/xml/172) all of the Childs that belong to that node.

The problem:

As ez knows how to read the URL's generated by the system, but JS does not, we think it's a better idea to take into consideration the second option, so we would like to obtain a response chain with the XML needed and pass the information to the JS function. So we need to make a request, save the response in a variable and give this variable to the JS code.

In ez docs a native code is mentioned ezSOAPClient that suggest that it can be used to make requests and get responses to the server but I cannot find any hints that could give me an example on how to use it, I am quite sure this could be a solution but with no help at all I am kind of grounded.

Gaetano, The JS is already developed and I cannot build JSON templates. Your explanation about the custom http request could be a guide, but if defined, is the JS going to "get" the XML code of the page. I mean ez will certainly get that code, but is JS going to do the same? If you could give us more information so we can carry on it will be appreciated indeed.

thanks again, this is the only issue to end up our web site project.

I am going to post some parts of this message as a new question to see if I could get anwsers about the ezSOAPClient.

Diseño Web Cuba
Web Design Cuba
www.elfosdesign.com

Gaetano Giunta

Wednesday 07 May 2008 6:17:18 am

Sorry, I have a hard time understanding your explanation, even though it is detailed - must be the translation.

I assume the following about your setup:

- the treeview that has to be built via javascript is still part of the same, single eZ Publish site.
- the javascript that builds the treeview is also hosted on the same ezpublish server, and is in fact used on a page served by eZ Publish

About the 2 methods you describe for having the existing js lib generate the treeview, I assume you mean:
1 - the html+js page that renders the treeview makes xhr calls to another url to fetch the xml that describes the node structure
2 - the html+js page that renders the treeview finds the xml string that describes the node structure inside itself, as a javascript var

option 1 is more flexible, 2 is faster

In any case, I do not think there is any need for an eZ Soap client here: ez soap client is a server-side component, completely unlike javascript. If you use it, you will have an eZ page making an http request to another eZ page, which is a complete waste of resources.

The way I would implement the 2 options above are:

1 - as noted in the previous response: the js code in the first page makes an xhr request to a different eZPublish page. The second requested page is full xml. The js code parses the retrieved xml and injects data in the treeview.

2 - have the xml "printed" inside the page that renders the treeview: this is even simpler, as eZ, as you said, knows how to render the treemenu node in xml. Just add to your template of the first page code like this

<script type="text/javascript">
myJsString = '{node_view_gui content_node=172 view='xml'}';
windows.onload = myLib.rendertreefromxml(myJsString);
</script>
For more docs on node_view_gui see http://ez.no/doc/ez_publish/technical_manual/4_0/reference/template_functions/visualization/node_view_gui

Final comment: "The JS is already developed and I cannot build JSON templates. Your explanation about the custom http request could be a guide, but if defined, is the JS going to "get" the XML code of the page. I mean ez will certainly get that code, but is JS going to do the same? If you could give us more information so we can carry on it will be appreciated indeed"
- ez does not "get" any xml code of pages. the browser gets the xml code, ez gets the browser request and sends back the xml
- as I said above, js is going to get exactly the same that your browser gets (if it makes the same request). It then will or will not be able to make use of what it has gotten.

Principal Consultant International Business
Member of the Community Project Board