CS3 javascript XML and attribute adding.

I've been trying to get something working in CS3 javascript XML for some time and it is getting really frustrating.
Say I have:
var someXML = new XML("<anElement/>");
someXML.@xxx = "something";
$.writeln(someXML.toXMLString());
gives the output I'd expect (<anElement xxx="something"/>);
But I need the name of the attribute to be dynamic.  As far as I can see I should be able to either:
someXML.getAttribute("xxx") = "something";
or
someXML.@["xxx"] = "something";
both these cases give an error of 'Cannot set property xxx'.  I'm using CS3 version 5.0.4 (the debug build because most of the time I'm working directly with the API - not through scripting).
I looking for ideas to try...
Ian

Hi Ole, thanks for the reply.
I am aiming to manipulate XML using standard javascript functions - nothing directly to do with indesign, though other parts of the script does interact with it.  Basically the scripts allow a user to set some configuration options and that is in an XML string format (if it was the indesign XML Hierarchy XMLElements, etc I'm pretty sure I could get things to work - worst case I could add to the scripting support in a plugin and make it work...).
I had an idea (driving home after a frustrating day), Since the XML I'm processing is small, I can move forward by crudely making a string from the XML object, inserting the attribute into the string and then re-new'ing the XML object.  With large comments about why - unless someone can come up with a reason/fix for the javascript-XML not working (I suppose it may just be the number of InDesign/Extendscript versions I have installed - CS2/CS3/CS4, indesign and server).
Ian

Similar Messages

  • Nested XML and attributes

    Hi all,
    Not sure if this is me doing things wrong, or a bug.
    XML:
    <schedules>
    <entry>
    <groupTitle group="test">Nice Test
    Title</groupTitle>
    <type>testtype</type>
    <items qty="2">
    <item>number 1</item>
    <item>number 2</item>
    </items>
    </entry>
    </schedules>
    I have two datasets:
    ds1 = new...XMLDataSet ("data/data.xml", "schedules/entry");
    ds2 = new...NestedXMLDataSet(ds1, "items/item");
    Everything seems to work fine except for accessing the @qty
    attribute for items. From reading the docs on datasets, I should be
    able to access that using {ds2::@qty} I believe ?
    If I add a @qty attribute to <entry> as a test, I can
    access that via {ds1::@qty}, or if I change ds2's XPath to just
    "items" then I can access it through {ds2::@qty} ... but then
    repeat on ds2 doesnt step through the child items.
    Am I doing something wrong or is there a bug accessing
    attributes on nested xml datasets ?
    Thanks in advance as always!
    Regards
    Dave

    Hi Dave,
    to access the @qty attribute, you don't need to create a
    nested data set. You can add a sub -path for the XML data set.
    The code should look like this:
    var ds1 = new Spry.Data.XMLDataSet("test.xml",
    "/schedules/entry", {subPaths: "items"});
    <div spry:region="ds1">
    <ul spry:repeat="ds1">
    <li>{items/@qty}</li>
    </ul>
    </div>
    Diana

  • Integrating Flash CS3 with XML

    Hello, I done a tutorial from learnflash.com on Integrating
    Flash CS3 with XML, and I can't figure out why when the file is
    published the scrollbar component doesn't work.

    Yep, big difference. Flash CS3 is the earlier version of
    Flash, so you can't open CS4 files in CS3. You are probably
    confusing CS3 with AS3, which is supported by both versions of
    Flash CS#.

  • Default xml namespace and attributes

    Hi,
    I was trying to use default xml namespaces, but came upon something strange.
    I got the following piece of xml:
    <animal type="sheep" xmlns="http://blabla">
        <name>josh</name>
        <age>2</age>
    </animal>
    and the following code
    public static var ns:Namespace = new Namespace("http://blabla");
    var xml:XML; // xml will be read into this var, not going into details here
    public function myfunc():void {
      default xml namespace = ns;
      trace(  xml.animal.@type );
    now for some reason, the elements are correctly traversed using the default namespace. But the attribute isn't found. After a bit of debugging, I found that I could only retrieve the attribute when using xml.animal.attribute(new QName("", "type")). Am I doing something wrong here? Why isn't the attribute in the same default namespace as the element?
    Kind regards,
    Jan

    The attribute should be in the element's namespace. If I run this snippet on the timeline, it outputs the correct values.
    var xml:XML =
    <xml>
    <animal type="sheep" xmlns="http://blabla">
      <name>josh</name>
      <age>2</age>
    </animal>
    <animal type="cow" xmlns="http://blabla">
      <name>jim</name>
      <age>2</age>
    </animal>
    </xml>
    var ns:Namespace = new Namespace("http://blabla");
    default xml namespace = ns;
    trace( xml.animal.@type ); // OUTPUT: sheepcow

  • Element name and attribute completion in XML editor?

    With either WebLogic Workshop 9.2.2 or 10.x, is it possible to get completion assistance on elements and attributes? It works in the JSP editor, but I need to know whether this will work for XML documents. For some of these namespaces, they are defined in JSF taglibs.

    I tested this on an .xhtml doc. Right-clicking gives me these options:
    * HTML Editor
    * Text Editor
    * System Editor
    * In-Place Editor
    * Default Editor
    Is this perhaps a feature available in 10.1?

  • How to create a user using XML and specifying addional attributes that are objects

    I'm trying to create a user using XML and specifying some attributes that are objects and not sure how to do it. How would I set the DirectoryUserAcl to Public?
    Here's the xml file:
    <?xml version = '1.0' standalone = 'yes'?>
    <SimpleUser>
    <UserName>mike2</UserName>
    <Password>abc123</Password>
    <AdminEnabled>false</AdminEnabled>
    <HomeFolderRoot>/home</HomeFolderRoot>
    <HasContentQuota>false</HasContentQuota>
    <DirectoryUserAcl> ??? </DirectoryUserAcl>
    <DefaultAclBundleAcl> ??? </DefaultAclBundleAcl>
    <HomeFolderPolicyBundleAcl> ??? </HomeFolderPolicyBundleAcl>
    </SimpleUser>

    I figured out the answer:
    <?xml version = '1.0' standalone = 'yes'?>
    <SimpleUser>
    <UserName>mike2</UserName>
    <Password>abc123</Password>
    <AdminEnabled>false</AdminEnabled>
    <HomeFolderRoot>/home</HomeFolderRoot>
    <HasContentQuota>false</HasContentQuota>
    <DirectoryUserAcl classname="SystemAccessControlList" refType="name">Public</DirectoryUserAcl>
    </SimpleUser>
    null

  • OC4J orion-application.xml - elements and attributes

    Hi. i read in oracle docs sentense like this: "Each property maps to an element attribute in the orion-application.xml descriptor." These properties are from deployment plan and i need to know what is the name of the element in orion-application.xml wich is mapped to webSiteBinding property (from deployment plan).

    I just did a quick test of this, and it seems to work for me.
    I used the following XML:
    <?xml version="1.0" encoding="iso-8859-1"?>
    <Employees xmlns="
    http://www.foo.com/Employees">
    <Employee Id="001">
    <LastName>Davis</LastName>
    <FirstName>Kirk</FirstName>
    </Employee>
    <Employee Id="002">
    <LastName></LastName>
    <FirstName>James</FirstName>
    </Employee>
    <Employee Id="003">
    <FirstName>Anthony</FirstName>
    </Employee>
    <Employee>
    </Employee>
    </Employees>
    With the XPath "/Employees/Employee" I got rows in the data
    set and things displayed fine in my page. Changing it to
    "/employees/employee" caused the data set to have no rows which I
    would expect since things should be case sensitive.
    Can you provide me with some sample XML and XPath that
    doesn't work?
    Thanks!
    --== Kin ==--

  • Multiple plugtmp-1 plugtmp-2 etc. in local\temp folder stay , crossdomain.xml and other files containing visited websitenames created while private browsing

    OS = Windows 7
    When I visit a site like youtube whith private browsing enabled and with the add-on named "shockwave flash" in firefox add-on list installed and activate the flashplayer by going to a video the following files are created in the folder C:\Users\MyUserName\AppData\Local\Temp\plugtmp-1
    plugin-crossdomain.xml
    plugin-strings-nl_NL-vflLqJ7vu.xlb
    The contents of plugin-crossdomain contain both the "youtube.com" adress as "s.ytimg.com" and is as follows:
    <?xml version="1.0"?>
    <!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
    -<cross-domain-policy> <allow-access-from domain="s.ytimg.com"/> <allow-access-from domain="*.youtube.com"/> </cross-domain-policy>
    The contents of the other file I will spare you cause I think those are less common when I visit other sites but I certainly don't trust the file. The crossdomain.xml I see when I visit most other flashpayer sites as well.
    I've also noticed multiple plugin-crossdomain-1.xml and onwards in numbers, I just clicked a youtube video to test, got 6 of them in my temp plus a file named "plugin-read2" (no more NL file cause I changed my country, don't know how youtube knows where I'm from, but that's another subject, don't like that either). I just noticed one with a different code:
    <?xml version="1.0"?>
    -<cross-domain-policy> <allow-access-from domain="*"/> </cross-domain-policy>
    So I guess this one comprimises my browsing history a bit less since it doesn't contain a webadress. If these files are even meant to be deposited in my local\temp folder. The bigger problem occurs when they stay there even after using private browsing, after clearing history, after clearing internet temporary files, cache, whatever you can think of. Which they do in my case, got more than 50 plugtmp-# folders in the previous mentioned local\temp folder containing all website names I visited in the last months. There are a variety of files in them, mostly ASP and XML, some just say file. I have yet to witness such a duplicate folder creation since I started checking my temp (perhaps when firefox crashes? I'd say I've had about 50 crashes in recent months).
    I started checking my temp because of the following Microsoft Security Essential warnings I received on 23-4-12:
    Exploit:Java/CVE-2010-0840.HE
    containerfile:C:\Users\Username\AppData\Local\Temp\jar_cache2196625541034777730.tmp
    file:C:\Users\Username\AppData\Local\Temp\jar_cache2196625541034777730.tmp->pong/reversi.class
    and...
    Exploit:Java/CVE-2008-5353.ZT
    containerfile:C:\Users\Noname\AppData\Local\Temp\jar_cache1028270176376464057.tmp
    file:C:\Users\Noname\AppData\Local\Temp\jar_cache1028270176376464057.tmp->Testability.class
    Microsoft Security Essentials informed me that these files were quarantained and deleted but when going to my temp file they were still there, I deleted them manually and began the great quest of finding out what the multiple gigabytes of other files and folders were doing in that temp folder and not being deleted with the usual clearing options within firefox (and IE).
    Note that I have set my adobe flasplayer settings to the most private intense I could think of while doing these tests (don't allow data storage for all websites, disable peer-to peer stuff, don't remember exactly anymore, etc.). I found it highly suspicious that i needed to change these settings online on an adobe website, is that correct? When right-clicking a video only limited privacy options are available which is why I tried the website thing.
    After the inital discovery of the java exploit (which was discovered by MSE shortly after I installed and started my first scan with Malwarebytes, which in turn made me suspicious whether I had even downloaded the right malwarebytes, but no indication in the filename if I google it). Malwarebytes found nothing, MSE found nothing after it said it removed the files, yet it didn't remove them, manually scanning these jar_cache files with both malwarevytes and MSE resulted in nothing. Just to be sure, I deleted them anyways like I said earlier. No new jar_cache files have been created, no exploits detected since then. CCleaner has cleaned most of my temp folder, I did the rest, am blocking all cookies (except for now shortly), noscript add-on has been running a while on my firefox (V 3.6.26) to block most javascripts except from sites like youtube. I've had almost the same problem using similar manual solutions a couple of months ago, and a couple of months before that (clearing all the multiple tmp folders, removing or renaming jar_cache manually, running various antmalware software, full scan not finding a thing afterwards, installing extra add-ons to increase my security, this time it's BetterPrivacy which I found through a mozilla firefox https connection, I hope, which showed me nicely how adobe flash was still storing LSO's even after setting all storage settings to 0 kb and such on the adobe website, enabling private browsing in firefox crushed those little trolls, but still plugtmp trolls are being created, help me crush them please, they confuse me when I'm looking for a real threat but I still want to use flash, IE doesn't need those folders and files, or does it store them somewhere else?).
    I'm sorry for the long story and many questions, hope it doesn't scare you away from helping me fight this. I suspect it's people wanting to belong to the hackergroup Anonymous who are doing this to my system and repeating their tricks (or the virus is still there, but I've done many antivirus scans with different programs so no need to suggest that option to me, they don't find it or I run into it after a while again, so far, have not seen jar_cache show up). Obviously, you may focus on the questions pertaining firefox and plugtmp folders, but if you can help me with any information regarding those exploits I would be extremely grateful, I've read alot but there isn't much specific information for checking where it comes from when all the anti-virus scanners don't detect anything anymore and don't block it incoming. I also have downloaded and installed process monitor but it crashes when I try to run it. The first time I tried to run it it lasted the longest, now it crashes after a few seconds, I just saw the number of events run up to almost a million and lots of cpu usage. When it crashed everything returned back to normal, or at least that's what I'm supposed to think I guess. I'll follow up on that one on their forum, but you can tell me if the program is ligit or not (it has a microsoft digital signature, or the name micosoft is used in that signature).

    update:
    I haven't upgraded my firefox yet because of a "TVU Web Player" plugin that isn't supported in the new firefox and I'm using it occasionally, couldn't find an upgrade for it. Most of my other plugins are upgraded in the green (according to mozilla websitechecker):
    Java(TM) Platform SE 6 U31 (green)
    Shockwave for Director (green - from Adobe I think)
    Shockwave Flash (green - why do I even need 2 of these adobe add-ons? can I remove one? I removed everything else i could find except the reader i think, I found AdobeARM and Adobe Acrobat several versions, very confusing with names constantly switching around)
    Java Deployment Toolkit 6.0.310.5 (green, grrr, again a second java, why do they do this stuff, to annoy people who are plagued with java and flash exploits? make it more complicating?)
    Adobe Acrobat (green, great, it's still there, well I guess this is the reader then)
    TVU Web Player for FireFox (grey - mentioned it already)
    Silverlight Plug-In (yellow - hardly use it, I think, unless it's automatic without my knowing, perhaps I watched one stream with it once, I'd like to remove it, but just in case I need it, don't remember why I didn't update, perhaps a conflict, perhaps because I don't use it, or it didn't report a threat like java and doesn't create unwantend and history compromising temp files)
    Google Update (grey - can I remove? what will i lose? don't remember installing it, and if I didn't, why didn't firefox block it?)
    Veetle TV Core (grey)
    Veetle TV Player (grey - using this for watching streams on veetle.com, probably needs the Core, deleted the broadcaster that was there earlier, never chose to install that, can't firefox regulate that when installing different components? or did i just miss that option and assumed I needed when I was installing veetle add-on?)
    Well, that's the list i get when checking on your site, when i use my own browseroptions to check add-ons I get a slightly different and longer list including a few I have already turned off (which also doesn't seem very secure to me, what's the point in using your site then for anything other than updates?), here are the differences in MY list:
    I can see 2 versions of Java(TM) Platform SE 6 U31, (thanks firefox for not being able to copy-paste this)
    one "Classic Java plug-in for Netscape and Mozilla"
    the other is "next generation plug-in for Mozilla browsers".
    I think I'll just turn off the Netscape and Mozilla one, don't trust it, why would I need 2? There I did it, no crashes, screw java :P
    There's also a Mozilla Default plugin listed there, why does firefox list it there without any further information whether I need it or not or whether it really originates from Mozilla firefox? It doesn't even show up when I use your website plugin checker, so is there no easy way by watching this list for me to determin I can skip worrying about it?
    There's also some old ones that I recently deactivated still listed like windows live photo gallery, never remember adding that one either or needing it for anything and as usual, right-clicking and "visit homepage" is greyed out, just as it is for the many java crap add-ons I encountered so far.
    Doing a quick check, the only homepage I can visit is the veetle one. The rest are greyed out. I also have several "Java Console" in my extentions tab, I deactivated all but the one with the highest number. Still no Java Console visible though, even after going to start/search "java", clicking java file and changing the settings there to "show" console instead of "hide" (can't remember exact details).
    There's some other extentions from noscript, TVU webplayer again, ADblock Plus and now also BetterPrivacy (sidenote, a default.LSO remains after cleanup correct? How do I know that one isn't doing anything nasty if it's code has been changed or is being changed? To prevent other LSO's I need to use both private browsing and change all kinds of restrictions online for adobe flashplayer, can anyone say absurd!!! if you think you're infected and want to improve your security? Sorry that rant was against Adobe, but it's really against Anonymous, no offense).

  • Draw figures from a xml and then draw anothers when I click on them

    This is what I have to do:
    I got a XML file with the info of a drawing: circles, rectangles.....
    I read the file and I draw the figures on a JPanel.
    And now what I have to do is this:
    When I click on a figure I have to recognize what figure is, for example, rectangle number 2 on the XML file. Then I have to read the XML and foud what I have to draw when I click on that figure, this info is on the XML:
    <Transition Rectangle="2" NextDraw="Rectangle 3" />
    How do I draw all these figures and keep the info I need (name and number of the figure)? And how do I manage mouse events for recognize the click on a figure for draw anothers.
    Sorry for my bad english and thanks

    I don't know the structure of your XML file.
    Anyway, I guess it's something like the following :
    shapes.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <shapes>
         <Transition Rectangle="1" NextDraw="Rectangle 2" />
         <Transition Rectangle="2" NextDraw="Rectangle 3" />
         <Transition Rectangle="3" NextDraw="Circle 1" />
         <Transition Circle="1" NextDraw="Circle 2" />
         <Transition Circle="2" NextDraw="Circle 3" />
         <Transition Circle="3" />
    </shapes>Here the java code. Plz, take a look at it and adapt it to your needs.
    XMLParserHandler.java
    import java.util.HashMap;
    import java.util.Map;
    import org.xml.sax.Attributes;
    import org.xml.sax.SAXException;
    import org.xml.sax.SAXParseException;
    import org.xml.sax.helpers.DefaultHandler;
    public class XMLParserHandler extends DefaultHandler {
         Map<String, String> shapes;
         public XMLParserHandler(){
              shapes = new HashMap<String, String>();
         public void startDocument() throws SAXException {
              //System.out.println("Start Shapes Document.xml");
              shapes = new HashMap<String, String>();
         public void endDocument() throws SAXException {
              //System.out.println("End Shapes shapes.xml");
         public void startElement(String uri, String localName, String qName,
                   Attributes attributes) throws SAXException {
              //System.out.println("Start Element : " + qName);
              //display(attributes);
              if("TRANSITION".equals(qName.toUpperCase())){
                   String key = null;
                   String value = "";
                   int n = attributes.getLength();
                   String attrName;
                   for (int i = 0; i < n; i++) {
                        attrName = attributes.getQName(i);
                        if(! "NEXTDRAW".equals(attrName.toUpperCase())){
                             key = new String(attrName+" "+attributes.getValue(i));
                        }else{
                             value = new String(attributes.getValue(i));
                   if(key!=null){
                        shapes.put(key.toUpperCase(), value.toUpperCase());
         public void endElement(String uri, String localName, String qName)
                   throws SAXException {
              //System.out.println("End Element : " + qName);
         public void characters(char[] ch, int start, int length)
                   throws SAXException {
              //System.out.println(new String(ch, start, length));
         public void error(SAXParseException e) throws SAXException {
              throw e;
         public void fatalError(SAXParseException e) throws SAXException {
              throw e;
         public Map<String, String> getShapes() {
              return shapes;
         private void display(Attributes attrs){
              int n = attrs.getLength();
              for (int i = 0; i < n; i++) {
                   System.out.println("***"+attrs.getQName(i)+" = "+attrs.getValue(i));
    MyPanel.java
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Shape;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.awt.geom.Ellipse2D;
    import java.awt.geom.Rectangle2D;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Map;
    import javax.swing.JPanel;
    public class MyPanel extends JPanel {
         static String CIRCLE = "CIRCLE";
         static String RECTANGLE = "RECTANGLE";
         public List shapeList;
         int currentIndex = 0;
         Shape currentShape;
         public MyPanel(Map shapes, String entry) {
              createShapeList(shapes, entry);
              addMouseListener(new MyMouseListener());
         private String getShapeName(String value){
              return value.split("\\s+")[0];
         private void createShapeList(Map shapes, String entry){
              shapeList = new ArrayList();
              Shape shape=null;
              String key = new String(entry);
              String value ;
              int i=0;
              do{
                   value=getShapeName(key);
                   System.out.println(value);
                   if(CIRCLE.equals(value)){
                        shape = new Ellipse2D.Double(5, 5+40*i, 20, 20);
                        System.out.println("==> added circle");
                   }else if(RECTANGLE.equals(value)){
                        shape = new Rectangle2D.Double(5, 5+40*i, 20, 20);
                        System.out.println("==> added rectangle");
                   shapeList.add(shape);
                   key = (String)shapes.get(key);
                   i++;
              }while(value!=null&&value.trim().length()>0);
              currentShape = (Shape)shapeList.get(currentIndex);
         class MyMouseListener extends MouseAdapter{
              public void mouseClicked(MouseEvent e) {
                   int x = e.getX();
                   int y = e.getY();
                   if(currentShape.contains(x, y)){
                        if(currentIndex<shapeList.size()-1){
                             currentIndex++;
                             currentShape = (Shape)shapeList.get(currentIndex);
                             repaint();
         public void paint(Graphics g) {
              Graphics2D g2 = (Graphics2D) g;
              g2.setPaint(Color.red);
              for (int i = 0; i < currentIndex+1; i++) {
                   g2.fill((Shape)shapeList.get(i));
    Main.java
    import java.io.File;
    import java.util.Map;
    import javax.swing.JFrame;
    import javax.xml.parsers.SAXParser;
    import javax.xml.parsers.SAXParserFactory;
    public class Main {
         public static void main(String[] args) {
              SAXParserFactory spf = SAXParserFactory.newInstance();
              SAXParser parser;
              Map myShapes = null;
              try {
                   parser = spf.newSAXParser();
                   XMLParserHandler handler = new XMLParserHandler();
                   parser.parse(new File("shapes.xml"), handler);
                   myShapes = handler.getShapes();
                   String entry = "RECTANGLE 1";
                   //Create and set up the window.
                   JFrame frame = new JFrame("MyFrame");
                   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                   // Create and set up the content pane.
                   MyPanel newContentPane = new MyPanel(myShapes, entry);
                   newContentPane.setOpaque(true); // content panes must be opaque
                   frame.setContentPane(newContentPane);
                   // Display the window.
                   frame.setSize(400, 400);
                   frame.setResizable(false);
                   frame.setVisible(true);
              }catch(Exception e){
                   e.printStackTrace();
    NB: as mentioned in the Main class (see main method), you should provide the main entry for your xml file : String entry = "RECTANGLE 1";Hope That Helps

  • XML Pagemap attributes

    I have been trying to find all the different attributes that can be used in a pagemap but cannot find them using a search engine, anyone know where I can find them please?

    I have simular problems with xml documents. Added a extra taglibrary with separate code coloring and sometimes it shows up, sometimes it don't. And after some editing it will appear, but not on all tags. Apart from that, sometimes attributes will show in a list, sometimes they don't.
    Think that something is not right in CS4 (on windows xp sp3).
    Grtz

  • Sun-web.xml and additional classpaths

    Got sun webserver 6.1 running on Solaris.
    In development we need a web app to include additional classes over and above those found in the WEB-INF/classes directory.
    This was achieved in web server 6.0 by adding an extra classpath into the relevant web app definition in web-apps.xml.
    In 6.1 this is achieved through the sun-web.xml file using the 'extra-class-path' attribute within the 'class-loader' tag.
    Only it doesn't work.
    I don't think the sun-web.xml file is even being read as it doesn't pick up any (deliberate) XML errors!
    Anyone got any ideas / help / an example sun-web.xml file that uses 'extra-class-path' ?
    Thanks in advance,
    Kevin P.

    The problem is that the sun-web.xml is specific to the server you're deploying to. (It might look like the one for the bundled PE but that's just by accident:-()
    Also different containers (like the Sun Web Server, the Application Server) use the same file name but different schemas/DTD's for that file:-(
    So we decided to not include it.
    But you have the source, everything is done via Ant;-) Look at the build.xml and nbproject/build-impl.xml in your project;-)
    I hope that helps;-)
    -- Marco

  • Parsing XML and Storing values in instance variable

    hi,
    i'm new to XML.
    here i'm trying to parse an XML and store their element data to the instance variable.
    in my main method i'm tried to print the instance variable. but it shows "" (ie it print nothing ).
    i know the reason, its becas of the the endElement() event generated and it invokes the characters() and assigns "" to the instance variable.
    my main perspective is to store the element data in instance variable.
    thanks in advance.
    praks
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import javax.xml.parsers.*;
    import org.xml.sax.*;
    import org.xml.sax.helpers.*;
    public class mysax extends DefaultHandler
         String ctelement;
         CharArrayWriter contents;
         String vname1,vrcbreg1,vaddress1,vcountry1,vtelephone1,vfax1;
         String vname,vrcbreg,vaddress,vcountry,vtelephone,vfax;
         public mysax()
              vname1 = null;
              vrcbreg1 = null;
              vaddress1 = null;
              vcountry1 = null;
              vtelephone1 = null;
              vfax1 = null;
              contents= new CharArrayWriter();
         public void doparse(String url) throws Exception
              SAXParserFactory spf = SAXParserFactory.newInstance();
    SAXParser sp = spf.newSAXParser();
    ParserAdapter pa = new ParserAdapter(sp.getParser());
    pa.setContentHandler(this);
    pa.parse(url);          
         public void startElement(String namespace,String localName,String qName,Attributes atts)
              ctelement = localName;     
         public void endElement(String uri,String localName,String qName) throws SAXException
         public void characters(char[] ch,int start, int length) throws SAXException
              try
                   if(ctelement.equals("name"))
                        vname = new String (ch,start,length);
                        System.out.println("The method "+vname1);
              }catch (Exception e)
                   System.out.println("The exception "+e);
         public static void main(String args[])
              try
              mysax ms = new mysax();
              ms.doparse(args[0]);
              System.out.println("the contents name "+ms.vname1);
              catch(Exception e)
                   System.out.println("this is exception at main" +e);
    my XML looks like
    <coyprofile_result>
    <company>     
    <name>abcTech</name>
    <rcbreg>123456789</rcbreg>
    <address>Singapore</address>
    <country>sg</country>
    <telephone>123456</telephone>
    <fax>123155</fax>
    </company>
    </coyprofile_result>

    I believe that the problem has to do with the value you assign to ctelement. You are assigning the value of localName to ctElement, however for the element: <name>...</name> the localname is empty string i.e. "", but qName equals "name". Because you are assigning empty string to ctElement, when you do the comparison in characters of ctElement to "name" it will always be false. So in startElement change it to ctElement = qName; Try it and see if it works. I have produced similar programs and it works for me.
    Hope this helps.

  • Get Javascript values and use them in a servlet?

    Hey
    I have a HTML which has Javascript scripts which I have to get values from (a array to be exact) and pass them to a servlet so I can process the information in a certain way. I cant seem to find a way to do this properly as the servlet is server side and Javascript is client side. How can I implement this?
    Using a quick example example I have
    C:/index.html
    C:/js/script.js
    Index.html contains:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <script type="text/javascript" src="js/script.js">
    </script>
    </head>
    <body>
    a href="javascript:void(0);" id="add"><img src="images/menunew.png" alt="plus" border="0" />
    /a>
    </body>
    </html>
    Script.js contains:
    var Script = Class.create({
    a:4,
    b:5,
    add: function(){       
    return (this.a + this.b);
    (Ignore syntaxis errors as this is a quick example I wrote up just to see if you can give me a practical example on how to read it.)
    How can from a Java servlet access a and b from the script.js file (which contains a class named Script) and also access the function add which returns that value?
    Thank you for the help
    Edited by: 902756 on 16-dic-2011 0:18

    DrClap wrote:
    902756 wrote:
    1: Yes, it seems like the logically answer but Im not too up on AJAX and even less on mixing it up with servlets. Do you mind giving me a simple add (function) sample or something similar?You are looking at it the wrong way. What you actually want to do is to have the browser send a request (which somehow contains that Javascript data) to a URL which causes the servlet to receive the data. There's no "mixing it up" going on there. The client and the server are entirely separate.
    And since that request would be an HTTP request, it's just text. There's no concept in HTTP of transmitting objects, whether they be Javascript objects or Java objects. Anything you want to transmit has to be converted into text by the sender and converted back into objects by the receiver.
    So there's no such thing as "a simple add function". You're going to have to stop thinking in that way and start thinking of client-server systems in the way they actually are.The thing is I want to start simple to grab a simple concept....
    Im trying a AJAX route and I have the following:
    /index.html
    /js/Adding.js
    Index contains:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
         <title></title>
         <script type="text/javascript" src="js/Adding.js"></script>
    </head>
    <body>
    <select name="num1">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    </select>
    <select name="num2">
    <option value="5">5</option>
    <option value="6">6</option>
    <option value="7">7</option>
    <option value="8">8</option>
    </select>
    <form method="get" name="adding">
    Do
    <span id="res"></span>
    </form>
    </body>
    </html>
    Adding.js contains
    var Adding = Class.create({
    x: null,
    y: null,
    add: function()
         var xmlHttp = new XMLHttpRequest();
         var value1 = document.getElementById("num1").value;
    var value2 = document.getElementById("num2").value;
         xmlHttp.open("GET", "index.html", false);
         xmlHttp.send(value1 + value2);
         var result = document.getElementById("res");
         result.innerHTML = xmlHttp.responseText;
    This shows 2 comboboxes full of numbers and link saying "Do" which calls the javascript function and adds the two numbers in the comboboxs and shows them on the screen without refreshing the page. This does not work and I would like this to work before I continue onto the bigger picture.

  • Inserting a node in XML and retaining the doc type

    Hi All,
    I want to insert one new node in an XML. Using the following code I can do that. But the problem is if the XML has doc type declaration then its giving me problem. After inserting the node the transformer is removing my doc type declaration from the XML. I have to retain the doc type definition (including entity declaration) as it is in the original XML file.
    The following is the code that I'm using.
    Document vDoc = null;
    try {
    // Contruct the DOM document
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    vDoc = builder.newDocument();
    Node vFormNode = vDoc.createElement("Form");
    vDoc.appendChild(vFormNode);
    // Convert into a String the DOM document
    TransformerFactory tFactory = TransformerFactory.newInstance();
    Transformer transformer = tFactory.newTransformer();
    DOMSource source = new DOMSource(vDoc);
    StringWriter sw = new StringWriter();
    StreamResult result = new StreamResult(sw);
    transformer.transform(source, result);
    catch (Exception e) {
    System.out.println("Error: " + e.getMessage());
    }The doc type def. in the original file is some thing like this.
    <!DOCTYPE article SYSTEM "someurl/TFJA.dtd"[
    <!ENTITY T0001 SYSTEM ".\BTN_A_000112809_O_XML_IMAGES\BTN_A_000112809_O_T0001.gif" NDATA GIF>
    <!ENTITY F0001 SYSTEM ".\BTN_A_000112809_O_XML_IMAGES\BTN_A_000112809_O_F0001g.gif" NDATA GIF>
    <!ENTITY F0002 SYSTEM ".\BTN_A_000112809_O_XML_IMAGES\BTN_A_000112809_O_F0002g.jpg" NDATA JPEG>
    ]>I know that I can set up the doc type definition in the new XML using the following properties of the transformer.
    transformer.setOutputProperty( OutputKeys.DOCTYPE_SYSTEM,"article" );
    transformer.setOutputProperty( OutputKeys.DOCTYPE_PUBLIC,"my DTD def");
    I cannot hard code the DTD def. as it can vary from one XML to another. Using doc.getDocType() I can get the doctype of the original XML. But is it is not returning the complete def. including entities declaration. Its giving me "someurl/TFJA.dtd".
    Is there any way to retain the complete doc type in the original XML file? I don't have much experience in XML and this issue is eating my head.. Also do I have to modify the DTD to accommodate the new tags added in order to make it a valid XML?
    Any help and sample code would be highly appreciated.

    Hi,
    I also had similar requirement and when searching i came across this post. Later i found the solution for this. Instead of hardcoding the doctype you can get it from Document as follows..Snippet from the code i used..
    DocumentType doctype = document.getDoctype();
    if(doctype != null) {
                   String id = doctype.getSystemId();
                   if(id == null || id.length() == 0)
                        return;
                   transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, id);
                   id = doctype.getPublicId();
                   if(id == null || id.length() == 0)
                        return;
                   transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, id);
    Hope this helps.
    Regards,
    Deepak

  • When I try to start Firefox I get an Error Message: (Javascript /application) Error on adding toolbar element. TypeError, aButtonLabel is undefined. id. Google Shortcut settings

    When I try to start Firefox I get an Error Message: (Javascript /application) Error on adding toolbar element. TypeError, aButtonLabel is undefined. id. Google Shortcut settings. Firefox will not start. I have been through the troubleshooting steps. Nothing helps
    == I tried to enter Firefox. No apparant reason ==
    == User Agent ==
    Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.2; AskTbGLSV5/5.8.0.12304)

    Hi,
    had this problem but now sorted.
    Go to settings for google shortcuts, follow link to homepage and upload latest version, it has not yet been approved by Firefox, but works and solves the bug.
    Hope this helps.
    A

Maybe you are looking for

  • Import procedure

    Hello In Import pricing procedure, when i did MIro for Custom clearing vendor, then 16% CVD ,2%cess and 1%^ EDcess, i want to add these all taxes to material cost, plz guide me how to add these taxes to material cost, how to make ? regards sapman

  • Itunes File Sharing: Adding files doesn't work

    Hi, i have a problem adding files via Itunes File Sharing in Apps. Here's my setup: Windows 7 64bit, german Itunes 11.1.5.5, x64, german Iphone 5s, 32GB, directly attached via USB several apps with file sharing support (OpenVPN, VLC, Good Reader...)

  • Misbehaving Attachments in Mail

    When I attach a document in Mail (usually a PDF) it sometimes shows up as a icon with a PDF symbol and other times it actually opens up the document in the mail message (this also happens with JPEGs). This drives me crazy because I apparently have no

  • Bluescreen - Caught in an infinite loop

    Hello, I have a strange Problem with my System. Everytime I use a 2D/3D progam it freeze after about 30 minutes. But the strangest thing is, new games like Quake4 , F.E.A.R and Oblivion do not freeze. I tried everything that I know. - Ran Memtest86+

  • Error -603 (could not install extension) notification keeps popping up when I sign into CC even though I've installed the extension trough Extension Manager

    Hi like my question says above, purchased an extension and installed it manually because it would not install automatically (error -603) but now I keep getting the same message/notification every time that I log into CC when starting the computer or