0

good day, I have a UML class diagram exported to an XML file, and the code basically and repeatedly is like this:

<UML:Class name="Zip Code" isLeaf="false" xmi.id="{C7C65474-DD51-4165-89A0-FB552A929185}" isAbstract="false" visibility="public">

So, what i need to do, is to output to the user all the class(etc) found in the file. More exactly, i need to read the name inside the double quotes.

More properly, read the string inside the double quotes from a specific tag, example:

to get all classes names i must search in: <UML:Class name=" STRING WHAT I WANNA GET "

to get all atributtes names i must search in: <UML:Attribute name=" STRING I WANNA GET "

edit : i have tried but sttil not working :x

i have this;

example.php

<?php
$xmlstr = <<<XML
<UML:Class name="Colaborator" isLeaf="false" xmi.id="{B8D626AE-F100-4548-9136-057E68BE577D}" isAbstract="false" visibility="public">
                    <UML:Classifier.feature>
                        <UML:Attribute name="Colaborator Name" xmi.id="{BB9111A8-740A-4463-9DF8-719E21E3F1CC}" ownerScope="instance" visibility="private" changeability="changeable">
                            <UML:StructuralFeature.type>
                                <UML:Classifier xmi.idref="Dttp0"/>
                                <UML:lol> sfdsf </UML:lol>
                            </UML:StructuralFeature.type>
                        </UML:Attribute>
                        <UML:Attribute name="Colaborator Address" xmi.id="{D7C15DA3-F86B-4696-874C-C69F94CDEE51}" ownerScope="instance" visibility="private" changeability="changeable">
<UML:StructuralFeature.type>
                          <UML:Classifier xmi.idref="Dttp1"/>
                        </UML:StructuralFeature.type>
                        </UML:Attribute>
                    </UML:Classifier.feature>
                </UML:Class>

XML;
?>

and in test.php

<?php
include 'example.php';

$UML:Class = new SimpleXMLElement($xmlstr);

foreach ($UML:Class->xpath('//UML:Attribute') as $attr) {
echo $attr->name, PHP_EOL;
}
?>
MichaelS
  • 15
  • 4
  • 2
    [Have you tried an XML parser?](http://stackoverflow.com/a/1732454/476) – deceze Jun 21 '12 at 14:13
  • i tried but its not what i really need, because i got some problems with the UML version. see my edit please – MichaelS Jun 21 '12 at 14:43
  • What are the "problems with the UML version"? What XML parser have you tried? – deceze Jun 21 '12 at 15:03
  • I really dont want to go more inside XML, my file is from type XML, but it could be TXT, to my solution i dont think its important. – MichaelS Jun 21 '12 at 15:08
  • Well, sorry you feel that way, because XML is specifically designed to make it easy to extract structured information from a big blob of text... If you want to forgo that, good luck to you. – deceze Jun 21 '12 at 15:23
  • @deceze So how do i can search a specific tag by using the xml parser? – MichaelS Jun 22 '12 at 08:32
  • Many ways, for example using Xpath: http://php.net/manual/en/simplexml.examples-basic.php#example-5116 – deceze Jun 22 '12 at 08:49
  • @deceze i got this(its in the question), but its not working, what is wrong? – MichaelS Jun 22 '12 at 10:15

1 Answers1

0

If you just need the name (and perhaps offset):

regex: name="([\w ]+)"

Otherwise, you'll need to use an XML parser.

somedev
  • 1,053
  • 1
  • 9
  • 27