JDOM and &qout;

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mali_djuro

    JDOM and &qout;

    Hi all,
    i used JDOM to create XML file.
    first, i get data from database and create Document object. in some data i
    have quotas, so it makes replacment in content of elements. for example:
    if i have "Hi" in database, i will have "Hi&quo t; in content of
    element. And it is ok, because in xml does not exist ", at least i think
    that.
    After it i want to make convert from document to string. I used

    XMLOutputter serializer = new XMLOutputter();
    String output = serializer.outp utString(docume nt);

    now, when i look what's happened with "Hi&quo t; i found following
    string
    "Hi&am p;quot;
    it makes conversion of & again, and that is not ok.

    has someone similiar problem? or do you know how to solve it?

    i can make parsing of string again and cut what is wrong, but is it possible
    to set something without that?

    thanks in advance.


  • Raymond DeCampo

    #2
    Re: JDOM and &qout;

    mali_djuro wrote:[color=blue]
    > Hi all,
    > i used JDOM to create XML file.
    > first, i get data from database and create Document object. in some data i
    > have quotas, so it makes replacment in content of elements. for example:
    > if i have "Hi" in database, i will have "Hi&quo t; in content of
    > element. And it is ok, because in xml does not exist ", at least i think
    > that.
    > After it i want to make convert from document to string. I used
    >
    > XMLOutputter serializer = new XMLOutputter();
    > String output = serializer.outp utString(docume nt);
    >
    > now, when i look what's happened with "Hi&quo t; i found following
    > string
    > "Hi&am p;quot;
    > it makes conversion of & again, and that is not ok.
    >
    > has someone similiar problem? or do you know how to solve it?
    >
    > i can make parsing of string again and cut what is wrong, but is it possible
    > to set something without that?
    >[/color]

    Friend,

    It is likely that the good people at JDOM have already considered your
    problem and are accounting for it themselves. So, it is probably safe
    to simply pass "Hi" directly to the JDOM API without prior escaping.

    Ray

    Comment

    • mali_djuro

      #3
      Re: JDOM and &qout;

      Hi,
      i didn't understand you.
      i need to create document object and than transform it to string, or file.

      if you have some examples please write to me.

      thanks.

      "Raymond DeCampo" <rdecampo@spa m-I-am-not.twcny.rr.co m> wrote in message
      news:AGWSb.1545 2$%72.3792@twis ter.nyroc.rr.co m...[color=blue]
      > mali_djuro wrote:[color=green]
      > > Hi all,
      > > i used JDOM to create XML file.
      > > first, i get data from database and create Document object. in some data[/color][/color]
      i[color=blue][color=green]
      > > have quotas, so it makes replacment in content of elements. for example:
      > > if i have "Hi" in database, i will have &quot;Hi&quo t; in content of
      > > element. And it is ok, because in xml does not exist ", at least i think
      > > that.
      > > After it i want to make convert from document to string. I used
      > >
      > > XMLOutputter serializer = new XMLOutputter();
      > > String output = serializer.outp utString(docume nt);
      > >
      > > now, when i look what's happened with &quot;Hi&quo t; i found following
      > > string
      > > &amp;quot;Hi&am p;quot;
      > > it makes conversion of & again, and that is not ok.
      > >
      > > has someone similiar problem? or do you know how to solve it?
      > >
      > > i can make parsing of string again and cut what is wrong, but is it[/color][/color]
      possible[color=blue][color=green]
      > > to set something without that?
      > >[/color]
      >
      > Friend,
      >
      > It is likely that the good people at JDOM have already considered your
      > problem and are accounting for it themselves. So, it is probably safe
      > to simply pass "Hi" directly to the JDOM API without prior escaping.
      >
      > Ray
      >[/color]


      Comment

      • Raymond DeCampo

        #4
        Re: JDOM and &amp;qout;

        mali_djuro wrote:[color=blue]
        > Hi,
        > i didn't understand you.
        > i need to create document object and than transform it to string, or file.
        >
        > if you have some examples please write to me.
        >
        > thanks.
        >
        > "Raymond DeCampo" <rdecampo@spa m-I-am-not.twcny.rr.co m> wrote in message
        > news:AGWSb.1545 2$%72.3792@twis ter.nyroc.rr.co m...
        >[color=green]
        >>mali_djuro wrote:
        >>[color=darkred]
        >>>Hi all,
        >>>i used JDOM to create XML file.
        >>>first, i get data from database and create Document object. in some data[/color][/color]
        >
        > i
        >[color=green][color=darkred]
        >>>have quotas, so it makes replacment in content of elements. for example:
        >>>if i have "Hi" in database, i will have &quot;Hi&quo t; in content of
        >>>element. And it is ok, because in xml does not exist ", at least i think
        >>>that.
        >>>After it i want to make convert from document to string. I used
        >>>
        >>>XMLOutputt er serializer = new XMLOutputter();
        >>>String output = serializer.outp utString(docume nt);
        >>>
        >>>now, when i look what's happened with &quot;Hi&quo t; i found following
        >>>string
        >>>&amp;quot;Hi &amp;quot;
        >>>it makes conversion of & again, and that is not ok.
        >>>
        >>>has someone similiar problem? or do you know how to solve it?
        >>>
        >>>i can make parsing of string again and cut what is wrong, but is it[/color][/color]
        >
        > possible
        >[color=green][color=darkred]
        >>>to set something without that?
        >>>[/color]
        >>
        >>Friend,
        >>
        >>It is likely that the good people at JDOM have already considered your
        >>problem and are accounting for it themselves. So, it is probably safe
        >>to simply pass "Hi" directly to the JDOM API without prior escaping.
        >>
        >>Ray
        >>[/color]
        >[/color]

        Please do not top post, especially in reply to someone who has bottom
        posted.

        If you wish more specific advise, you will have to supply more specific
        code yourself. For example, what is document in your code above?
        Ideally, you should post the smallest possible complete program that
        exhibits the issue you are having. Provide the expected and actual
        outputs. I suspect you will be most pleased from the response of the group.

        Ray

        Comment

        • mali_djuro

          #5
          Re: JDOM and &amp;qout;


          "Raymond DeCampo" <rdecampo@spa m-I-am-not.twcny.rr.co m> wrote in message
          news:tICTb.2834 8$n62.22674@twi ster.nyroc.rr.c om...[color=blue]
          > mali_djuro wrote:[color=green]
          > > Hi,
          > > i didn't understand you.
          > > i need to create document object and than transform it to string, or[/color][/color]
          file.[color=blue][color=green]
          > >
          > > if you have some examples please write to me.
          > >
          > > thanks.
          > >
          > > "Raymond DeCampo" <rdecampo@spa m-I-am-not.twcny.rr.co m> wrote in message
          > > news:AGWSb.1545 2$%72.3792@twis ter.nyroc.rr.co m...
          > >[color=darkred]
          > >>mali_djuro wrote:
          > >>
          > >>>Hi all,
          > >>>i used JDOM to create XML file.
          > >>>first, i get data from database and create Document object. in some[/color][/color][/color]
          data[color=blue][color=green]
          > >
          > > i
          > >[color=darkred]
          > >>>have quotas, so it makes replacment in content of elements. for[/color][/color][/color]
          example:[color=blue][color=green][color=darkred]
          > >>>if i have "Hi" in database, i will have &quot;Hi&quo t; in content of
          > >>>element. And it is ok, because in xml does not exist ", at least i[/color][/color][/color]
          think[color=blue][color=green][color=darkred]
          > >>>that.
          > >>>After it i want to make convert from document to string. I used
          > >>>
          > >>>XMLOutputt er serializer = new XMLOutputter();
          > >>>String output = serializer.outp utString(docume nt);
          > >>>
          > >>>now, when i look what's happened with &quot;Hi&quo t; i found following
          > >>>string
          > >>>&amp;quot;Hi &amp;quot;
          > >>>it makes conversion of & again, and that is not ok.
          > >>>
          > >>>has someone similiar problem? or do you know how to solve it?
          > >>>
          > >>>i can make parsing of string again and cut what is wrong, but is it[/color]
          > >
          > > possible
          > >[color=darkred]
          > >>>to set something without that?
          > >>>
          > >>
          > >>Friend,
          > >>
          > >>It is likely that the good people at JDOM have already considered your
          > >>problem and are accounting for it themselves. So, it is probably safe
          > >>to simply pass "Hi" directly to the JDOM API without prior escaping.
          > >>
          > >>Ray
          > >>[/color]
          > >[/color]
          >
          > Please do not top post, especially in reply to someone who has bottom
          > posted.
          >
          > If you wish more specific advise, you will have to supply more specific
          > code yourself. For example, what is document in your code above?
          > Ideally, you should post the smallest possible complete program that
          > exhibits the issue you are having. Provide the expected and actual
          > outputs. I suspect you will be most pleased from the response of the[/color]
          group.[color=blue]
          >
          > Ray
          >[/color]

          sorry, ray.
          i didn't think when i answered on your post.
          i am back on my problem:

          function transformXMLToS tring(){

          //here, i got some object
          SomeObject so = new SomeObject();
          so.setName("mal i");
          so.setHi("\"Hi\ ""); // here i have value of so.hi = "Hi" with qoutas

          //now i make Document object

          Element root = new Element("mainNo de");
          String output = new String();
          Document document = new Document(root);
          try{
          //NodeName
          Element sub = new Element("nodeNa me");
          sub.addContent( so.getName());
          root.addContent (prom);

          //NodeHi
          sub = new Element("NodeHi ");
          sub.addContent( so.getHi()); //content of sub is &quot;Hi&quo t;
          root.addContent (prom);

          XMLOutputter serializer = new XMLOutputter();
          output = serializer.outp utString(docume nt);

          }
          catch(Exception e){
          System.out.prin tln(e.getMessag e());
          }
          return output;
          }

          so, for output i get
          <?xml version="1.0"?>
          <nodeMain>
          <NodeName>mal i</NodeName>
          <NodeHi>&amp;qu ot;Hi&amp;quot; </NodeHi>
          </nodeMain>

          but i want for output following string
          <?xml version="1.0"?>
          <nodeMain>
          <NodeName>mal i</NodeName>
          <NodeHi>&quot;H i&quot;</NodeHi>
          </nodeMain>


          thanks


          Comment

          • Raymond DeCampo

            #6
            Re: JDOM and &amp;qout;

            mali_djuro wrote:[color=blue]
            >
            > function transformXMLToS tring(){
            >
            > //here, i got some object
            > SomeObject so = new SomeObject();
            > so.setName("mal i");
            > so.setHi("\"Hi\ ""); // here i have value of so.hi = "Hi" with qoutas
            >
            > //now i make Document object
            >
            > Element root = new Element("mainNo de");
            > String output = new String();
            > Document document = new Document(root);
            > try{
            > //NodeName
            > Element sub = new Element("nodeNa me");
            > sub.addContent( so.getName());
            > root.addContent (prom);
            >
            > //NodeHi
            > sub = new Element("NodeHi ");
            > sub.addContent( so.getHi()); //content of sub is &quot;Hi&quo t;
            > root.addContent (prom);
            >
            > XMLOutputter serializer = new XMLOutputter();
            > output = serializer.outp utString(docume nt);
            >
            > }
            > catch(Exception e){
            > System.out.prin tln(e.getMessag e());
            > }
            > return output;
            > }
            >
            > so, for output i get
            > <?xml version="1.0"?>
            > <nodeMain>
            > <NodeName>mal i</NodeName>
            > <NodeHi>&amp;qu ot;Hi&amp;quot; </NodeHi>
            > </nodeMain>
            >
            > but i want for output following string
            > <?xml version="1.0"?>
            > <nodeMain>
            > <NodeName>mal i</NodeName>
            > <NodeHi>&quot;H i&quot;</NodeHi>
            > </nodeMain>
            >
            >
            > thanks
            >
            >[/color]

            It would be best if you provide a complete program. That would allow
            other to run and debug it.

            Since I do not know what is happening in the SomeObject class, I cannot
            know what is really being passed to the JDOM classes. I would focus on
            exactly what is being passed to sub.addContent( ).

            Ray



            Comment

            • trs1800

              #7
              random name, im bored

              import java.util.Rando m;
              public class name
              {
              public static void main(String[] args)
              {
              String string1;
              char char1 = 7;
              string1 = " ";
              int temp, length;
              Random generator = new Random();
              length = generator.nextI nt(10);
              for(int blah = 0;blah <= length;blah++)
              {
              temp = generator.nextI nt(26);
              if(temp == 1)
              char1 = 65;
              if(temp == 2)
              char1 = 66;
              if(temp == 3)
              char1 = 67;
              if(temp == 4)
              char1 = 68;
              if(temp == 5)
              char1 = 69;
              if(temp == 6)
              char1 = 70;
              if(temp == 7)
              char1 = 71;
              if(temp == 8)
              char1 = 72;
              if(temp == 9)
              char1 = 73;
              if(temp == 10)
              char1 = 74;
              if(temp == 11)
              char1 = 75;
              if(temp == 12)
              char1 = 76;
              if(temp == 13)
              char1 = 77;
              if(temp == 14)
              char1 = 78;
              if(temp == 15)
              char1 = 79;
              if(temp == 16)
              char1 = 80;
              if(temp == 17)
              char1 = 81;
              if(temp == 18)
              char1 = 82;
              if(temp == 19)
              char1 = 83;
              if(temp == 20)
              char1 = 84;
              if(temp == 21)
              char1 = 85;
              if(temp == 22)
              char1 = 86;
              if(temp == 23)
              char1 = 87;
              if(temp == 24)
              char1 = 88;
              if(temp == 25)
              char1 = 89;
              if(temp == 26)
              char1 = 90;
              string1 = string1 + char1;
              }
              System.out.prin tln(string1);
              }


              }

              Comment

              Working...