DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: malformed XML???

  1. #1
    Join Date
    Apr 2011
    Posts
    4

    malformed XML???

    I have some data in XML that I need to parse, but it seems to not be in a standard format. I can convert it with some regex stuff, but I need to get the format right first.

    The first part passes the parser,
    Code:
    <Lay type="Input">
    <Ug>
    <UgUn id="0">
    <Un>
    <Bias>
    -0.0552877
    </Bias>
    </Un>
    </UgUn>
    <UgUn id="1">
    <Un>
    <Bias>
    0.408643
    </Bias>
    </Un>
    </UgUn>
    <UgUn id="2">
    <Un>
    <Bias>
    0.427559
    </Bias>
    </Un>
    </UgUn>
    </Ug>
    </Lay>
    When I add the seconds layer tag,
    Code:
    <Lay type="Hidden">
    <Ug>
    <UgUn id="0">
    <Un>
    <Bias>
    -1.5808
    </Bias>
    <Cg id="0" Fm="Input">
    <Cn num="3">
    0 1.42767
    1 1.16508
    2 -0.56867
    </Cn>
    </Cg>
    </Un>
    </UgUn>
    <UgUn id="1">
    <Un>
    <Bias>
    -1.63367
    </Bias>
    <Cg id="0" Fm="Input">
    <Cn num="3">
    0 -0.0159938
    1 -0.157863
    2 -0.167117
    </Cn>
    </Cg>
    </Un>
    </UgUn>
    </Ug>
    </Lay>
    I get an error from the parser that 257 root element has sibling.

    I am not at all familiar with XML, but I can't see what is wrong with this. The nesting appears symmetrical, etc. If someone could let me know what the issue is, I would really appreciate the advice.

    I am also not sure what is a good parser/viewer to use. If someone can suggest a good free tool, preferably one that doesn't require microsoft XML, I would appreciate that as well.

    LMHmedchem

  2. #2
    Join Date
    Apr 2011
    Posts
    4
    I found one issue with the XML. These spaces,
    Code:
    <Cn num="3">
    0   1.42767
    1   1.16508
    2   -0.56867
    </Cn>
    are an issue I think. I have replace that with,
    Code:
    <Cn num="3">
    <0>1.42767</0>
    <1>1.16508</1>
    <2>-0.56867</2>
    </Cn>
    Now I am getting a parser error,
    UTF-8 719 tag syntax error at offset 306 expecting tag name /! or ?

    Any suggestions???

    LMHmedchem

  3. #3
    Join Date
    Apr 2011
    Posts
    4
    I guess I don't really understand how XML is supposed to be formatted. This part of the data is just fine.
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <Lay type="Input">
    <Ug>
    <UgUn id="0">
    <Un>
    <Bias>-0.0552877</Bias>
    </Un>
    </UgUn>
    <UgUn id="1">
    <Un>
    <Bias>0.408643</Bias>
    </Un>
    </UgUn>
    <UgUn id="2">
    <Un>
    <Bias>0.427559</Bias>
    </Un>
    </UgUn>
    </Ug>
    </Lay>
    But if I add the same data again, calling it Lay2,
    Code:
    <Lay2 type="Hidden">
    <Ug>
    <UgUn id="0">
    <Un>
    <Bias>-0.0552877</Bias>
    </Un>
    </UgUn>
    <UgUn id="1">
    <Un>
    <Bias>0.408643</Bias>
    </Un>
    </UgUn>
    <UgUn id="2">
    <Un>
    <Bias>0.427559</Bias>
    </Un>
    </UgUn>
    </Ug>
    </Lay2>
    I get an error that,
    "the markup in the document following the root element must be well formed"

    both parts of the code are formed in the same way, so I can't see what the issue is.

    LMHmedchem

  4. #4
    Join Date
    Apr 2011
    Posts
    4
    Well this is what I ended up with, though it's a touch on the ugly side,
    Code:
    #!/bin/bash
    
    infile=$1
    outfile=$1".mod.wts"
    
    # add version and root begin tags to beginning of input file
    echo '<?xml version="1.0" encoding="ASCII"?>' > temp1
    echo "<net>" >> temp1
    cat temp1 $1  > temp2
    
    # format information tags (end with />)
    sed 's/<Fmt  *\([a-z,A-Z]*\) *>/<Fmt Fmt="\1"\/>/g'       temp2 | \
    sed 's/<Name\ Network_0>/<Name\ Name="Network_0"\/>/g'          | \
    sed 's/<Epoch  *\([0-9]*\) *>/<Epoch Epoch="\1"\/>/g'           | \
    
    # format tags with arguments of  diofferent name than tag
    sed 's/<UgUn  *\([^ ]\{1,9\}\) *>/<UgUn id="\1">/g'             | \
    sed 's/<Cn  *\([0-9]*\) *>/<Cn num="\1">/g'                     | \
    
    
    # format remaining tags where tag and are have same value
    perl -pe 's/<(\w+) (\w+)>/<\1 \1="\2">/'                        | \
    
    # format tags with multiple args
    awk '{ if ( $0 ~ /<Cg 0 Fm:Input>/ ) {
         printf( "&#37;s\n", "<Cg Cg=\"0\">" );
         printf( "%s\n", "<Fm>Input</Fm>" );
         } else {
              print $0;
         }
    }'                                                              | \
    awk '{ if ( $0 ~ /<Cg 0 Fm:Hidden>/ ) {
         printf( "%s\n", "<Cg Cg=\"0\">" );
         printf( "%s\n", "<Fm>Hidden</Fm>" );
         } else {
              print $0;
         }
    }'                                                              | \
    
    # format multi row, multi are data
    perl -p0e 's/(<Un>\n)(.*)/\1<Bias>\2<\/Bias>/g'                 | \
    perl -pe 's/(\d+) ([\d.-]+)/<C\1>\2<\/C\1>/ if /<Cn/../<\/Cn/'   > $outfile
    
    # add root close tag to end of file
    echo "</net>" >> $outfile
    
    # cleanup
    rm temp1 temp2
    I have attached the before and after files as well.

    I guess everyone over here was asleep this weekend.

    LMHmedchem
    Attached Files Attached Files

  5. #5
    Join Date
    May 2009
    Posts
    60
    Contained in the zip new_test.xml is no xml file in the sense of w3c


    There are many of the basic rules violated
    for example
    attributte are in quotes

    UTF-8719 tag syntax error at offset 306 expecting tag name /! or?

    all tags begin with letters

    Therefore, error message

    Each xml file has a root tag | node

    Therefore, in the trash file with the new_test.xml
    and forget

    with the second file new_test_mod can work

    and it is so very look of a normal browser, the data
    and all programmierr language to use the xml interface have
    Please explain what made ​​the data should be

Similar Threads

  1. Try XML Junction
    By Tim in forum xml.announcements
    Replies: 0
    Last Post: 10-11-2001, 04:00 PM
  2. XML Startkabel Updates
    By xmlstartkabel in forum XML
    Replies: 0
    Last Post: 10-10-2001, 04:07 AM
  3. Data Junction Announces XML Junction 7.51
    By Tim Frost in forum xml.announcements
    Replies: 0
    Last Post: 04-02-2001, 10:53 AM
  4. Check out Turbo XML: Free trial download
    By Extensibility in forum web.announcements
    Replies: 0
    Last Post: 07-20-2000, 06:20 PM
  5. Check out Turbo XML
    By Sales in forum xml.announcements
    Replies: 0
    Last Post: 07-20-2000, 06:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center