Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Your question is very confusing.

I need to parse some HTML files and have to write a XML output file. In some cases I get a XML parser error.

  • What are you using to parse the HTML?
  • What are you using to write the XML?
  • What "XML parser error" do you get?
  • Show us some code

The symbol ® ( REGISTERED SIGN ) need to be convert to its equivalent unicode U00AE

Is "®" the result you get after parsing the HTML? i.e. the character and not an ampersand followed by an identifier and then a semi-colon? If so, then the parsing is working fine, and it is the output you need to worry about. (I mention this because PerlMonks takes HTML input, so you might have wanted to say ® rather then ®.)

Any XML library should be outputting something appropriate when given ® as input. Either it will output an entity (which should be absolutely fine, since you should be parsing XML only with an XML parser which can handle such things) or it will output the character in whatever character encoding is being used (so you just need to make sure you are outputting UTF-8 (or whichever unicode encoding you want) — how you do that depends on which XML library you are using.

I don't want Decimal Equivalent or HTML entities

Named HTML entities could screw things up in XML, but the decimal entity should not.

as this XML file should be parsed in JSON.

This doesn't make sense. XML is a data format. JSON is a completely different data format.

You can't parse anything in JSON.

You could store an XML document as a string inside a JSON object, but that shouldn't prevent you from using entities — you would parse the JSON to extract the string of XML, then put that string in an XML parser to extract the data from it.

What is the problem you are really trying to solve? You don't seem to have provided enough detail here.


In reply to Re: Convert HTML symbols to equivalent Unicode by dorward
in thread Convert HTML symbols to equivalent Unicode by jai_dgl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-16 19:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found