Contenuto principale

string

Convert parsed HTML tree to string

    Description

    str = string(tree) converts the htmlTree object tree to string.

    Tip

    Use the string function to help inspect the underlying HTML code of htmlTree objects. To navigate elements of htmlTree objects, use the findElement function.

    example

    Examples

    collapse all

    Read HTML code from the URL https://www.mathworks.com/help/textanalytics using the webread function.

    url = "https://www.mathworks.com/help/textanalytics";
    code = webread(url);

    Parse the HTML code using the htmlTree function.

    tree = htmlTree(code);

    Find all the paragraphs in the HTML tree using the findElement function. The paragraphs are the nodes with element name "P".

    subtrees = findElement(tree,"P");

    Convert the subtrees to string using the string function.

    str = string(subtrees)
    str = 18×1 string array
        "<P class="h1">↵  <A xmlns="http://www.w3.org/1999/xhtml" href="../index.html">Help Center</A>↵</P>"
        "<P>Text Analytics Toolbox™ provides algorithms and visualizations for preprocessing, analyzing, and modeling text data. Models created with the toolbox can be used in applications such as sentiment analysis, predictive maintenance, and topic modeling.</P>"
        "<P>Text Analytics Toolbox includes tools for processing raw text from sources such as equipment logs, news feeds, surveys, operator reports, and social media. You can extract text from popular file formats, preprocess raw text, extract individual words, convert text into numerical representations, and build statistical models.</P>"
        "<P>Using machine learning techniques such as LSA, LDA, and word embeddings, you can find clusters and create features from high-dimensional text datasets. Features created with Text Analytics Toolbox can be combined with features from other data sources to build machine learning models that take advantage of textual, numeric, and other types of data.</P>"
        "<P class="category_desc">Learn the basics of Text Analytics Toolbox</P>"
        "<P class="category_desc">Import text data into MATLAB<SUP>®</SUP> and preprocess it for analysis</P>"
        "<P class="category_desc">Develop predictive models using topic models and word embeddings</P>"
        "<P class="category_desc">Visualize text data and models using word clouds and text scatter plots</P>"
        "<P class="category_desc">Information on language support in Text Analytics Toolbox</P>"
        "<P>You clicked a link that corresponds to this MATLAB command:</P>"
    
    

    Input Arguments

    collapse all

    HTML tree, specified as an htmlTree array.

    Output Arguments

    collapse all

    String, returned as a string array with the same size as tree.

    Version History

    Introduced in R2018b

    expand all