开发者

Want XML contents to be in-line

I have this XML structure:

<?xml version="1.0" encoding="utf-8"?>
<Request>
    <RequestHeader requestType="CreateUserRequest" dateTime="2011-08-01T16:50:25.9387377+10:00" />
    <RequestBody>
        <CreateUserRequest>
            <User userId="123007" firstName="Peter" lastName="McDonald" active="true" />
        </CreateUserRequest>
    </RequestBody>
 </Request>

and I would that structure to be converted to the following:

<?xml version="1.0" encoding="utf-8"?><Request><RequestHeader requestType="CreateUserRequest" dateTime="2011-08-01T16:50:25.9387377+10:00" /><RequestBody><CreateUserRequest><User userId="123007" firstName="Peter" lastName="McDonald" active="true" /></CreateUserRequest></RequestBody></Request>

I did try in PHP with DOMDocument:

    $contents = file_get_contents('User.xml');
    $dom = new DOMDocument('1.0', 'utf-8开发者_Go百科');
    $dom->preserveWhiteSpace = false;
    $dom->formatOutput = false;
    $dom->loadXML($contents);

    echo $dom->saveXML();

But it came out as:

    <?xml version="1.0" encoding="utf-8"?>
    <Request><RequestHeader requestType="CreateUserRequest" dateTime="2011-08-01T16:50:25.9387377+10:00" /><RequestBody><CreateUserRequest><User userId="123007" firstName="Peter" lastName="McDonald" active="true" /></CreateUserRequest></RequestBody></Request>

Can someone please help me with regular expressions or perhaps an alternate way to achieve that.

Thanks


if you don't care about the contents of the XML (eg cdata) then a simple...

str_replace("\n",'',$xml)

..would suffice

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜