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

eZ debug

Timing: Jan 20 2025 17:35:41
Script start
Timing: Jan 20 2025 17:35:41
Module start 'content'
Timing: Jan 20 2025 17:35:42
Module end 'content'
Timing: Jan 20 2025 17:35:42
Script end

Main resources:

Total runtime0.9423 sec
Peak memory usage4,096.0000 KB
Database Queries208

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0095 587.7109180.8359
Module start 'content' 0.00950.8216 768.5469681.0000
Module end 'content' 0.83110.1111 1,449.5469345.0938
Script end 0.9422  1,794.6406 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00420.4444210.0002
Check MTime0.00140.1506210.0001
Mysql Total
Database connection0.00070.076010.0007
Mysqli_queries0.832688.36282080.0040
Looping result0.00250.26852060.0000
Template Total0.903695.920.4518
Template load0.00180.194820.0009
Template processing0.901895.699920.4509
Template load and register function0.00010.009710.0001
states
state_id_array0.00120.126410.0012
state_identifier_array0.00150.162220.0008
Override
Cache load0.00170.1829800.0000
Sytem overhead
Fetch class attribute can translate value0.00130.136740.0003
Fetch class attribute name0.00140.147990.0002
XML
Image XML parsing0.00150.158840.0004
class_abstraction
Instantiating content class attribute0.00000.0021100.0000
General
dbfile0.00380.4062340.0001
String conversion0.00000.001130.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
7content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
16content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
8content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 38
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs